...

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

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

     1  // Package playwright is a library to automate Chromium, Firefox and WebKit with
     2  // a single API. Playwright is built to enable cross-browser web automation that
     3  // is ever-green, capable, reliable and fast.
     4  package playwright
     5  
     6  // DeviceDescriptor represents a single device
     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  // Playwright represents a Playwright instance
    17  type Playwright struct {
    18  	channelOwner
    19  	Chromium BrowserType
    20  	Firefox  BrowserType
    21  	WebKit   BrowserType
    22  	Devices  map[string]*DeviceDescriptor
    23  }
    24  
    25  // Stop stops the Playwright instance
    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  //go:generate bash scripts/generate-api.sh
    49  

View as plain text