Troubles to show the browser using puppeteer from WSL2 - javascript

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']});

Related

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.

IPFSAccessController.save ERROR: Error: Deprecated, use .toString()

i'm only trying to launch the exemple of the app kit OrbitDB which is :
import OrbitDB from "orbit-db";
import IPFS from "ipfs";
async function main () {
// Create IPFS instance
const ipfsOptions = { repo : './ipfs', }
const ipfs = await IPFS.create(ipfsOptions)
// Create OrbitDB instance
const orbitdb = await OrbitDB.createInstance(ipfs)
// Create database instance
const db = await orbitdb.keyvalue('ipfs_db')
}
main()
you can find it here : https://github.com/dappkit/aviondb#using-nodejs
but the problem is when i launch it, i got these errors :
Swarm listening on /ip4/127.0.0.1/tcp/4002/p2p/12D3KooWM7D9NdMhtxyiWiKH4XVpuZW5oDu9MbWxFmEzLsG9UynM
Swarm listening on /ip4/192.168.1.53/tcp/4002/p2p/12D3KooWM7D9NdMhtxyiWiKH4XVpuZW5oDu9MbWxFmEzLsG9UynM
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/p2p/12D3KooWM7D9NdMhtxyiWiKH4XVpuZW5oDu9MbWxFmEzLsG9UynM
IPFSAccessController.save ERROR: Error: Deprecated, use .toString()
at CID.get toBaseEncodedString [as toBaseEncodedString] (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/multiformats/cjs/src/cid.js:94:11)
at Object.writeCbor [as write] (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db-access-controllers/node_modules/orbit-db-io/index.js:62:14)
at async IPFSAccessController.save (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db-access-controllers/src/ipfs-access-controller.js:46:13)
at async Function.create (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db-access-controllers/src/access-controllers.js:68:20)
at async OrbitDB._determineAddress (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/aviondb/node_modules/orbit-db/src/OrbitDB.js:331:37)
(node:8397) UnhandledPromiseRejectionWarning: Error: `undefined` is not supported by the IPLD Data Model and cannot be encoded
at undefinedEncoder (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/#ipld/dag-cbor/cjs/index.js:47:9)
at objectToTokens (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:175:20)
at Object (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:149:9)
at objectToTokens (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:184:10)
at Object (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:149:9)
at objectToTokens (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:184:10)
at encodeCustom (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:214:18)
at Object.encode (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/cborg/cjs/lib/encode.js:236:10)
at Object.encode (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/#ipld/dag-cbor/cjs/index.js:85:41)
at put (/home/zar/Etna4/SmartContract/db_ipfs/node_modules/ipfs-core/src/components/dag/put.js:35:25)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8397) 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:8397) [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.
i seriously don't know what to do, i tried to clear the cache, to delete node_modules and package-lock.json, and do a npm install, but nothing changed, i got the same error, do you have any idea to fix this ?
This error clearly points to an incompatibility between IPFS and OrbitDB.
The latest version of js-ipfs that OrbitDB v0.26.1 supports is 0.55.4.
You should change the ipfs (or ipfs-core) version in your package.json to ^0.55.4.
Note: The upcoming OrbitDB v0.27, will support the latest IPFS version.

I'm having a problem with a node js project, my server wont respond and will throw me an error [duplicate]

This question already has answers here:
MongooseError - Operation `users.findOne()` buffering timed out after 10000ms
(17 answers)
Closed 1 year ago.
My js file wont respond and it will trow me this error in the console wich i don't understand:
[nodemon] restarting due to changes...
[nodemon] starting `node index.js`
Backend server is running
Connected to MONGODB
(node:5282) UnhandledPromiseRejectionWarning: MongooseError: Operation
`users.insertOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/home/francesco/Desktop/Projects/Social Network/NODE-REST-
API/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:149:23)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5282) 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:5282) [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 is the code of the module (btw dont mind but th "ok" its for testing.
const router = require("express").Router();
const User = require("../models/User")
//REGISTER
router.get("/register", async (req,res)=>{
const user = await new User({
username:"john",
email:"john#gmail.com",
password:"123456"
})
await user.save();
res.send("ok");
});
module.exports = router
the syntax is right, needed to format it for containing on the "code" on the question.
Thanks in advance, Francesco
You are trying to call the model without even establishing a connection with the database. You need to use async/await with connect() or createConnection().

(node:2136) UnhandledPromiseRejectionWarning: TypeError: browser

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()

Understanding why Puppeteer wont load a website

I have some simple code
const puppeteer = require('puppeteer');
async function getPic() {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://www.paniniamerica.net');
await page.screenshot({path: 'panini.png'});
await browser.close();
}
getPic();
I noticed that this specific website just times out. Other websites like google.com or even stackoverflow.com work fine. Is this website blocking this type of behavior?
This is the error it spits out.
(node:63995) UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!
at CDPSession.LifecycleWatcher._eventListeners.helper.addEventListener (/Users//Desktop/test/node_modules/puppeteer/lib/LifecycleWatcher.js:46:107)
at CDPSession.emit (events.js:182:13)
at CDPSession._onClosed (/Users//Desktop/test/node_modules/puppeteer/lib/Connection.js:215:10)
at Connection._onMessage (/Users//Desktop/test/node_modules/puppeteer/lib/Connection.js:105:17)
at WebSocketTransport._ws.addEventListener.event (/Users//Desktop/test/node_modules/puppeteer/lib/WebSocketTransport.js:44:24)
at WebSocket.onMessage (/Users//Desktop/test/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:182:13)
at Receiver.receiverOnMessage (/Users//Desktop/test/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:182:13)
at Receiver.dataMessage (/Users//Desktop/test/node_modules/ws/lib/receiver.js:422:14)
-- ASYNC --
at Frame.<anonymous> (/Users//Desktop/test/node_modules/puppeteer/lib/helper.js:111:15)
at Page.goto (/Users//Desktop/test/node_modules/puppeteer/lib/Page.js:674:49)
at Page.<anonymous> (/Users//Desktop/test/node_modules/puppeteer/lib/helper.js:112:23)
at getPic (/Users//Desktop/test/test.js:6:14)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:63995) 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:63995) [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.

Categories