nodejs Why can't I use puppeteer-core? - node.js

I am trying to use puppeteer-core and chrome-aws-lambda so I can upload my function to aws lambda but I get an error when running my script locally, I have tried uninstalling and reinstalling the modules but I still get an error, this is my code
const chrome = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');
(async () => {
const browser = await puppeteer.launch({
args: chrome.args,
executablePath: "/home/usern/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br",
headless: chrome.headless,
});
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
})();
It gives me this error, im not sure what to do to fix it
(node:17811) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: ���m�����鹲o�b�Vb%�]!yb: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: �6��d�11�l��L���: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: cannot open c: No such file
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: i��D-mPL�-X�R: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 1: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: U�#.: not found
/home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: 2: /home/connor/Desktop/serverless/node_modules/chrome-aws-lambda/bin/chromium-75.0.3765.0.br: Syntax error: ")" unexpected
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/home/connor/Desktop/serverless/node_modules/puppeteer-core/lib/Launcher.js:342:14)
at Interface.helper.addEventListener (/home/connor/Desktop/serverless/node_modules/puppeteer-core/lib/Launcher.js:331:50)
at Interface.emit (events.js:198:15)
at Interface.close (readline.js:394:8)
at Socket.onend (readline.js:172:10)
at Socket.emit (events.js:198:15)
at endReadableNT (_stream_readable.js:1139:12)
at processTicksAndRejections (internal/process/task_queues.js:81:17)
(node:17811) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:17811) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

puppeteer-core does not include a chrome installation unlike the puppeteer package.
If you wish to use puppeteer in Lambda, try using a Lambda layer that already provides chrome for you such as https://github.com/RafalWilinski/serverless-puppeteer-layers.

Related

NestJS - UnhandledPromiseRejectionWarning

Short version:
I am looking for a way to way to run my NestJS application with the '--trace-warnings' flags that nodeJS offers. Is there some way to do this or does NestJS offer something similar?
Long version:
Hi! NestJS noob here. I am trying to run a dev version of the NestJS application I am working on. However, on starting the application I get the error below.
Clearly, it is missing a catcherror somewhere! However, the dev version has a LOT of updates and this error can be anywhere so I am hoping for a more efficient way of finding this bug than just checking every single new function! In the errormessage there are a few tips on flags to run while starting the application (node --trace-warnings ...). However, these are for node and not NestJS.
So therefore my question; is there some way to run NestJS with the --trace-warnings flag or some other efficient way to find where I am missing the catcherror?
Thanks in advance!
Error:
(node:72899) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:72899) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:72899) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:72899) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:72899) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Well, 6379 is the Redis default port, it seems like Nest cannot connect to it :)
By the way, give a look at this paragraph:
https://docs.nestjs.com/exception-filters#catch-everything
In order to catch every unhandled exception (regardless of the
exception type), leave the #Catch() decorator's parameter list empty,
e.g., #Catch().
import {
ExceptionFilter,
Catch,
ArgumentsHost,
HttpException,
HttpStatus,
} from '#nestjs/common';
#Catch()
export class AllExceptionsFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse();
const request = ctx.getRequest();
const status =
exception instanceof HttpException
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
response.status(status).json({
statusCode: status,
timestamp: new Date().toISOString(),
path: request.url,
});
}
}
To answer your specific question:
I am looking for a way to way to run my NestJS application with the '--trace-warnings' flags that nodeJS offers. Is there some way to do this or does NestJS offer something similar?
I've been trying to do the same thing, and there seems to be next-to-no documentation online on how to do this. Through some trial and error, I've found that this seems to work:
node --trace-warnings -r source-map-support/register --inspect dist/main
Note that this won't rebuild your application (neither when you first start it up, or by watching for changes), so you'll need to do that manually. The debugger is enabled via --inspect switch, remove that if you don't need to debug.
try to use a npm response / request logger like winston or moesif you will get a lot of help trust me.
here are the links for these library for nestjs
https://github.com/scalio/nest-couchdb

Get error when try to post to another domain

I'm trying to post form-urlencoded in Axios
This is my code
const qs = require("qs");
const axios = require("axios");
const tmp = { id: "96e8ef9f-7f87-4fb5-a1ab-fcc247647cce", filter_type: "2" };
axios
.post("https://www.lalal.ai/api/preview/", qs.stringify(tmp))
.then((result) => {
console.log(result);
});
This what I got
(node:2440) UnhandledPromiseRejectionWarning: Error: Request failed with status code 403
at createError (D:\reactjs\crud-mern\server\node_modules\axios\lib\core\createError.js:16:15)
at settle (D:\reactjs\crud-mern\server\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (D:\reactjs\crud-mern\server\node_modules\axios\lib\adapters\http.js:244:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2440) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2440) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Can anyone explain to me what is the error and how to fix it? thanks :D
In the error response it states Request failed with status code 403. 403 usually means "Forbidden" and that you do not have access to perform that request. I would check to make sure you have any access keys, tokens, or authorization required to make that request.
403 Forbidden: The server understood the request, but is refusing to fulfill it. (Source)

Puppeteer cluster sometimes cannot start in k8s

I'm using puppeteer with puppeteer-cluster, this is deployed on k8s and everything works great.
The only problem I'm having is that sometimes the pod won't start, and throws this exception:
(node:24) UnhandledPromiseRejectionWarning: Error: Unable to launch browser, error message: read ECONNRESET
at Cluster.<anonymous> (/app/node_modules/puppeteer-cluster/dist/Cluster.js:107:23)
at Generator.throw (<anonymous>)
at rejected (/app/node_modules/puppeteer-cluster/dist/Cluster.js:6:65)
at process._tickCallback (internal/process/next_tick.js:68:7)
followed by:
(node:24) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
and:
(node:24) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
This doesn't affect me functionally considerably, as k8s just creates a new pod (which works fine), but I'd like to understand what happens, and if I can fix it.
Cluster initialization code:
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: Constants.CONFIG.URL_CONCURRENCY,
retryLimit: Constants.CONFIG.CLUSTER_INTERNAL_RETRIES,
timeout: Constants.CONFIG.MAX_TIMEOUT
puppeteerOptions: { ignoreHTTPSErrors: true, args: ["--no-sandbox"] }
});
versions:
"puppeteer": "^2.0.0",
"puppeteer-cluster": "^0.18.0",

Selenium-WebDriver UnhandeledPromiseRejectionWarning Error

This is my first time using Selenium web driver. I am having issues 'getting' a web address. Here is my code:
const {Builder, By, Key, until} = require('selenium-webdriver'),
app = require('express'),
express = app();
let driver = new Builder().forBrowser('chrome').build();
driver.get('https://google.com'); //<---- known bug(doesn't open proper page)
So there, I am just trying to open google.com Please tell me what I'm doing wrong. Anyway, here's the error when I do, node app.js:
DevTools listening on ws://127.0.0.1:12825/devtools/browser/cd5a8eae-4ff0-482e-9f80-cf49f4c3f794
(node:11584) UnhandledPromiseRejectionWarning: WebDriverError: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"A07868DB3EACD45E5235CB0DA6162B30","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
at Object.checkLegacyResponse (C:\Users\Ben Levy\Desktop\bot\node_modules\selenium-webdriver\lib\error.js:585:15)
at parseHttpResponse (C:\Users\Ben Levy\Desktop\bot\node_modules\selenium-webdriver\lib\http.js:533:13)
at Executor.execute (C:\Users\Ben Levy\Desktop\bot\node_modules\selenium-webdriver\lib\http.js:468:26)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:11584) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11584) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Thanks!
From the error
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
I can see it running old chromedriver 2.9 and not compatible with the Chrome, download the latest version from here.

(node:13606) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object] - Ionic Framework

I'm working with the Ionic Framework in its 3rd version, and when I run ionic cordova build --release android, I get this error :
(node:13791) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object]
(node:13791) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Other threads about this didn't lead me anywhere. Please help
my first attempt would be to check my code for an unhandled promise rejection.
How can i dectect a unhandled promise rejection?
assuming we have a code like this:
asyncAction.then(success => {
// do stuff with the result of success
})
so if the asyncActions fails, there is an unhandled promise rejection because we never catch the rejection of the promise. To catch the rejection we need to do this:
asyncAction.then(success => {
// do stuff with the result of success
}, rejection => {
// handle action failed
})
I solved my problem downgrading cordova version to 7.1.0

Resources