-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsole_message.go
More file actions
68 lines (58 loc) · 1.5 KB
/
Copy pathconsole_message.go
File metadata and controls
68 lines (58 loc) · 1.5 KB
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
package patchright
type consoleMessageImpl struct {
event map[string]any
page Page
worker Worker
}
func (c *consoleMessageImpl) Type() string {
return c.event["type"].(string)
}
func (c *consoleMessageImpl) Text() string {
return c.event["text"].(string)
}
func (c *consoleMessageImpl) String() string {
return c.Text()
}
func (c *consoleMessageImpl) Args() []JSHandle {
args := c.event["args"].([]any)
out := []JSHandle{}
for idx := range args {
out = append(out, fromChannel(args[idx]).(JSHandle))
}
return out
}
func (c *consoleMessageImpl) Location() *ConsoleMessageLocation {
location := &ConsoleMessageLocation{}
remapMapToStruct(c.event["location"], location)
// The wire only carries lineNumber/columnNumber; mirror upstream by
// populating the non-deprecated line/column aliases too.
location.Line = location.LineNumber
location.Column = location.ColumnNumber
return location
}
func (c *consoleMessageImpl) Page() Page {
return c.page
}
func (c *consoleMessageImpl) Worker() (Worker, error) {
return c.worker, nil
}
func newConsoleMessage(event map[string]any) *consoleMessageImpl {
bt := &consoleMessageImpl{}
bt.event = event
page := fromNullableChannel(event["page"])
if page != nil {
bt.page = page.(*pageImpl)
}
worker := fromNullableChannel(event["worker"])
if worker != nil {
bt.worker = worker.(*workerImpl)
}
return bt
}
func (c *consoleMessageImpl) Timestamp() (float64, error) {
v, ok := c.event["timestamp"]
if !ok {
return 0, nil
}
return v.(float64), nil
}