(node:2136) UnhandledPromiseRejectionWarning: TypeError: browser - javascript

When try to run this url page this is the error i keep getting. Please Advice.
(node:2136) UnhandledPromiseRejectionWarning: TypeError: browser.newpage is not a function
at createPage (C:\Users\xolas\Downloads\Bot development\bot.js:7:32)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:2136) 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:2136) [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.
const puppeteer = require('puppeteer');
const product_url = "https://www.wilko.com/";
async function createPage() {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.goto(product_url);
}
createPage()

Related

Accessibility test case using axe core and webdriverjs - Error: UnhandledPromiseRejectionWarning

I have an automated WebUI tesing case which is supposed to test a website on accessibility. It's working fine and giving me the required output locally on my Mac but unfortunately failing on my VM (Ubuntu 22.04.1 LTS).
This is the source code:
const AxeBuilder = require('#axe-core/webdriverjs');
const { Builder, By, Key, promise, until } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
promise.USE_PROMISE_MANAGER = false;
const options = new firefox.Options();
options.headless();
const driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
async function main() {
await driver.get('https://digital.hamburg.de/').then(() => {
new AxeBuilder(driver).analyze(async (err, results) => {
try {
console.log(results.violations);
} catch (e) {
console.log("Something went wrong", e.message);
} finally {
await driver.close()
}
});
});
}
main();
And the following my output which I'm getting from the VM:
(node:38796) UnhandledPromiseRejectionWarning: Error: Server terminated early with status 2
at /home/jenkins/workspace/test/node_modules/selenium-webdriver/remote/index.js:248:24
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:38796) 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:38796) [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:38796) UnhandledPromiseRejectionWarning: Error: Server terminated early with status 2
at /home/jenkins/workspace/test/node_modules/selenium-webdriver/remote/index.js:248:24
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:38796) 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: 3)
I'm quite a newbie at this and glad for any help.

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined, in my api

I'm testing out my NodeJs api, and that errors occurs. Here is the code of the function that is not working:
const createUser = (req,res) => {
const name = req.body.name;
const email = req.body.email;
const password = req.body.password;
const newUser = new User({name:name, email:email, password:password});
//----
newUser.save()
.then(() => res.json('200'))
.catch(err => {
if(err.keyPattern.name){
res.json("User already exists");
}else if(err.keyPattern.email){
res.json("Email already exists")
}else{
res.status(400).json("ERROR:"+err);
}
})
}
It is not the folder, because every other route works. I tried to console log everything until the line into I wrote //-----, and everything looks great. Now, The save startement seams to have a problem. Here is the complete error:
(node:12584) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined
at C:\Users\mposs\OneDrive\Desktop\Files\projects\moondevdotenv\moondev.env\backend1\controller\userController.js:13:31
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12584) 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:12584) [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 someone help me? Thanks

Twitter API V2.0 returning response with code 203

I'm building an app using the Twitter API V2.0 to get user info by username and it is returning me a code 203 response.
Code:
const { TwitterApi } = require('twitter-api-v2');
const twitterClient = new TwitterApi(tokens.BEARER);
const roClient = twitterClient.readOnly;
const user = await roClient.v2.userByUsername('plhery');
console.log(user);
Response:
(node:404) UnhandledPromiseRejectionWarning: Error: Request failed with code 403
at RequestHandlerHelper.createResponseError (C:\Users\IGOR\Documents\Code\Node\famoso_falou\node_modules\twitter-api-v2\dist\client-mixins\request-handler.helper.js:73:16)
at IncomingMessage.<anonymous> (C:\Users\IGOR\Documents\Code\Node\famoso_falou\node_modules\twitter-api-v2\dist\client-mixins\request-handler.helper.js:114:33)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1317:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:404) 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:404) [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.

Troubles to show the browser using puppeteer from WSL2

i have troubles when i try to execute my script using puppeteer with the "headless" option set up in false to show the browser
Im Working with WSL2, here is my script
const puppeteer = require('puppeteer');
(async () => {
console.log('Start Scraping...');
const browser = await puppeteer.launch({ headless: false }); <-- Here's the problem
const page = await browser.newPage();
await page.goto('https://es.wikipedia.org/wiki/Node.js');
await browser.close();
console.log('End Scraping...');
})()
This is the output when i try to run it
Start Scraping...
(node:3057) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
[3068:3068:0429/043013.248542:ERROR:browser_main_loop.cc(1393)] Unable to open X display.
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (/home/nilsonkr/courses/nodejs/foundaments/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:194:20)
at ChildProcess.<anonymous> (/home/nilsonkr/courses/nodejs/foundaments/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:185:79)
at ChildProcess.emit (events.js:327:22)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3057) 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:3057) [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.
When i set that value to true or just don't write it , it works, but i am still wondering what is the reason and how can i fix it ? to show the browser
i have already tried adding these flags but it didn't work either
const browser = await puppeteer.launch({headless: false,args: ['--no-sandbox', '--disable-setuid-sandbox']});

How do ES6 async/await work with Observables and streams when they fail?

So, I've been trying to replicate this code:
https://github.com/sindresorhus/np/blob/370ef638344ab7115c956b75dc2823850084da39/index.js#L16
And it works. However, if the promise fails, I get an "unhandled promise" warning. Where does the catch statement belong on something like this if at all? Is there a better way to source information like this?
(node:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup
at makeError (/Users/daghassi/git/build/node_modules/execa/index.js:172:9)
at Promise.all.then.arr (/Users/daghassi/git/build/node_modules/execa/index.js:277:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
(node:48454) 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: 5)
(node:48454) [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:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup
at makeError (/Users/daghassi/git/build/node_modules/execa/index.js:172:9)
at Promise.all.then.arr (/Users/daghassi/git/build/node_modules/execa/index.js:277:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:160:7)
(node:48454) 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: 6)
(node:48454) UnhandledPromiseRejectionWarning: Error: Command failed: np patch --no-cleanup
Just put a try/catch block around your await call. This should be the same as if you would call a Promise and provide a catch function.
So if you have a function which getPromise() which returns a promise, you simply do this.
async function asyncFunction() {
try {
const result = await getPromise();
} catch (error) {
// Add your error handling code here
}
}

Categories