Lambda AWS - Error: connect ECONNREFUSED 127.0.0.1:9222
matheusbento opened this issue · 6 comments
Hello guys I'm having the following error when trying to run serverless-chrome on lambda.
`
2022-04-13T13:04:41.496Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Spawning headless shell
2022-04-13T13:04:41.498Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: ChromeLauncher No debugging port found on port 9222, launching a new Chrome.
2022-04-13T13:04:41.604Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Launcher Chrome running with pid 24 on port 9222.
2022-04-13T13:04:41.604Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 0
2022-04-13T13:04:42.106Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 1
2022-04-13T13:04:42.608Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 2
2022-04-13T13:04:43.110Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 3
2022-04-13T13:04:43.611Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 4
2022-04-13T13:04:44.113Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 5
2022-04-13T13:04:44.614Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 6
2022-04-13T13:04:45.116Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 7
2022-04-13T13:04:45.617Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 8
2022-04-13T13:04:46.119Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 9
2022-04-13T13:04:46.621Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Waiting for Chrome 10
2022-04-13T13:04:46.622Z 9b8249dc-60ad-560c-a06f-130cac3fd345 INFO @serverless-chrome/lambda: Error trying to spawn chrome: Error: connect ECONNREFUSED 127.0.0.1:9222 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 9222}
My code to connect with puppeteer
this.chrome = await getChrome();
puppeteer.use(StealthPlugin());
this.browser = await puppeteer.connect({
args: ['--no-sandbox'],
browserWSEndpoint: this.chrome.endpoint,
dumpio: true,
headless: this.isHeadLess,
disableGpu: this.isHeadLess,
slowmo: 10,
});
My code to getChrome:
export const getChrome = async () => {
try {
const chrome = await launchChrome(
process.env.APP_DEV == 'prod'
? {
flags: ['--window-size=1280,1696', '--hide-scrollbars'],
}
: { chromePath: process.env.PUPPETEER_EXEC_URL },
);
console.log({ chrome });
const response = await request
.get(`${chrome.url}/json/version`)
.set('Content-Type', 'application/json');
const endpoint = response.body.webSocketDebuggerUrl;
return {
endpoint,
instance: chrome,
};
} catch (e) {
console.log({ e });
}
};;`
I also had this error:
DevTools listening on ws://127.0.0.1:9222/devtools/browser/b3db09ab-4250-4c63-be21-07eb1eeefa3d
[0413/133945.501862:FATAL:platform_font_skia.cc(97)] Check failed: InitDefaultFont(). Could not find the default font
I also hit this error every time I make a request.
@jeremyhaile If you had some progress, share it with me, please. I'm using docker to build my AWS lambda.
@matheusbento I haven't found a workaround yet, but if I do I will post it here!
Any solution?
Hey guys, I finally found a solution:
https://medium.com/@mrbento/deploy-webscrapping-puppeteer-nestjs-to-aws-lambda-c0cb4ce99cd7