Question

I am trying to debug some Javascript locally, but I'm running in to a strange issue. If I open a local file like:

<html>
    <head>
        <script src="file.js"></script>
    </head>
    <body></body>
</html>

with a file.js that is just:

(function() {
    'use strict';
    debugger
})();

it fails to pause on the debugging line. However, if I open that exact same file in Firefox/Firebug, it does pause on that line. Also, if I add debugger lines to files served on my local server (ie. http:// files instead of file:// files) the Chrome debugger pauses as expected.

The problem only manifests (as far as I can tell) in Chrome with local files. However, I've googled a lot and I haven't been able to find any sort of "disable debugger in local files" option for Chrome or anything like that (that I might have accidentally enabled).

Has anyone ever seen this before, and if so were you able to resolve it?

Was it helpful?

Solution

So it turned out that the problem was a flag I had added to Chrome. By default Chrome won't let your local files access other local files, so I had enabled local-file-loading with the command line flag:

--allow-file-access-from-files

That worked great, except it caused a side effect I didn't realize: when you run local files (or at least local files loaded by other local files) Chrome apparently "sandboxes" them. Unfortunately, Chrome also refuses to debug "sandboxed" code, which meant that my debugger was mysteriously failing.

So, for anyone who wants to run local files in Chrome (say to run a web-based testing framework), the trick is to first add the above flag, but then also add this flag:

--allow-sandbox-debugging

so that Chrome will still trigger the debugger when your code includes a debugger line in a local file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top