I'm using Selenium to crawl an AngularJS site and would like to create a list of all thrown errors (the specific errors I'm actually interested in are these lex errors). AngularJS exposes $exceptionHandler to overwrite exception handling behavior. But would rather stay away from modifying app code as much as possible as these are remote tests.
I'm using Firefox so browser.manage().logs() fails. I suspect this question is closely related to Log console errors using protractor - this SO answer.
I have tried window.onerror
and window.addEventListener('error', () => { ... });
but neither of them catch the thrown error. I wonder if there is something that AngularJS is doing that blocks propagation to the window maybe?
My goal:
window.thrownErrors = [];
[Some global object].throw = (error) => {
console.error(error);
window.thrownErrors.push(error);
}
throw new Error('throw test');
console.log(window.thrownErrors); // => ['throw test']