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

[BUG] ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed. #28

Closed
dobomode opened this issue Dec 26, 2022 · 10 comments · Fixed by #76
Closed

[BUG] ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed. #28

dobomode opened this issue Dec 26, 2022 · 10 comments · Fixed by #76
Labels
bug Something isn't working

Comments

@dobomode
Copy link

Environment

  • chromium Version: 109.0.0
  • puppeteer / puppeteer-core Version: 19.4.0
  • Node.js Version: 18.x
  • Lambda / GCF Runtime: nodejs18.x
  • Serverless framework
  • Local development on Mac using serverless offline plugin

Expected Behavior

Page should load without errors.

Current Behavior

Getting an error:
ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed.

Steps to Reproduce

        const executablePath = IS_OFFLINE
              ? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
              : await chromium.executablePath;
        browser = await chromium.puppeteer.launch({
            args: chromium.args,
            defaultViewport: chromium.defaultViewport,
            executablePath: executablePath,
            headless: true,
            ignoreHTTPSErrors: true,
        });

When using deprecated @sparticuz/chrome-aws-lambda package, there is no error.

@dobomode dobomode added the bug Something isn't working label Dec 26, 2022
@dobomode dobomode changed the title [BUG] [BUG] ProtocolError: Protocol error (Runtime.callFunctionOn): Target closed. Dec 27, 2022
@daveykane
Copy link

I'm also getting this, it seems to be an issue with the docker image that Serverless is using. The error I'm seeing is

localstack_main | [0124/171548.356439:ERROR:nss_util.cc(124)] Error initializing NSS without a persistent database: libsoftokn3.so: cannot open shared object file: No such file or directory

@Sparticuz
Copy link
Owner

Interesting, I believe that file is included in the aws.tar.br file, but it is only used when running on a native aws image. @daveykane, you are also trying to user sls offline?

@daveykane
Copy link

daveykane commented Jan 24, 2023

No I’m using serverless-localstack the stack successfully deploys but when I run sls invoke I get the above error.

The browser launches and I can create a new page but during page.evaluate that error gets thrown.

I’ll debug the package to see if aws.tar.br is being used.

@Sparticuz
Copy link
Owner

In order to autorun the aws.tar.br file, take a look at https://github.com/Sparticuz/chromium/blob/master/source/index.ts#L41

It requires AWS_EXECUTION_ENV to be set to something that will satisfy that regex. Is that env var set in serverless-localstack?

@daveykane
Copy link

daveykane commented Jan 25, 2023

It is yes, the value is AWS_Lambda_nodejs14.x and I can see from debugging that condition that at the end LD_LIBRARY_PATH is /tmp/aws/lib:/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib

This line is also being fired ok https://github.com/Sparticuz/chromium/blob/master/source/index.ts#L217

@daveykane
Copy link

I can see the following list of files in on the lambda during execution in the dir /tmp/aws/lib but I'm not sure why Chromium isn't finding them

[
  'libexpat.so.1',
  'libnss3.so',
  'libnssutil3.so',
  'libsoftokn3.so',
  'libsqlite3.so.0',
  'libuuid.so.1'
]

@hasan-wajahat
Copy link

I am never able to run chrome in local docker setting using my Mac either. I also get a protocol error. But the same docker container runs on aws lambda and on windows machine. This was true for native chromium package and it seems to be true for this package as well.

@hasan-wajahat
Copy link

Hey @Sparticuz the above mentioned fix makes it work in docker for macos? Were you able to do so yourself?

@Sparticuz
Copy link
Owner

This package can't support arm yet, so you need to run your own version of chromium until I'm able to support arm. I've documented how you can do that natively. In a docker, you'll need to do some trickery. Either do a bind mount to a host version of chromium, or run some code on container start to install chromium. (see @puppeteer/browsers)

@hasan-wajahat
Copy link

Thanks for the info @Sparticuz!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants