JS Error Capture in Chrome

I take away the js errors in the application using window.onerror, but the fact is that in Chrome, if the dev tools are not open, then the parameter urlpassed to the handler onerroris always equal to the open URL.

While the dev tools are open, it urlpoints to the exact file .jsthat caused the js error.

How do you deal with this? Are there any workarounds?

And to be more clear - here are 2 results:

  • Uncaught ReferenceError: a is not defined index:122 - it was received after receiving the page
  • Uncaught ReferenceError: a is not defined List.js:122- this was obtained after getting the same page with dev tools open. This is the expected result - I sent a call a();to a file List.jsfor testing.

UPD : this is done for functional testing (using selenium webdriver). I want to fix js errors for further research.

+5
source share
2 answers

Deliver the following architecture:

window.addEventListener("error", handleException, false);

function handleException(I_sMsg) {

    if (I_sMsg.stack) {
            sMsg = I_sMsg.stack.replaceAll(getBaseURL(), "");
        alert(sMsg);
    } else if (I_sMsg.message) {
        alert(I_sMsg.message);
    }   

    return cancelEvent(I_sMsg);
} 

Now anyone throw new Error("description");will go through the first part of the if statement and have a good stack so you can parse the urls.

It also works for unexpected exceptions, resulting in the following message (in this case, after calling a non-existent function bibi())

screenshot of an unexpected exception

After further study, my structure uses some kind of home task management (as shown in the stack in fact), where each action belongs to the task.

()

    try {
        oTask.func.apply(oTask.obj, oTask.prms);
    } catch(ex) {
        handleException(ex);
        return false;
    }

, , catch try. , . .

, , , , api.js , .

+1

, , .

Chrome chrome://inspect/ URL- (. chrome://chrome-urls/ ). , , , , . URL- Chrome 28.

chrome://inspect/ , , DevTools.

, , , inspect , DevTools , window.onerror, .

- :

document.getElementsByClassName('row')[n].getElementsByTagName('a')[0].click()
+1

All Articles