There is one problem when using window.onerror() - you are not able to get the stack trace, so the errors not much meaningful. Recently CEF implemented CefV8StackTrace but it doesn't help, it doesn't show real stack trace when inside onerror event, it is a similar limit of this workaround code that works in Internet Explorer and Firefox, but not in Chrome:
- Code: Select all
window.onerror = function (errorMessage, url, lineNumber)
{
try {
throw new Error("get current stack trace");
} catch (e) {
stackTrace = e.trace;
}
};
So when in window.onerror I call my C++ function to handle the error, then CefV8StackTrace::GetCurrent() does not return stack trace of the error that happened, it seems the context is being changed in onerror event.
I was thinking about another solution of catching javascript errors, to implement OnConsoleMessage() display handler, and check whether the "message" param contains "error" or "failed" string inside, it's not a perfect solution, but it should work with my own code that I have control over.
These are example errors that show in Developer tools:
- Code: Select all
Failed to load resource ...
ReferenceError: asd is not defined
SyntaxError: Unexpected token }
Unfortunately it does not work, CefV8StackTrace::GetCurrent() returns an empty stack trace when called from OnConsoleMessage() handler.