Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gulien opened this issue Dec 12, 2018 · 3 comments
Closed

Comments

@gulien
Copy link

gulien commented Dec 12, 2018

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! 😄

@mafredri
Copy link
Owner

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?

@gulien
Copy link
Author

gulien commented Dec 12, 2018

Travis CI is now working as expected 🎉 thank you for the quick answer!

@mafredri
Copy link
Owner

Glad to hear, no problem 😄!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants