Skip to content

Commit

Permalink
feat: add dynamic browser options for custom launch
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasvuono committed Feb 24, 2022
1 parent 345b202 commit bbe89ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (p *Playwright) Launch(args []string) {
log.Fatalf("could not start playwright: %v", err)
}
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
Args: args,
})
if err != nil {
Expand All @@ -40,9 +39,9 @@ func (p *Playwright) Launch(args []string) {
p.Browser = browser
}

func (p *Playwright) LaunchCustomBrowser(args []string, browserPath string) {
func (p *Playwright) LaunchCustomBrowser(args []string, browserPath string, driver string) {
runOptions := playwright.RunOptions{
DriverDirectory: "./",
DriverDirectory: driver,
SkipInstallBrowsers: true,
Browsers: []string {browserPath},
}
Expand All @@ -51,8 +50,8 @@ func (p *Playwright) LaunchCustomBrowser(args []string, browserPath string) {
log.Fatalf("could not start playwright: %v", err)
}
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
Args: args,
ExecutablePath: &browserPath,
})
if err != nil {
log.Fatalf("could not launch browser: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion playwright_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestPlaywrightCustomBrowser(t *testing.T) {
var opts2 playwright.PageGotoOptions
var opts3 playwright.PageWaitForSelectorOptions

pw.LaunchCustomBrowser(opts, "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe")
pw.LaunchCustomBrowser(opts, "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", "")
pw.NewPage()
pw.Goto("https://www.google.com", opts2)
pw.WaitForSelector("//html/body/div[1]/div[2]", opts3)
Expand Down

0 comments on commit bbe89ca

Please sign in to comment.