mafredri / cdp

Package cdp provides type-safe bindings for the Chrome DevTools Protocol (CDP), written in the Go programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cdp.Target: CreateBrowserContext: rpc error: Not allowed. (code = -32000)

gulien opened this issue ยท comments

Hello again,

The following error is thrown in Travis CI and has also been reported here gotenberg/gotenberg#15:

cdp.Target: CreateBrowserContext: rpc error: Not allowed. (code = -32000)

It happens here in my code: https://github.com/thecodingmachine/gotenberg/blob/master/internal/pkg/printer/html.go#L55

Google Chrome is installed in a Debian/stretch Docker image: https://github.com/thecodingmachine/gotenberg/blob/master/build/base/Dockerfile#L33.

And it is launched with PM2 using those options:

"--no-sandbox",
"--headless",
"--remote-debugging-port=9222",
"--disable-gpu",
"--disable-translate",
"--disable-extensions",
"--disable-background-networking",
"--safebrowsing-disable-auto-update",
"--disable-sync",
"--disable-default-apps",
"--hide-scrollbars",
"--metrics-recording-only",
"--mute-audio",
"--no-first-run",

๐Ÿค” I have now idea why it is happening. I cannot reproduce it locally (macOS with Docker) as those commands works as expected:

$ docker run --rm -p 3000:3000 thecodingmachine/gotenberg:3
$ curl --request POST \
    --url http://localhost:3000/convert/html \
    --header 'Content-Type: multipart/form-data' \
    --form files=@index.html \
    > result.pdf

Thank you! ๐Ÿ˜„

I suspect this might be a Chrome version issue. In fact, I'm a bit surprised it works for you locally. At least historically, a browser context could not be created from a Page-endpoint. Instead, you had to connect to the Browser-endpoint (available via /json/version).

There's an example of using the browser endpoint in the incognito example, basically you'd change thecodingmachine/gotenberg/internal/pkg/printer/html.go#L41-L52 with:

// Fetch the websocket URL for the browser endpoint.
bver, err := devtool.New("http://localhost:9222").Version(ctx)
if err != nil {
return err
}
bconn, err := rpcc.DialContext(ctx, bver.WebSocketDebuggerURL)
if err != nil {
return err
}
defer bconn.Close()
// Initialize the browser CDP client.
bc := cdp.NewClient(bconn)

Does making this change fix the issue?

Travis CI is now working as expected ๐ŸŽ‰ thank you for the quick answer!

Glad to hear, no problem ๐Ÿ˜„!