forked from playwright-community/playwright-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracing.go
71 lines (66 loc) · 1.54 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
package playwright
type tracingImpl struct {
context *browserContextImpl
channel *channel
}
func (t *tracingImpl) Start(options ...TracingStartOptions) error {
if _, err := t.channel.Send("tracingStart", options); err != nil {
return err
}
if _, err := t.channel.Send("tracingStartChunk", options); err != nil {
return err
}
return nil
}
func (t *tracingImpl) StartChunk() error {
_, err := t.channel.Send("tracingStartChunk")
return err
}
func (t *tracingImpl) Stop(options ...TracingStopOptions) error {
path := ""
if len(options) == 1 && options[0].Path != nil {
path = *options[0].Path
}
if err := t.stopChunk(path); err != nil {
return err
}
if _, err := t.channel.Send("tracingStop"); err != nil {
return err
}
return nil
}
func (t *tracingImpl) StopChunk(options ...TracingStopChunkOptions) error {
path := ""
if len(options) == 1 && options[0].Path != nil {
path = *options[0].Path
}
if err := t.stopChunk(path); err != nil {
return err
}
return nil
}
func (t *tracingImpl) stopChunk(path string) error {
save := true
if path == "" {
save = false
}
artifactChannel, err := t.channel.Send("tracingStopChunk", map[string]interface{}{
"save": save,
})
if err != nil {
return err
}
if artifactChannel != nil {
artifact := fromChannel(artifactChannel).(*artifactImpl)
if path != "" {
if err := artifact.SaveAs(path); err != nil {
return err
}
}
return artifact.Delete()
}
return nil
}
func newTracing(context *browserContextImpl) *tracingImpl {
return &tracingImpl{context, context.channel}
}