Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Last active June 4, 2024 00:44
Show Gist options
  • Save douglasmiranda/ce242e6025513c5e975c176709d1343b to your computer and use it in GitHub Desktop.
Save douglasmiranda/ce242e6025513c5e975c176709d1343b to your computer and use it in GitHub Desktop.
Browserless / Puppeteer (Protocol error (Runtime.callFunctionOn): Target closed) Timeout Issue

Error: Protocol error (Runtime.callFunctionOn): Target closed

Browserless v2.6.1 running on Docker

I don't know why this happens, but it doesn't matter if you set your TIMEOUT environment variable, like so:

services:
  browserless:
    image: ghcr.io/browserless/chrome
    environment:
      - ALLOW_GET=true
      - TOKEN=a
      - TIMEOUT=1200000
    ports:
      - "3000:3000"

...or if you set "timeout" in your request to browserless HTTP API

http://localhost:3000/chrome/function?token=a&timeout=1200000

You will still get the some timeout error.

IF you're using an endpoint that receives a json body, just check their docs, you may be able to fix some timeout issues by using the gotoOptions option.

{
  "url": "https://example.com",
  "gotoOptions": {
    "timeout": 1200000
  }
}

https://docs.browserless.io/open-api/#tag/Browser-REST-APIs/paths/~1chrome~1pdf/post

The endpoint /chrome/function does not have that option (gotoOptions). As far as I know, if someone knows just correct me in the comments.

So the solution I found for now is to set the timeout directly in my goto request.

Something like: await page.goto("https://example.com", {waitUntil: 'load', timeout: 120000}); just like in the example below:

export default async function ({ page }) {
  await page.goto("https://example.com", {waitUntil: 'load', timeout: 120000});
  // do stuff   
  return {
    data: {
      a: true
    },
    type: "application/json",
  };
}

More:

  • you may want to look for the wait* puppeteer args.
  • puppeteer/puppeteer#4863
  • await page.goto(url, {waitUntil: 'networkidle2'}); heavy pages with many requests seems to benefit from this
  • seems like changing lauch option protocolTimeout (puppeteer) can help with timeouts also
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment