Why does not work Puppeteer-firefox on servers? - javascript

I'm trying to run on Windows Server 2008 and 2016
Are there any solutions to launch it? I searched a lot but found nothing.
I get an error:
C:\Users\Administrator\Desktop\_t>node app.js
ERROR: The process "1212" not found.
(node:4276) UnhandledPromiseRejectionWarning: Error: Failed to launch Firefox!
at onClose (C:\Users\Administrator\Desktop\_t\node_modules\puppeteer-firefox
\lib\Launcher.js:263:14)
at Interface.helper.addEventListener (C:\Users\Administrator\Desktop\_t\node
_modules\puppeteer-firefox\lib\Launcher.js:252:50)
at Interface.emit (events.js:187:15)
at Interface.close (readline.js:379:8)
at Socket.onend (readline.js:157:10)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
-- ASYNC --
at Puppeteer.<anonymous> (C:\Users\Administrator\Desktop\_t\node_modules\pup
peteer-firefox\lib\helper.js:31:27)
at C:\Users\Administrator\Desktop\_t\a.js:253:21
at afterLogin (C:\Users\Administrator\Desktop\_t\a.js:277:4)
at Object.start (C:\Users\Administrator\Desktop\_t\a.js:101:2)
at Object.<anonymous> (C:\Users\Administrator\Desktop\_t\app.js:156:7)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:282:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
(node:4276) 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:4276) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.
On Ubuntu server:
(node:7869) UnhandledPromiseRejectionWarning: Error: Failed to launch Firefox!
at onClose (/root/node_modules/puppeteer-firefox/lib/Launcher.js:263:14)
at Interface.helper.addEventListener (/root/node_modules/puppeteer-firefox/lib/Launcher.js:252:50)
at Interface.emit (events.js:194:15)
at Interface.close (readline.js:379:8)
at Socket.onend (readline.js:157:10)
at Socket.emit (events.js:194:15)
at endReadableNT (_stream_readable.js:1103:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
-- ASYNC --
at Puppeteer.<anonymous> (/root/node_modules/puppeteer-firefox/lib/helper.js:31:27)
at /root/a.js:255:21
at afterLogin (/root/a.js:269:4)
at Object.start (/root/a.js:102:2)
at Object.<anonymous> (/root/app.js:156:7)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
(node:7869) 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:7869) [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.
Does it work on at least some server?
Everything works fine on my Desktop computer.
Requires a version for working with the Firefox
Puppeteer-firefox

I had the same problem (failed to Launch Firefox) on my VPS Windows.
So i went to node_modules/puppeteer-firefox/.local-browser/.../firefox.exe and i tried to open it. I had the 0xc00007b error when i tried to open the exe file.
Download "All in One Runtimes" for Windows and start the installation of all softwares. I maked this and this works for me.
Try it and tell me !
Edit: (sorry for the bad english)

Please don't use the puppeteer-firefox package anymore. It has been deprecated.
Experimental support for Firefox is included in the official puppeteer package now.
Here an example from the Puppeteer repository in how to run your script against Firefox:
(async () => {
const browser = await puppeteer.launch(firefoxOptions);
const page = await browser.newPage();
console.log(await browser.version());
await page.goto('https://news.ycombinator.com/');
// Extract articles from the page.
const resultsSelector = '.storylink';
const links = await page.evaluate((resultsSelector) => {
const anchors = Array.from(document.querySelectorAll(resultsSelector));
return anchors.map((anchor) => {
const title = anchor.textContent.trim();
return `${title} - ${anchor.href}`;
});
}, resultsSelector);
console.log(links.join('\n'));
await browser.close();
})();
If there is still a problem in launching Firefox, then please let us know and we can get it fixed.

Related

Logging messages from one channel

I've tried several times to work this and I don't understand the error, I am receiving but I'll explain what I'm trying to do: Basically I want to log the messages from one channel and paste those messages onto a different channel. Here is the code I have so far;
client.on(`message`, message => {
if (message.author.bot) return; // If the message is by a bot return.
if (!message.guild) return; // If the message isn't in a guild return.
if (message.guild) {
const msgLog = `[MESSAGE] [${message.guild.name}] [#${message.channel.name}] ${message.author.username}#${message.author.discriminator}: ${message.content}\n` // You can change this to whatever you want.
client.channels.get(`814685640088223795`).send(msgLog); // Replace CHANNEL ID with the channel ID you want the logs to go to.
return;
}
})
The error I am receiving goes as follows:
(node:17260) UnhandledPromiseRejectionWarning: ReferenceError: client is not defined
at Object.<anonymous> (D:\stuff\S1 Discord Bot\s1-bot\src\events\message\message.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at registerEvents (D:\stuff\S1 Discord Bot\s1-bot\src\utils\registry.js:33:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:17260) 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:17260) [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
You are missing this from your index file:
const Discord = require("discord.js");
//under const Discord etc
const client = new Discord.Client();
If you are trying to only allow guildMessages, you do it like this:
if (message.channel.type === "dm") return; //dont react to dms
Finally, to send a message to a channel by id:
message.guild.channels.cache.get('814685640088223795').send(msglog); //using 'cache' since v12 uses managers
You seem to be missing two important lines of code:
const Discord = require('discord.js');
const client = new Discord.Client();
Appending these two lines from the discord.js documentation in the beginning of your index.js file should make it work.

How to handle the unhandelable errors?

I'm facing a problem with error handling in NodeJS,
While I was testing an application that I made, I noticed that if I passed undefined by mistake to the mongoose.connect() it will give you an error, unfortunately, this error is not being caught by the callback function, not either by try & catch blocks:
const envVariable = undefined;
try {
mongoose.connect(envVariable, (err) => {
if (err) return console.log("There was an error");
console.log("success");
});
} catch (error) {
console.log("Hah! I caught you");
}
You see the error is not being caught, see the output:
(node:36807) UnhandledPromiseRejectionWarning: MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined". Make sure the first parameter to `mongoose.connect()` or `mongoose.createConnection()` is a string.
at NativeConnection.Connection.openUri (.../nodeJS/tests/node_modules/mongoose/lib/connection.js:680:11)
at .../nodeJS/tests/node_modules/mongoose/lib/index.js:345:10
at .../nodeJS/tests/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise (<anonymous>)
at promiseOrCallback (.../nodeJS/tests/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose._promiseOrCallback (.../nodeJS/tests/node_modules/mongoose/lib/index.js:1135:10)
at Mongoose.connect (.../nodeJS/tests/node_modules/mongoose/lib/index.js:344:20)
at Object.<anonymous> (.../nodeJS/tests/server.js:8:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
(Use `node --trace-warnings ...` to show where the warning was created)
(node:36807) 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:36807) [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've faced these kinds of problems many times in my application, but this time I caught one here to open the discussion, how can I stop these kinds of errors to show in my face? and instead, handle them in a nice way?
handle = to catch when this problem happens, and to send a nice response to the client that there was a problem from the server side.
The moongoose.connect function takes the callback as its third argument, after connection string and options object. It returns a promise, which is getting rejected on the error, but you are never handling that.
The proper syntax is either
try {
await mongoose.connect(envVariable);
console.log("success");
} catch (error) {
console.log("Hah! I caught you");
}
or
mongoose.connect(envVariable).then(() => {
console.log("success");
}, (err) => {
console.log("Hah! I caught you");
});

Cannot connect to MySQL database with Node.js

My app has to connect to a mysql database but i am stuck just in that moment i cant connect it, im using a method that transforms callbacks code to promise code thats the reason i need to use async and await also the man of the tutorial doesnt have any error i guess because he has diferent terms on the keys.js, he is on linux, root user and also he has a password, things that i dont have. I really need hel thank you.
This is the code that is giving problems:
const express= require('express');
const router= express.Router();
const pool = require('../database');
router.get('/add', (req,res) =>{
res.render('casas/add');
});
router.post('/add', async (req,res) => {
const {titulo, precio, direccion, numhab, superficie} = req.body;
const nuevoPiso={
titulo,
precio,
direccion,
numhab,
superficie
};
await pool.query('INSERT INTO PISOS set ?', [nuevoPiso]);
res.send('recibido');
});
module.exports=router;
The problem is on the await line because if I delete that and the async word it works perfectly but obviously without that I cant send the elements to the database. The error that gives me the terminal is this:
(node:9548) UnhandledPromiseRejectionWarning: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'Axell'#'localhost' (using password: NO)
at Handshake.Sequence._packetToError (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
--------------------
at Protocol._enqueue (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:202:8)
at internal/util.js:297:30
at new Promise (<anonymous>)
at Pool.query (internal/util.js:296:12)
at C:\Users\Axell\Desktop\node-sql-app\src\routes\casas.js:20:15
at Layer.handle [as handle_request] (C:\Users\Axell\Desktop\node-sql-app\node_modules\express\lib\router\layer.js:95:5)
(node:9548) 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:9548) [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.
POST /casas/add - - ms - -
(node:9548) UnhandledPromiseRejectionWarning: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'Axell'#'localhost' (using password: NO)
at Handshake.Sequence._packetToError (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
--------------------
at Protocol._enqueue (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\Users\Axell\Desktop\node-sql-app\node_modules\mysql\lib\Pool.js:202:8)
at internal/util.js:297:30
at new Promise (<anonymous>)
at Pool.query (internal/util.js:296:12)
at C:\Users\Axell\Desktop\node-sql-app\src\routes\casas.js:20:15
at Layer.handle [as handle_request] (C:\Users\Axell\Desktop\node-sql-app\node_modules\express\lib\router\layer.js:95:5)
(node:9548) 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)
POST /casas/add - - ms - -
I dont know where the error is maybe on my keys.js where i have this im on windows that is my username but I dont have a password:
module.exports={
database:{
host:'localhost',
user:'Axell',
database: 'casas',
password: ''
}
};
Here you can download the whole app it is unfinished because I cant continue due to this error: https://mega.nz/#!LAwgwAQK!OiuBqH4qxyT5CW2xRSUXdmhpfRyTtf3TobmYw-NqIic
Thank you so much!
The issue you are having is unrelated to async/await.
The credentials to MySQL incorrect. This could be an incorrect username, an incorrect password or perhaps you did not grant the Axell permission to access the casas database.
Given that you're on localhost, you can test this without localhost. Just try logging on with the same credentials with some other mysql tool (such as the mysql) tool, and you should get a similar error.

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.

AssertionError [ERR_ASSERTION]: Invalid register options "value" must be an object

I am trying to setup a nodeJS application that .
Using Hapi and PostgreSQL DB.
Referred all documentations but the error persists.
While server.register
server.register({
register: require('hapi-node-postgres'),
options : {
connectionString: "Postgresdb://dbuser:dbpassword#localhost/dbName"
}
}, err => {
console.log(err);
});
The error that is coming is:
UnhandledPromiseRejectionWarning: ***AssertionError [ERR_ASSERTION]: Invalid register options "value" must be an object
at Object.exports.apply*** (/home/sc/code/Reporting(proto)/node_modules/hapi/lib/config.js:22:10)
at internals.Server.register (/home/sc/code/Reporting(proto)/node_modules/hapi/lib/server.js:367:26)
at Object.<anonymous> (/home/sc/code/Reporting(proto)/index.js:16:8)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
(node:15989) 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:15989) [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.
Please assist.
I am using
"hapi": "^17.5.3"
"hapi-node-postgres": "^4.1.0"
You are using v16 options for registering the plugin as that method is no longer support for the v17 try this link

Categories