ok, I am a new learner to node.js:
when I try to load google.com,and exec the script in the page,like this:
var zombie=require("zombie");
browser = new zombie.Browser({ debug: true })
browser.visit("http://www.google.com",function(err,_browser,status){
if(err){
throw(err.message);
}
})
but get error:
28 Feb 16:06:40 - The onerror handler
on target
{ frames: [ [Circular] ],
contentWindow: [Circular],
window: [Circular],
…………………………
what can I do?
The actual error message is hidden part way down the error output. Within the browser.visit function, add...
console.log(err.message);
...above throw(err.message);. This should give you a better indication of what's going wrong :)
EDIT: Having tested node 0.4.1 / zombie 0.9.1 on www.google.com, it looks like a javascript error (ILLEGAL TOKEN) is causing the problem. You can circumvent javascript errors by setting up your zombie code like so:
browser = new zombie.Browser();
browser.runScripts = false; // this disables executing javascript
browser.visit("http://www.google.com/", function (err, browser) {
if (err) { console.log('Error:' + err.message); }
else { console.log('Page loaded successfully'); }
// ... rest of your code here
});
Personally, I don't find the current zombie error output very helpful, so I prefer to turn it off and display a simple console.log message when something goes wrong.
Lastly, you can also debug errors by passing in debug: true to the browser function:
browser = new zombie.Browser({ debug: true });
This will output all calls (inc. ajax) and might help to pinpoint the source of an error.
Good luck!
Related
When I have an Error in my code, compiling with ts-node, the error does not appear in the console.
For exemple:let data = await fs.readFileSync(path);
I have this code where I use "fs" to read a file, using a path that the function receive as parameter. But when the path is from a file that does not exists nothing happends in the console. The only thing that happens is that the requisition never finish loading.
If I put a console.log like this in the code, the error appears saying that the file does not exists : console.log(fs.readFile(path, (data) => { }))
It doesn't make sense, since the errors are supposed to show in the console. (This happens with lot of type of commum errors that make it harder to finish the application)
here's the repository with all the code https://github.com/Macintosh-1984/Pokedex_Express
somebody help please
You are not capture the error on readFile
fs.readFile(path, 'utf8', function(err, data){
// you have err here
});
Here is the command that is broken:
fs.writeFileSync('Metadata.json', metadataString);
console.log("Metadata written.");
I have placed a breakpoint and verified that metadataString is actually a string. The console logs Metadata written just fine and the file stays empty...
Not sure what else I can check... Thanks in advance.
fs.writeFileSync() throws an Error exception if it fails. Use a try/catch block:
try {
fs.writeFileSync('Metadata.json', metadataString);
} catch (err) {
console.log('Error writing Metadata.json:' + err.message)
}
I'm grunt beginner. But whenever I install any kind of grunt library to handle images it does not work.
grunt-webshot, webshot, getPixels, node-image, node, gm, node-pngjs, imagemagick, node-png, png, get-pixels
grunt.registerTask("getPixels", "your description", function() {
var fs = require('fs') , gm = require('gm');
gm('source/templates/t1/images/menu_item_bg.png').size(function (err, size) {
grunt.log.writeln(size.width > size.height ? 'wider' : 'taller than you');
});
});
Silently fails. No error, no nothing (I get: Done, without errors). Does not enter callback.
Same is with other libraries I used.
Only grunt modules can be used in grunt? Dont Think so, it seems i can use any library by using require() and it should work. It works ok with require('path')
Any way I can debug it? Make it return some kind of error or fix this problem?
Edit
I wrote a makescreenshot.js script which I call with node
var webshot = require('webshot');
// also tried commented varians:
//webshot('google.com', 'google.jpg', function(err) {
//webshot('http://google.com', 'google.jpg', function(err) {
webshot('http://google.com', 'google.jpg', {}, function(err) {
console.log('console.log ERROR: ' + err);
});
It returns the following: console.log ERROR: Error: PhantomJS exited with return value 1
Seems I figured it somehow. The problem seemed to be not properly installed Microsoft Visual Studio I reinstalled MSVS 2013 Express and it started taking screens normally.
WebSocket connection to 'ws://localhost:35729/livereload' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED chromereload.js:9
'WebSocket.URL' is deprecated. Please use 'WebSocket.url' instead. chromereload.js:12
I'm getting this error message in my chrome extension since chrome updated to version 38. I'm not quite sure whats going on here, but now opening most things causes the extension to crash. I used yeoman to scaffold my project at the beginning, and everything was working fine. I tried removing livereload from the manifest, but that seems to break everything. Any help would be appreciated.
Here is the code:
'use strict';
// Reload client for Chrome Apps & Extensions.
// The reload client has a compatibility with livereload.
// WARNING: only supports reload command.
var LIVERELOAD_HOST = 'localhost:';
var LIVERELOAD_PORT = 35729;
var connection = new WebSocket('ws://' + LIVERELOAD_HOST + LIVERELOAD_PORT + '/livereload');
connection.onerror = function (error) {
console.log('reload connection got error' + JSON.stringify(error));
};
connection.onmessage = function (e) {
if (e.data) {
var data = JSON.parse(e.data);
if (data && data.command === 'reload') {
chrome.runtime.reload();
}
}
};
In Chrome this message is emitted when using something like JSON.stringify() or similar on a WebSocket object. These kind of routines will access the WebSocket.URL property, which is deprecated, and emit this warning. Even if your code doesn't explicitly call WebSocket.URL. You can delete this property to mute the warning from Chrome.
var ws = new WebSocket('wss://example.com/');
delete ws.URL;
console.log(JSON.stringify(ws));
So, I have a node server, running expressjs io (uses socket.io), and I'm building a grid map that tracks coordinates in a database.
Only, I've run into a peculiar issue in that my sockets only listen sometimes.
At first there was no error message, and only by chance I let the page run and I got this error.
Uncaught TypeError: Cannot call method '0' of undefined UkPS99A_w96Ae0K570Nt?t=1395276358213&i=0:1
When I click on the file UkPS99A_w96Ae0K570Nt?t=1395276358213&i=0:1 I get this code:
io.j[0]("8::");
If I refresh the page, every few times it will suddenly work find for about 10 tile clicks, and then it stops working. My database is updating properly until the sockets basically die out.
Here is where I send the coordinates in my map:
io.emit("move", {x:this.x,y:this.y});
Server listening:
app.io.route('move', function(req) {
con.getConnection(function(err){
if (err) console.log("Get Connection Error.. "+err);
//removed query because redundant
req.io.emit("talk", {x:req.data.x,y:req.data.y});
});
});
and my socket script:
io.on("talk",function(data) {
console.log(data.x,data.y);
});
My script includes are at the bottom of the page in this order:
<script src="socket.io/socket.io.js"></script>
<script>io = io.connect();</script> <!-- open the socket so the other scripts can use it -->
<script src="../js/sock.js"></script>
<script src="../js/map.js"></script>
Is there something I'm doing wrong to that the socket seems to lose connection and throw some sort of error?
Update: I left the server running longer and a couple more error messages popped up in my console:
Uncaught TypeError: Cannot call method 'close' of null socket.io.js:1967
Uncaught TypeError: Cannot call method 'close' of null socket.io.js:1967
Uncaught TypeError: Cannot call method 'onClose' of null
More update: altered the connection line and added the proper CORS to my server.js
io = io.connect('http://sourceundead.com', {resource : 'socket.io'});
Still the same issue.
You seem to have a connection attrition as you never release them to the pool.
Assuming con is the (bad) name of your pool, instead of
app.io.route('move', function(req) {
con.getConnection(function(err){
if (err) console.log("Get Connection Error.. "+err);
//removed query because redundant
req.io.emit("talk", {x:req.data.x,y:req.data.y});
});
});
you should have something like
app.io.route('move', function(req) {
con.getConnection(function(err, connection){
if (err) console.log("Get Connection Error.. "+err);
//removed query because redundant
req.io.emit("talk", {x:req.data.x,y:req.data.y});
connection.release();
});
});
Be careful that using connections must be done with care to ensure they're always released, and it's a little tedious to do especially when handling errors as soon as you have a few queries to do when doing a task.
At some point you might want to use promises to make that easier. Here's a blog post about using bound promises to ease database querying in node.js.