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