...
1
2
3
4 package playwright
5
6
7 type DeviceDescriptor struct {
8 UserAgent string `json:"userAgent"`
9 Viewport *BrowserNewContextOptionsViewport `json:"viewport"`
10 DeviceScaleFactor float64 `json:"deviceScaleFactor"`
11 IsMobile bool `json:"isMobile"`
12 HasTouch bool `json:"hasTouch"`
13 DefaultBrowserType string `json:"defaultBrowserType"`
14 }
15
16
17 type Playwright struct {
18 channelOwner
19 Chromium BrowserType
20 Firefox BrowserType
21 WebKit BrowserType
22 Devices map[string]*DeviceDescriptor
23 }
24
25
26 func (p *Playwright) Stop() error {
27 return p.connection.Stop()
28 }
29
30 func newPlaywright(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *Playwright {
31 pw := &Playwright{
32 Chromium: fromChannel(initializer["chromium"]).(*browserTypeImpl),
33 Firefox: fromChannel(initializer["firefox"]).(*browserTypeImpl),
34 WebKit: fromChannel(initializer["webkit"]).(*browserTypeImpl),
35 Devices: make(map[string]*DeviceDescriptor),
36 }
37 for _, dd := range initializer["deviceDescriptors"].([]interface{}) {
38 entry := dd.(map[string]interface{})
39 pw.Devices[entry["name"].(string)] = &DeviceDescriptor{
40 Viewport: &BrowserNewContextOptionsViewport{},
41 }
42 remapMapToStruct(entry["descriptor"], pw.Devices[entry["name"].(string)])
43 }
44 pw.createChannelOwner(pw, parent, objectType, guid, initializer)
45 return pw
46 }
47
48
49
View as plain text