...

Source file src/github.com/playwright-community/playwright-go/tracing.go

Documentation: github.com/playwright-community/playwright-go

     1  package playwright
     2  
     3  type tracingImpl struct {
     4  	channelOwner
     5  }
     6  
     7  func (t *tracingImpl) Start(options ...TracingStartOptions) error {
     8  	if _, err := t.channel.Send("tracingStart", options); err != nil {
     9  		return err
    10  	}
    11  	title := ""
    12  	if len(options) == 1 && options[0].Title != nil {
    13  		title = *options[0].Title
    14  	}
    15  	if _, err := t.channel.Send("tracingStartChunk", map[string]interface{}{
    16  		"title": title,
    17  	}); err != nil {
    18  		return err
    19  	}
    20  	return nil
    21  }
    22  
    23  func (t *tracingImpl) StartChunk(options ...TracingStartChunkOptions) error {
    24  	_, err := t.channel.Send("tracingStartChunk", options)
    25  	return err
    26  }
    27  
    28  func (t *tracingImpl) StopChunk(options ...TracingStopChunkOptions) error {
    29  	path := ""
    30  	if len(options) == 1 && options[0].Path != nil {
    31  		path = *options[0].Path
    32  	}
    33  	if err := t.doStopChunk(path); err != nil {
    34  		return err
    35  	}
    36  	return nil
    37  }
    38  
    39  func (t *tracingImpl) Stop(options ...TracingStopOptions) error {
    40  	path := ""
    41  	if len(options) == 1 && options[0].Path != nil {
    42  		path = *options[0].Path
    43  		return t.doStopChunk(path)
    44  	}
    45  	_, err := t.channel.Send("tracingStopChunk", options)
    46  	return err
    47  }
    48  
    49  func (t *tracingImpl) doStopChunk(filePath string) error {
    50  	isLocal := !t.connection.isRemote
    51  	mode := "doNotSave"
    52  	if filePath != "" {
    53  		if isLocal {
    54  			mode = "compressTraceAndSources"
    55  		} else {
    56  			mode = "compressTrace"
    57  		}
    58  	}
    59  	artifactChannel, err := t.channel.Send("tracingStopChunk", map[string]interface{}{
    60  		"mode": mode,
    61  	})
    62  	if err != nil {
    63  		return err
    64  	}
    65  	// Not interested in artifacts.
    66  	if filePath == "" {
    67  		return nil
    68  	}
    69  	// The artifact may be missing if the browser closed while stopping tracing.
    70  	if artifactChannel == nil {
    71  		return nil
    72  	}
    73  	// Save trace to the final local file.
    74  	artifact := fromChannel(artifactChannel).(*artifactImpl)
    75  	if err := artifact.SaveAs(filePath); err != nil {
    76  		return err
    77  	}
    78  	return artifact.Delete()
    79  }
    80  
    81  func newTracing(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *tracingImpl {
    82  	bt := &tracingImpl{}
    83  	bt.createChannelOwner(bt, parent, objectType, guid, initializer)
    84  	return bt
    85  }
    86  

View as plain text