0

I am trying to connect to a puppeteer instance that runs on a google cloud function v2.

This is the setup inside the function:

import getPort from 'get-port';
import puppeteer from "puppeteer-extra";

const port = await getPort();
const browser = await puppeteer.launch({
    args: [
        `--remote-debugging-port=${port}`,
    ],
});

console.log(browser.wsEndpoint());

this logged an endpoint. I copied that endpoint and tried to connect to from a client it via

await puppeteer.connect(myEndpoint);

but it threw an error:

SocketException: OS Error: The remote computer refused the network connection. How can I fix that?

Christian
  • 834
  • 7
  • 18

1 Answers1

1

The error you encountered is quite in common when you work with websockets and port connections.You can check that if this error occurs always during the connect request, it indicates that the machine exists but that it has no services listening on the specified port, or there is a firewall stopping you.The simplest starting point to check and eliminate the most probable cause could be to try to connect manually from the client machine using telnet or Putty. If that succeeds, then the problem is in your client code. If it doesn't, you need to see if the websocket endpoint string has the correct value.

As per the puppeteer documentation,check the string value for browser websocket endpoint as per below : puppeteer.connect(options) options <Object>browserWSEndpoint <?string> a browser websocket endpoint to connect to. This returns: Browser websocket url.Browser websocket endpoint which can be used as an argument to puppeteer.connect.The format is

ws://${host}:${port}/devtools/browser/<id>

You can find the webSocketDebuggerUrl from http://${host}:${port}/json/version.
Learn more about the devtools protocol and the browser endpoint.
Also check the below links for similar implementations:

Vaidehi Jamankar
  • 1,232
  • 1
  • 2
  • 10