A central home for tutorials, tooling, and showcases of the Playwright ecosystem.
This is the source of playwright.tech. A Next.js based application hosted on Vercel.
Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
Home Page: https://playwright-community.github.io/playwright-go/
License: MIT License
A central home for tutorials, tooling, and showcases of the Playwright ecosystem.
This is the source of playwright.tech. A Next.js based application hosted on Vercel.
I'm using the latest version github.com/mxschmitt/playwright-go v0.1100.0 // indirect
HTML code: For options with space:
<select name="cars" id="test1">
<option value="t1">t1</option>
<option value="t2">t 2</option>
<option value="t3">t 3</option>
<option value="t4">t4</option>
</select>
Playwrite-go code:
// success
v,err:=page.SelectOption("#test1",playwright.SelectOptionValues{Labels: playwright.StringSlice("t 2")})
fmt.Println(v,err)
// failed
v,err=page.SelectOption("#test1",playwright.SelectOptionValues{Labels: playwright.StringSlice("t 3")})
fmt.Println(v,err)
Result:
C:\Andrew\prj\learn>go run select.go
2021/05/26 11:50:59 Downloading browsers...
2021/05/26 11:50:59 Downloaded browsers successfully
pw:api navigating to "http://localhost:8888/", waiting until "load" +0ms
pw:api navigated to "http://localhost:8888/" +799ms
pw:api "load" event fired +28ms
pw:api "domcontentloaded" event fired +4ms
pw:api waiting for selector "#test1" +12ms
pw:api selector resolved to visible <select id="test1" name="cars">…</select> +23ms
pw:api selecting specified option(s) +5ms
pw:api selected specified option(s) +11ms
[t2] <nil>
pw:api waiting for selector "#test1" +37ms
pw:api selector resolved to visible <select id="test1" name="cars">…</select> +4ms
pw:api selecting specified option(s) +3ms
pw:api did not find some options - waiting... +3ms
pw:api "networkidle" event fired +398ms
[] could not send message to server: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "#test1"
selector resolved to visible <select id="test1" name="cars">…</select>
selecting specified option(s)
did not find some options - waiting...
============================================================
Note: use DEBUG=pw:api environment variable to capture Playwright logs.
It similar to this issue: microsoft/playwright#3830
I want to use this library to automate my daily tasks, like giving a job id, go to a page find all the pallets of this job and process these pallets one by one. Or giving an asset id, I verify if all the processing data are valid for this asset, etc.
When I click a button, it may show out different content, or alert messages according to the data.
What's the proper way in playwright-go to process these situation?
What's the correct way to do this in playwright-go?
await page.goto(loadLink)
// if load id is valid, this PALLET DETAILS table will show out
const hdTable = "#ctl00_ctl00_LoadPallet"
// if load id is invalid, it will show warning window with this close button
const closeButton = "#ctl00_ctl00_LoadGridClose"
await Promise.race([
page.click(closeButton).then(() => false),
page.waitForSelector(hdTable).then(() => true)
]).then(value => {
if (!value) {
console.log("wrong load id: ", loadID)
return
}
})
Thanks
Hi,
Hope you are all well !
I was wondering if it possible to catch all network requests with playwright for loading a page ?
Thanks for any insights or inputs on that.
Cheers,
Luc Michalski
Hi,
I'm using playwright on this project hippokampe specifically in the api module. This app is already tested in vagrant and linux pc, with positive results, but in the case of WSL 2, it's not working properly.
I debugged the project, and I can conclude that the problem it's raised right here. I don't receive an error but blocks the execution, like an infinite loop.
Thanks
We are delivering Moon - a solution for running parallel Selenium and Playwright tests. The only prerequisite to use it is being able to connect directly to Playwright websocket. https://aerokube.com/moon/latest/#_using_playwright Is it possible to do this right now?
my code:
`account.Pages.Active().On("response", func(response *playwright.Response) {
if strings.Index(response.URL(), "authenticationstate") != -1 {
out.Debug("Response detected", response.URL())
accountAuthStatus := authState{}
out.Debug("decoding json")
jsonDecodeError := response.JSON(&accountAuthStatus)
if jsonDecodeError != nil {
out.Debug("Error decode", jsonDecodeError.Error())
}
out.Debug("printing result")
out.Debug(accountAuthStatus.String())
}
})`
response.JSON() freezes the code and not returns any value ,
panic: reflect: call of reflect.Value.Float on zero Value
goroutine 9 [running]:
reflect.Value.Float(...)
C:/Program Files/Go/src/reflect/value.go:931
github.com/mxschmitt/playwright-go.remapValue(0x0, 0x0, 0x0, 0x130b260, 0xc00045b0c0, 0x182)
C:/Users/sicko/go/pkg/mod/github.com/mxschmitt/[email protected]/helpers.go:138 +0xc05
github.com/mxschmitt/playwright-go.remapValue(0x134de80, 0xc0026a78f0, 0x15, 0x13f6cc0, 0xc00045b080, 0x199)
C:/Users/sicko/go/pkg/mod/github.com/mxschmitt/[email protected]/helpers.go:158 +0x538
github.com/mxschmitt/playwright-go.remapMapToStruct(0x134de80, 0xc0026a78f0, 0x12e8e80, 0xc00045b080)
C:/Users/sicko/go/pkg/mod/github.com/mxschmitt/[email protected]/helpers.go:168 +0x167
github.com/mxschmitt/playwright-go.(*browserContextImpl).Cookies(0xc000268900, 0x0, 0x0, 0x0, 0x8, 0x0, 0x93e869, 0x9, 0x203000b)
I tried to download a csv
file from a page and it stuck when execute download.Path()
or download.Failure()
, etc.
HTML Source code:
<a class="ActiveLink" title="CSV (comma delimited)" alt="CSV (comma delimited)" onclick="$find('ctl32').exportReport('CSV');" href="javascript:void(0)" >CSV (comma delimited)</a>
Go code:
download,err:=page.ExpectDownload(func() error {
return page.Click("#ctl32_ctl05_ctl04_ctl00_Menu > div:nth-child(6) > a")
})
fmt.Println(err) // nil
fmt.Println(download.SuggestedFilename()) // "User Metrics.csv"
// Stuck Here
// =======
// stuck when execute one of the Failure(), Path() or SaveAs() functions.
// I can see the file is downloaded in the folder with a temporary name such as "32a609ac-c0c0-4e87-8bd6-ed4d69c6f474"
// And the file content is right, but the program stops here
fmt.Println(download.Failure())
// Press Ctrl + C from command line shows the following error message
exit status 2
The process tried to write to a nonexistent pipe.
How can I fix this problem?
Is is possible to install only one browser using the playwright-driver? I don't need all three downloaded.
Thanks
Current report (node scripts/validate-interfaces.js
):
Missing API interface functions:
I'm trying to see if the page gets redirected to a URL that looks like api-SOME_HASH.mywebsite.com
. Unfortunately, none of the URL options work.
Here is the code:
var timeout float64 = float64(10 * time.Second.Milliseconds())
var url = `/mywebsite\.com/`
_, err = page.WaitForNavigation(playwright.PageWaitForNavigationOptions{
Timeout: &timeout,
URL: &url,
})
The different options I tried for url
:
"/mywebsite\.com/"
"mywebsite\.com"
"mywebsite.com"
"*mywebsite.com*"
".*mywebsite\.com.*"
regexp.MustCompile(".*mywebsite\.com.*")
(Note: quotes must be substituted with backticks because of escaping)
All of the above result in the following error:
panic: (*string) 0xc0004049f0
goroutine 34 [running]:
github.com/mxschmitt/playwright-go.(*urlMatcher).Matches(0xc000404a00, 0xc00046e000, 0x276, 0x3)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/helpers.go:198 +0x3fc
github.com/mxschmitt/playwright-go.(*frameImpl).WaitForNavigation.func1(0xc000439fc0, 0x1, 0x1, 0x0)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/frame.go:165 +0x10e
reflect.Value.call(0x1413a60, 0xc000404a10, 0x13, 0x14afcbd, 0x4, 0xc00028b8f0, 0x1, 0x1, 0x18, 0xc000464720, ...)
/usr/local/go/src/reflect/value.go:476 +0x8e7
reflect.Value.Call(0x1413a60, 0xc000404a10, 0x13, 0xc0001c9458, 0x1, 0x1, 0x14060a0, 0x1, 0xc000464720)
/usr/local/go/src/reflect/value.go:337 +0xb9
github.com/mxschmitt/playwright-go.waitForEvent.func1(0xc000439f60, 0x1, 0x1)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/helpers.go:314 +0x206
reflect.Value.call(0x140b500, 0xc000406ed0, 0x13, 0x14afcbd, 0x4, 0xc00028b8a8, 0x1, 0x1, 0x14ae2e0, 0xc0001c9750, ...)
/usr/local/go/src/reflect/value.go:476 +0x8e7
reflect.Value.Call(0x140b500, 0xc000406ed0, 0x13, 0xc00028b878, 0x1, 0x1, 0xc00028b878, 0xc0001c9810, 0x0)
/usr/local/go/src/reflect/value.go:337 +0xb9
github.com/mxschmitt/playwright-go.(*eventEmitter).Emit.func1(0xc000404a40, 0x1, 0x1)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/event_emitter.go:38 +0x1a5
github.com/mxschmitt/playwright-go.(*eventEmitter).Emit(0xc0001d38d8, 0x14b1d1f, 0x9, 0xc0001c98d8, 0x1, 0x1)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/event_emitter.go:42 +0x252
github.com/mxschmitt/playwright-go.(*frameImpl).onFrameNavigated(0xc0001d38c0, 0xc000464690)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/frame.go:185 +0x191
reflect.Value.call(0x140b6c0, 0xc000191850, 0x13, 0x14afcbd, 0x4, 0xc00028b860, 0x1, 0x1, 0x14ae2e0, 0x0, ...)
/usr/local/go/src/reflect/value.go:476 +0x8e7
reflect.Value.Call(0x140b6c0, 0xc000191850, 0x13, 0xc00028b860, 0x1, 0x1, 0xc00045ca70, 0x9, 0x1)
/usr/local/go/src/reflect/value.go:337 +0xb9
github.com/mxschmitt/playwright-go.(*eventEmitter).Emit.func1(0xc000191860, 0x1, 0x1)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/event_emitter.go:38 +0x1a5
github.com/mxschmitt/playwright-go.(*eventEmitter).Emit(0xc00022f1f0, 0xc00045ca70, 0x9, 0xc0001c9dc0, 0x1, 0x1)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/event_emitter.go:42 +0x252
github.com/mxschmitt/playwright-go.(*connection).Dispatch(0xc00029a070, 0xc0002c1cc0)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/connection.go:73 +0x452
github.com/mxschmitt/playwright-go.(*transport).Start(0xc00028c0f0, 0x14d1740, 0xc0001acae0)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/transport.go:44 +0xc6
github.com/mxschmitt/playwright-go.(*connection).Start(...)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/connection.go:28
github.com/mxschmitt/playwright-go.Run.func1(0xc00029a070)
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/run.go:233 +0x32
created by github.com/mxschmitt/playwright-go.Run
/Users/marksk/.local/share/go/pkg/mod/github.com/mxschmitt/[email protected]/run.go:232 +0x1d5
exit status 2
(node:16889) UnhandledPromiseRejectionWarning: Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:156:25)
at writeGeneric (internal/stream_base_commons.js:147:3)
at Socket._writeGeneric (net.js:787:11)
at Socket._write (net.js:799:8)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/protocol/transport.js:47:25)
at DispatcherConnection.dispatcherConnection.onmessage (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/cli/driver.js:63:59)
at DispatcherConnection.sendMessageToClient (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:136:14)
(node:16889) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16889) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:16889) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:399:19)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/protocol/transport.js:47:25)
at DispatcherConnection.dispatcherConnection.onmessage (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/cli/driver.js:63:59)
at DispatcherConnection.sendMessageToClient (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:136:14)
at PageDispatcher._dispatchEvent (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:72:26)
at Page.<anonymous> (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/pageDispatcher.js:64:71)
at Page.emit (events.js:314:20)
at FrameManager.requestFinished (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/server/frames.js:239:24)
(node:16889) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:16889) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:399:19)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/protocol/transport.js:47:25)
at DispatcherConnection.dispatcherConnection.onmessage (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/cli/driver.js:63:59)
at DispatcherConnection.sendMessageToClient (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:136:14)
at new Dispatcher (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:63:30)
at new RequestDispatcher (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/networkDispatchers.js:32:9)
at Function.from (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/networkDispatchers.js:25:26)
at Page.<anonymous> (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/pageDispatcher.js:58:137)
(node:16889) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:16889) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:399:19)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/protocol/transport.js:47:25)
at DispatcherConnection.dispatcherConnection.onmessage (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/cli/driver.js:63:59)
at DispatcherConnection.sendMessageToClient (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:136:14)
at new Dispatcher (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:63:30)
at new RequestDispatcher (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/networkDispatchers.js:32:9)
at Function.from (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/networkDispatchers.js:25:26)
at Page.<anonymous> (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/pageDispatcher.js:58:137)
(node:16889) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:16889) UnhandledPromiseRejectionWarning: Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:399:19)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Transport.send (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/protocol/transport.js:47:25)
at DispatcherConnection.dispatcherConnection.onmessage (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/cli/driver.js:63:59)
at DispatcherConnection.sendMessageToClient (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:136:14)
at new Dispatcher (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/dispatcher.js:63:30)
at new RequestDispatcher (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/networkDispatchers.js:32:9)
at Function.from (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/networkDispatchers.js:25:26)
at Page.<anonymous> (/Users/marksk/Library/Caches/ms-playwright-go/1.10.0/package/lib/dispatchers/pageDispatcher.js:58:137)
(node:16889) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)
Am I doing something wrong? I would like to add here that I couldn't find any examples for URLs neither in the official playwright docs nor in playwright-go examples.
For example:
<select id="p-lang">
<option value="">Make a selection...</option>
<option value="go">Go</option>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option selected="selected" value="php">PHP</option>
<option value="js">JavaScript</option>
</select>
How can I get the value "php" or the test "PHP" from the select
tag?
Thanks.
There's a mention about width and height in the doc but I can only see Format being available. Viewport's width and height doesn't do anything for the PDF size
Handling the error each time is not nice, it might make sense to add or generate Must* methods which panic if an error gets returned.
I have discovered that playwright.Stop()
lefts behind a defunct process.
It is possible to reproduce the problem doing this:
Create this simple Go program:
package main
import (
"fmt"
"time"
"github.com/mxschmitt/playwright-go"
)
func main() {
runOpts := &playwright.RunOptions{
SkipInstallBrowsers: true,
}
pw, err := playwright.Run(runOpts)
if err != nil {
panic(err)
}
pw.Dispose()
fmt.Println("after dispose")
err = pw.Stop()
fmt.Println("after stop: ", err)
fmt.Println("after cleanup. Waiting...")
time.Sleep(20*time.Second)
}
As you can see, I have made it wait 20secs at the end, enough to run check the mentioned defunct process.
I build the program with go build .
and then I mount the binary in a docker container with the playwright runtime to test it:
$ docker run --name=bugdemo -ti -v $PWD/bugdemo:/mnt/bugdemo mcr.microsoft.com/playwright:focal bash
# /mnt/bugdemo
after dispose
after stop: <nil>
after cleanup. Waiting...
I open another shell in the container and check the running processes:
$ docker exec -ti bugdemo bash
# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 4236 3368 pts/0 Ss 14:14 0:00 bash
root 106 0.1 0.0 4240 3416 pts/1 Ss 14:27 0:00 bash
root 114 0.0 0.0 1078984 6112 pts/0 Sl+ 14:27 0:00 ./bugdemo
root 130 0.0 0.0 0 0 pts/0 Z+ 14:27 0:00 [playwright.sh] <defunct>
root 133 4.0 0.3 568364 53268 pts/0 Sl+ 14:27 0:00 /root/.cache/ms-playwright-go/1.10.0/node /root/.cache/ms-playwright-go/1.10.0/package/lib/cli/cli.js run-driver
root 140 0.0 0.0 5896 2932 pts/1 R+ 14:27 0:00 ps aux
After 20secs, once the bugdemo
process has finished, the defunct process disappears:
# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 4236 3368 pts/0 Ss+ 14:14 0:00 bash
root 106 0.0 0.0 4240 3532 pts/1 Ss 14:27 0:00 bash
root 141 0.0 0.0 5896 2848 pts/1 R+ 14:27 0:00 ps aux
I would expect pw.Stop()
or pw.Dispose()
to cleanup the playwright runtime completly.
Hi, I assumed that IsConnected
would represent the connection state between the browser instance and the client. According to the code it just set to true
when a browser is created but not updated when the browser connection is closed by accident or manually.
Hi, I can't see the type definition of the page errors.
For example:
page, _ := browserContext.NewPage()
page.Once("pageerror", func(err ???) {
c.Logger().Errorf("an error on the page was detected: %s", err)
})
I also recommend using custom function types e.g
type RequestFailedEventHandler = func(request *Request)
Hi
i am just update my Mac OS to last version today
but i can't run on my program
this the problem is
2021/02/16 20:48:35 Error Browser%!(EXTRA *fmt.wrapError=could not send message: could not send message to server: No executable path is specified. Pass "executablePath" option directly.
Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.)
exit status 1
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
})
i had change the browser chromium, firefox or webkit but nobody can work of them
thanks before
From example:
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
})
Is it possible to use plain Go type bool like:
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: false,
})
You can convert false
to playwright.Bool(false)
in Launch()
method.
This will be easier for end user.
Also the you may not need to export Bool()
or similar type convert method as a public method.
Please fix the tagging in the project.
Only old tags are showing because they respect semantic versioning:
$ go list -m -versions github.com/mxschmitt/playwright-go
github.com/mxschmitt/playwright-go v0.171.0 v0.171.1
v0.1100
should probably be set to v0.1100.0
(I am not sure about the logic of the numbers you are using here).
Hi
I'm wonder is it a bug or I'm doing something wrong? I'm trying to pass environment variable to the browser like:
b, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Env: map[string]interface{}{
"DISPLAY": ":99",
},
})
and getting FATAL Error found {"error": "could not send message: could not send message to server: env: expected array, got object"}
Version used: github.com/mxschmitt/playwright-go v0.171.1
UPDATE: I enabled DEBUGP=1
and got:
SEND>{"guid":"BrowserType@07f6a400aa7d2fba2442974fc31bc482","id":1,"method":"launch","params":{"env":{"DISPLAY":":99"}}}
RECV>{"id":1,"guid":"","method":"","params":null,"result":null,"error":{"error":{"name":"Error","message":"env: expected array, got object","stack":"Error: env: expected array, got object\n at /snapshot/playwright-cli/node_modules/playwright/lib/protocol/validatorPrimitives.js:69:19\n at /snapshot/playwright-cli/node_modules/playwright/lib/protocol/validatorPrimitives.js:63:16\n at Object.BrowserTypeLaunchParams (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/validatorPrimitives.js:81:27)\n at DispatcherConnection._validateParams (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:122:32)\n at DispatcherConnection.dispatch (/snapshot/playwright-cli/node_modules/playwright/lib/dispatchers/dispatcher.js:146:36)\n at Transport.onmessage (/snapshot/playwright-cli/lib/driver.js:48:61)\n at Immediate._onImmediate (/snapshot/playwright-cli/node_modules/playwright/lib/protocol/transport.js:70:26)\n at processImmediate (internal/timers.js:456:21)"}}}
Code:
package main
import (
"log"
"github.com/mxschmitt/playwright-go"
)
func main() {
pw, err := playwright.Run()
if err != nil {
log.Fatalf("could not start playwright: %v", err)
}
browser, err := pw.Chromium.Launch()
if err != nil {
log.Fatalf("could not launch browser: %v", err)
}
page, err := browser.NewPage()
if err != nil {
log.Fatalf("could not create page: %v", err)
}
_, err = page.Goto("https://yujiri.xyz/test")
if err != nil {
log.Fatalf("could not goto: %v", err)
}
textfield, err := page.QuerySelector("input")
if err != nil {
log.Fatalf("could not get element: %v", err)
}
err = textfield.Type("test")
if err != nil {
log.Fatalf("Could not enter text: %v", err)
}
}
Content of page:
<input>
Output:
2021/04/14 16:48:52 Downloading browsers...
2021/04/14 16:48:52 Downloaded browsers successfully
2021/04/14 16:48:54 Could not enter text: could not send message to server: text: expected string, got undefined
exit status 1
OS: Linux
Playwright-go: v0.1100.0
Few days ago, there was a playwright-go link at playwright official page(Supported language).
But now, it's gone.
Could I use this this lib?
Currently the API in the interface are hardcoded, the big benefit we get when we autogenerate them and put also the documentation in a follow up PR there.
In nodejs api reference cdpsession was introduced. But I couldn't find it anywere in go version.
https://playwright.dev/docs/api/class-cdpsession
Any plans of adding this feature in the future?
Hey team,
I'm experimenting with playwright, and trying to save the authenticated state using the context.StorageState()
However, struggling to find the way to restore the stored state.
While investigating, found the reference in this doc, and API doc for NewContext says that there should be an Option that allows to restore the state, namely storageState
.
However, browsing the sources it seems that it is not present in the current implementation.
My go.mod
// ...
github.com/mxschmitt/playwright-go v0.1100.0
// ...
If there's a workaround for this, I'd like to know it. I did try saving cookies, and loading them into context, but auth says NO and requires login.
Is there a way to regenerate with this option or are there any plans on adding it?
Thanks!
The above mentioned types don't seem to be used in their respective function calls (WaitForRequest and WaitForResponse).
Looking at the code here confirms that there is no way to set the timeout for those methods (other than setting the default page timeout).
Hi,
When I try to get body of response event the implementation waiting undefined time to load and process, no continue and I have to force finish process
page.On("response", func(response playwright.Response) {
if response.Request().ResourceType() == "xhr" {
tx, _ := response.Text()
fmt.Println(tx)
}
})
Blocked by microsoft/playwright#3503
We can use the upstream documentation, strip out the JavaScript examples like we do in Python and sync it with our codebase.
add support for aws lambda functions or google functions or MS functions for chromium or firefox ,and native drivers using go instead node (versions which is downloaded each time when executing the function so it will consume more resources and time).
I'm calling playwright-go from a TUI and it's cluttering up the TUI with these logs on startup: https://github.com/mxschmitt/playwright-go/blob/067f4185d7b5d1f2fffacbc7ac2cfae47b8afe9a/run.go#L89.
Would it be possible to make these log statements toggleable?
my code:
page.On("response", func(response playwright.Response) {
fmt.Printf("<< %v %s\n", response.Status(), response.URL())
fmt.Println(response.Body())
}
})
Always waiting channel,freezes the code and not returns any value.
python api have is_disabled()
but go have this function
Hello,
thanks for the lib It works great! I faced with some limitations:
I would like to avoid downloading https://github.com/mxschmitt/playwright-go/blob/c9d1531e0354a7f267237b3ac55595a8f18170e4/run.go#L29 after every container start. I assumed that playwright is already installed on the official mcr.microsoft.com/playwright:bionic
images.
It looks like that playwright is installed from an external source https://github.com/mxschmitt/playwright-go/blob/c9d1531e0354a7f267237b3ac55595a8f18170e4/run.go#L15 not the official ones.
How can I install a different playwright version? The current is 1.7
I am hitting this extremely weird issue where this code:
usernameBox, _ := page.QuerySelector("[name=username]")
usernameBox.Type("[email protected]")
does not work with go modules. Although it is able to select the input tag, it fails to populate it with the text passed to 'Type'. As soon as I run this using the old way, it starts working.
Complete code for reference:
pw, err := playwright.Run()
if err != nil {
log.Fatalf("could not start playwright: %v", err)
panic(err)
}
browserLaunchOptions := playwright.BrowserTypeLaunchOptions{
Headless: newFalse(),
DownloadsPath: newDownloadPath(),
}
browser, err := pw.Chromium.Launch(browserLaunchOptions)
if err != nil {
log.Fatalf("could not launch browser: %v", err)
panic(err)
}
browserContextOptions := playwright.BrowserNewContextOptions{
AcceptDownloads: newTrue(),
}
page, err := browser.NewPage(browserContextOptions)
dwnld, _ := page.ExpectDownload(func() error {
if err != nil {
log.Fatalf("could not create page: %v", err)
}
resp, err := page.Goto(linkToWebsite, playwright.PageGotoOptions{
WaitUntil: playwright.WaitUntilStateNetworkidle,
})
Sleep(15, "Website loading")
if err != nil {
log.Fatalf("could not goto: %v", err)
}
log.Println(resp.Status())
if !resp.Ok() {
log.Fatalf("Invalid response returned by %v", linkToWebsite)
}
usernameBox, _ := page.QuerySelector("[name=username]")
op := playwright.ElementHandleTypeOptions{
Delay: newDelay(6),
}
usernameBox.Type("[email protected]", op)
passwordBox, _ := page.QuerySelector("[name=password]")
passwordBox.Type("******")
loginBtn, _ := page.QuerySelector("button")
loginBtn.Click()
Sleep(15000000, "Logged in, waiting for the page to load")
return nil
})
Should fix the broken CI builds.
If ExtraHttpHeaders
value is set in BrowserNewContextOptions
, then the following error occurs at runtime:
$ go run main.go
2021/04/16 12:13:46 Downloading browsers...
2021/04/16 12:13:46 Downloaded browsers successfully
2021/04/16 12:13:47 could not create context: %!w(*fmt.wrapError=&{could not send message: could not send message to server: extraHTTPHeaders: expected array, got object 0xc0001a60a0})
exit status 1
Used the following for testing:
package main
import (
"log"
"github.com/mxschmitt/playwright-go"
)
func assertErrorToNilf(message string, err error) {
if err != nil {
log.Fatalf(message, err)
}
}
func main() {
pw, err := playwright.Run()
assertErrorToNilf("could not launch playwright: %w", err)
browser, err := pw.Firefox.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
})
assertErrorToNilf("could not launch Firefox: %w", err)
context, err := browser.NewContext(playwright.BrowserNewContextOptions{
ExtraHttpHeaders: map[string]string{
"X-Dummy-Header": "test-header",
},
})
assertErrorToNilf("could not create context: %w", err)
page, err := context.NewPage()
assertErrorToNilf("could not create page: %w", err)
_, err = page.Goto("https://duckduckgo.com")
assertErrorToNilf("could not goto: %w", err)
}
After I click a button, the web page shows some text in iFrame.
I have the id of a label in this iFrame.
How can I get the text of the label in this iFrame?
PLease help.
Thanks
Hi @mxschmitt ,
Hope you are all well !
Thanks for this amazing work with playwright-go :-)
I am working on a xss/sqli crawler and I was wondering if it is possible to catch a window alert triggered with playwright ?
Thanks for any insights or inputs on that question.
Cheers,
X.
Currently interfaces get used if an array is passed. It should use the correct type and use an Slice there:
type BrowserNewContextStorageState struct {
Cookies interface{} `json:"cookies"`
Origins interface{} `json:"origins"`
}
Hi,
I'm working with this library and the only thing that I can say is, GREAT JOB!!
I want to replicate the next diagram. Imagine that you have the same app A and B, but A is a daemon (service) and B is the interface. What I want to do is avoid to open the browser every time the user need to do something, I just want to have loaded the broswer and then just go to page that the user is requesting. That is possible?
Thanks in advance.
How can i set the size of the browser(width, height) on first launch and later resize programatically ?
Is this available as feature ?
Great job,
I wanna ask if I can export the html that I scraped?
Thanks in advance
Thanks for this great library and your hardwork to make it great.
From https://pkg.go.dev/github.com/mxschmitt/playwright-go#pkg-index, the methods show out if the type is struct(like Playwright
):
type Playwright
func Run(options ...*RunOptions) (*Playwright, error)
func (c *Playwright) Dispose()
func (p *Playwright) Stop() error
But No method shows out if the type is defined as interface(like Page
), we need to go to the type definition to find the available methods.
type Page
Is it possible to define the Page
as struct?
type Page struct {
// non export fields
}
func (*Page) Click(selector string, options ...PageClickOptions) error
func (*Page) Fill(selector, text string, options ...FrameFillOptions) error
... ...
What do you think about it?
Thanks.
Hi,
I use this lib to build https://github.com/StarpTech/fay a simple HTML to PDF rendering service. It works great so far and the numbers are really promising 👍
I'm getting panic exception instead of err if selector doesn't exist.
Everything works fine when an element exists on the page (<a> tag):
linkElement, err := entry.QuerySelector("a")
if err != nil {
log.Fatalf("could not get link element: %v", err)
}
But panic raised when it doesn't (<a class="someclass"> tag):
linkElement, err := entry.QuerySelector("a.someclass")
if err != nil {
log.Fatalf("could not get link element: %v", err)
}
panic: interface conversion: interface {} is nil, not *playwright.channel
Hello,
(upvote this microsoft/playwright#6856 instead)
since I've joined @microsoft we are considering moving this package over to the organisation. By that we would ensure that all features form the original Playwright project are integrate and bugs are fixed. Currently since it was a private project it got unfortunately not that much attention since my time was limited. For that we are currently evaluating what the use-cases are and how many people in which scenarios are using it.
Would be awesome if you could give us some feedback so you could help us with the decision. In more detail, answer the following questions:
Thank you!
(Thumbs up if you are interested in it)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.