How can I pass an object from server to client make it looking like this in the console?
I tried to use util.inspect(myObject, {showHidden: false, depth: null}),
but it returns a string and I cannot fold/unfold it in the console:
I tried to convert it to an object using var obj = JSON.parse(str);, but it gives me an error:
Uncaught SyntaxError: Unexpected token S in JSON at position 0
or var obj=eval("("+str+")");, but it gives me an error:
Uncaught SyntaxError: Unexpected token {
If you are using devtool or node monkey to connect node.js to your console, then you can simply use:
console.log(myObject);
Or for a more detailed view:
console.dir(myObject);
Node Inspector seems to have (had?) some issues with console ouput.
If you wish to log to stderr instead of stdout you can use:
console.error('%o',myObject)
Related
How to handle the error: Error: getaddrinfo ENOTFOUND unexistantwebsite.com with the node package Websocket(Ws) without making the app crashing ?
I just tryed to create a websocket connect on an non-existant website and that make all the app crashing :
var ws = new WebSocket('wss://unexistantwebsite.com/', {
binaryType: "arraybuffer"
});
I tried many way to handle the error but nothing works.
Surround with try catch: KO
Add .catch on the constructor end: KO (even invalid that's normal I suppose)
I just want to handle the error avoiding the app to crash.
When trying to scrape linkedin search results via puppetteer, i noticed that the search results page shows a blank. Upon investigation, i noticed in the developer console inside chromium launched by puppeteer this error:
Error while processing route: search.results.people Unexpected token % in JSON at position 0 SyntaxError: Unexpected token % in JSON at position 0
at JSON.parse (<anonymous>)
at u.s._deserializeQueryParam (https://static-exp1.licdn.com/sc/h/br/6n33815bd6sdo077qodh7watx:3028:140)
....
6n33815bd6sdo077qodh7watx:3028 Uncaught (in promise) SyntaxError: Unexpected token % in JSON at position 0
at JSON.parse (<anonymous>)
at u.s._deserializeQueryParam (6n33815bd6sdo077qodh7watx:3028)
....
This error does not occur if I launch chromium manually and load the same search URL.
This is preventing the search results from loading
Any ideas?
FYI Video that explains this: https://www.youtube.com/watch?v=GYhrDWLJJ9o
Steps to reproduce
Tell us about your environment:
Puppeteer version: latest (v4.0.0)
Platform / OS version: Ubuntu 18.04 LTS
URLs (if applicable): Searching linkedin (here's an example url) - you need to login to your linkedin account to set the cookies
Node.js version: v13.13.0 . NPM version 6.14.4
What steps will reproduce the problem?
const browser = await puppeteer.launch({
"ignoreHTTPSErrors": true,
"headless" : false,
"args" :[
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-gpu',
'--start-maximized',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
`--window-size=1200,800`,
'--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36',
]});
let page = await browser.newPage();
await page.setViewport({"width": c["width"],"height": c["height"]});
await page.setUserAgent(c["user_agent"]);
await page.goto(c["url"])
(where c["url"] is the link above)
The developer console on chromium has thjis output, which affects the page from rendering anything:
Error while processing route: search.results.people Unexpected token % in JSON at position 0 SyntaxError: Unexpected token % in JSON at position 0
at JSON.parse (<anonymous>)
at u.s._deserializeQueryParam (https://static-exp1.licdn.com/sc/h/br/6n33815bd6sdo077qodh7watx:3028:140)
....
6n33815bd6sdo077qodh7watx:3028 Uncaught (in promise) SyntaxError: Unexpected token % in JSON at position 0
at JSON.parse (<anonymous>)
at u.s._deserializeQueryParam (6n33815bd6sdo077qodh7watx:3028)
....
I tried upgrading chromium to latest. Nothing
Also tried on chrome by setting executablePath. Oddly enough, this error only shows up when going through puppeteer but not when I manually launch browser and go to the same URL.
What is the expected result?
Expected output doesn't show at all. Expected page an be seen if you just manually open browser and go to the URL as specified above.
What happens instead?
Page shows no search results.
Sounds like it doesn't like how that parameter is escaped.
https://www.linkedin.com/search/results/people/?facetGeoRegion=%5B%22us%3A296%22%5D&keywords=dwayne&origin=GLOBAL_SEARCH_HEADER
should be:
https://www.linkedin.com/search/results/people/?facetGeoRegion=["us:296"]&keywords=dwayne&origin=GLOBAL_SEARCH_HEADER
I am integrating mangopay in node js and I am using npm for mangopay2-nodejs-sdk.but when I use api.Users.create function for creating user ,it gives me error
Debug: internal, implementation, error
TypeError: Uncaught error: Cannot read property 'userClass' of undefined
at Service.extend.create (/home/hashir/artpaie/artapieapp/artapieBackend/node_modules/mangopay2-nodejs-sdk/lib/services/Users.js:38:41)
The error handler in _getUserApiAndClass method seems not to be working, my problem was that I didn't have specified the PersonType.
It is uppercase
Natural: 'NATURAL'
Legal: 'LEGAL'
I am trying this:
https://electron.atom.io/docs/api/protocol/
And I get this error:
https://google.com/#q=standard%2Fno-callback-literal Unexpected literal in error position of callback
Why is it not working?
Solution is to install this so the callback can work:
https://github.com/xjamundx/eslint-plugin-standard
I am very new to node.js, I just followed the steps to create a simple node.js application. Here it is on github
I ran the command jitsu deploy from the terminal to deploy it on nodejitsu, however I got this error right here, please any help on what could be wrong with code files?
Here is the code on git hub
Here is the error that is appearing:
prompt: Is this ok?: (yes) yes
info: Creating snapshot 0.0.0-5
info Uploading: [=============================] 100%
info: Updating app test
info: Activating snapshot 0.0.0-5 for test
info: Starting app test
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: Error spawning drone
error: Script took too long to listen on a socket
error:
error: This type of error is usually a user error.
error: Error output from Haibu:
error:
error: Error: Error spawning drone
error: at Object.onTimeout [as _onTimeout] (/root/haibu-orchestra/node_mod
ules/haibu/lib/haibu/core/spawner.js:396:15)
error: at Timer.list.ontimeout (timers.js:101:19)
help: For help with this error contact Nodejitsu Support:
help: webchat: <http://webchat.nodejitsu.com/>
help: irc: <irc://chat.freenode.net/#nodejitsu>
help: email: <support#nodejitsu.com>
You're server.js is exporting a function, but that doesn't get run. Just the body of your start function as top-level code directly inside the server.js module so that it executes when nodejitsu starts your application.
Nodejitsu is very picky about how quick your deployments listen on the system. There is a certain time frame between the start of deployment and end of deployment before your deployment is considered a failure. When it doesn't listen on a port for so long, it ends up giving you this error.
Rather than using your current start function, why don't you try creating your HTTP socket in index.js and then passing it into your start function as well, since you're already passing routes and handle to it?
For example, in index.js:
var http = require('http'),
server = http.createServer().listen(8080);
start(server, router.route, handle);
Then, rather than using http.createServer(onRequest).listen(8080) in your server.js file, you can use something like:
var start = function (server, route, handle) {
function onRequest(request, response) {
/* Your request stuff here */
}
server.on('request', onRequest);
};
This would most likely solve the whole problem.