I've been working on an AJAX script to perform some simple test manipulations via the Node.JS MongoDB driver. This script is causing me no end of headaches, for the following reasons:
When I run the script natively in the node.js command prompt, it runs to completion, and performs all of the operations I intend it to. A full trace of its activity in Chrome's Node Inspector reveals that it does indeed perform as intended.
Having debugged the script via Node Inspector, I then wrote a simple test page to call that script via AJAX. Despite taking care to use proper asynchronous callbacks, the script appears to hold up the server for an inordinate period of time, and returns with an HTTP status code of 0.
Having searched Stack Overflow for similar issues, the threads I surveyed all issue the same message - that this is a CORS problem. BUT ... if this was a CORS problem, NONE of the other AJAX scripts in the same directory would work, and would presumably return the same HTTP status code of 0.
Firing up a new, simpler test script to see if MongoDB connections are somehow interfering with my node.js server, this new script did NOT trigger an HTTP status code of 0, but instead returned as expected, with the HTTP status code of 200. This new test script resides in the same directory as the troublesome script, so it can't be a CORS issue.
Likewise, experimentally calling other scripts in the same directory via AJAX yields the same result - all the other scripts return HTTP 200 as expected.
So, why is this one script returning with an HTTP status of 0, while every other script in the same directory returns with an HTTP status of 200?
At this point, no doubt people will ask me to show the code. However, there's a slight problem. The script in question is 749 lines long, and I suspect that [1] it'll be impossible to pinpoint the error without embedding the entire code file in this question, and [2] numerous individuals will berate me for doing so. The fact that the script runs without errors in Node Inspector also makes this puzzling. I can edit this question and include all of that code if asked, but given what I've stated above, I have no idea where to begin pinpointing the error in that code, so there's no way I can select parts of it that might be problematic, especially in the light of the fact that it runs to completion, without error, in Node Inspector via the node.js command prompt.
Just in case this issue is platform specific, I'm running Node V8.11.3 LTS and MongoDB 4.0 on Windows 7 64-bit.
Related
I'm starting on a project using Node.js, and I'm running into some issues with it's logging. I'm completely new to Node.js, but my understanding is that using console.log([data]) should print out the value of [data] to the server console.
I see this occurring how I expect in several places in this project, but when I try to add additional logging, nothing is prompted out to the console window.
I've noticed that all of the files where logging is working are under a specific folder, while the bulk of the code is under another.
Does anybody know what might be the cause of these not to print out into the console? I've also tried console.error([data]) and console.warning([data]) to see if it might be due to an error but that also didn't work.
Without having your actual code, this is just a guess:
The files where the logging is working are the Javascript files for the server. The "bulk" of the code may be the client code (I guess so because you're saying in the comments of your post that you inserted a working alert, which is a browser thing), so your logs go to the browser not to the server.
I'm not expecting an answer, just thought I'd throw this out there...
I have an ASP.NET site running on IIS 7.5. Relatively often, maybe 10% of requests, one or two users receive errors while loading javascript resources.
One of the users (IE9) recorded the errors in the F12 tools. There are a couple dozen javascript files on our page, and most of them errored out with the following:
SCRIPT1014: Invalid character
xxxxx.js, line 1 character 11
All of the ones that errored give exactly line 1 character 11. Drilling down into the script files in IE through this error message, everything looked fine - the content that IE showed for these files was exactly what it should be.
But these script files, including jQuery, some third party plugins, and some internal scripts, apparently blew up completely when loading. All of our js files are hosted on our servers - no CDNs.
However, a few of the javascript files apparently were more successful, just erroring out with 'jQuery' is undefined or similar, telling me those must have at least started to execute properly.
Compression is enabled and working properly. I considered the possibility that maybe compression was to blame, and IE was attempting to execute gzip-compressed script without first decompressing it. However, when I force gzip bytes down a response, IE errors with line 1 character 1, and these are consistently character 11.
IE9 in "InPrivate" mode works fine - not a single error.
Something that may be related - the browser isn't properly using cached content. When loading the page from my machine (also IE9), the If-Modified-Since and If-None-Match request headers are sent every time on a refresh, which means the response comes back as a 304 every time, and regular navigation always simply uses cache with no requests. On the problem machine, about 1/3 of the time, the browser requests these files again, with no headers, which means they come back with 200's.
I watched Fiddler, and even with that weirdness, all requests and responses are properly formatted and contain good content, so while the caching thing is weird and possibly related, it does not appear to be the direct cause.
Of course I tried to reproduce a couple thousand times on my machine, manually and through Fiddler, and everything was always perfect. And the user can't reproduce on demand. So I can't even confirm whether it's a server or browser issue, or if it's unique to IE or IE9.
Any thoughts on what could cause this specific scenario? The line 1 character 11 thing is what leads me to believe there's some kind of pattern here.
I'm working on a headless browser based on WebKit (using C++/Qt4) with JavaScript support. The main purpose for this is being able to generate a HTML spanshot of websites heavily based on JavaScript (see Backbone.js or any other JavaScript MVC).
I'm aware that there isn't any way for knowing when the page is completely loaded (please see this question) and because of that, after I get the loadFinished signal (docs here) I create a timer and start polling the DOM content (as in checking every X ms the content of the DOM) to see if there were any changes. If there werent I assume that the page was loaded and print the result. Please keep in mind that I already know this is not-near-to-perfect solution, but it's the only one I could think of. If you have any better idea please answer this question
NOTE: The timer is non-blocking, meaning that everything running inside WebKit shouldn't be affected/blocked/paused in any way.
After testing the headless browser with some pages, everything seems to work fine (or at least as expected). But here is where the heisenbug appears. The headless browser should be called from a PHP script, which should wait (blocking call) for some output and then print it.
On my test machine (Apache 2.3.14, PHP 5.4.6) running the PHP script outputs the desired result, aka, the headless browser fetches the website, runs the JavaScript and prints what a user would see; but running the same script in the production server will fetch the website, run some of the JavaScript code and print the result.
The source code of the headless browser and the PHP script I'm using can be found here.
NOTE: The timer (as you can see in the source code of the headless browser) is set to 1s, but setting a bigger amount of time doesn't fix the problem
NOTE 2: Catching all JavaScript errors doesn't show anything, so it's not because of a missing function, wrong args, or any other type of incorrect code.
I'm testing the headless browser with 2 websites.
This one is working on both my test machine and in production server, while this one works only in my test machine.
I'm more propone to think that this is some weird bug in the JavaScript code in the second website rather than in the code of the headless browser, as it generates a perfect HTML snapshot of the first website, but then again, this is a heisenbug so I'm not really sure what is causing all this.
Any ideas/comments will be appreciated. Thank you
Rather than polling for DOM changes, why not watch network requests? This seems like a safer heuristic to use. If there has been no network activity for X ms (and there are no pending requests), then assume page is fully "loaded".
I am developing a cross-domain RPC library for which I want to do some unit-testing using qunit.
In order to do the testing properly I've setup a grunt file that launches a node.js server and phantomjs to load the test rpc.html as described here (using a server task so that different domains can be simulated, localhost and 127.0.0.1). This test opens an iframe with frame.html that mocks the RPC commands which are asserted within rpc.html.
So far all good. The problem I am encountering is that whenever a JS error occurs within frame.html it is not outputted to the console. Only errors that happen in rpc.html are shown. Although outputs of console.log() etc are working in frame.html.
Is there a way I can get all JavaScript errors to be shown that occur in frame.html, including parse errors and such?
Thank you in advance.
PhantomJS supports onError event handlers in its page objects, so that information about JavaScript exceptions can be intercepted and handled as appropriate.
AFAIK, you should possibly also check if loaded web-pages do not have their own window.onerror, because if they return true, the errors will be treated as handled.
in a simple html file opened locally via firefox I need some javascript code to execute a command (maybe "ls") and get it's result in a string I can use in js/jquery to alter the page contents.
I already know this is a generally bad idea, but I have to make this little local html file capable of running several scripts without a server and without cgi.
In the past I've used to install a plugin in TiddlyWiki (www.tiddlywiki.com) to execute external commands (firefox requested authorization for every operation), so javascript can do it, but how to get command result in js after execution?
I don't believe there's any way to do this without a cooperating browser plug-in. The browser plug-in would be told what command to execute via javascript, it would go execute that command and then call you back with a callback when the results were available. This could be very dangerous as giving the browser access to your local system in almost anyway opens you up to lots of types of attacks (which is why browsers don't offer this capability).