Interface to handle JavaScript errors

Think CEF could benefit from a new feature or capability? Discuss CEF feature requests here.

Interface to handle JavaScript errors

Postby mikeyk730 » Fri May 07, 2010 1:56 pm

Is there a way to get at JavaScript page errors? If I load the following html in my application, I would like to log an error about the undefined function.

Code: Select all
<html>
<head>
  <script type="text/javascript">
    undefined_funtion();
  </script>
</head>
</html>


Would an interface to accomplish this fit into CEF? Should I be looking at the V8 code instead? Any high level direction would be appreciated. Thanks!
mikeyk730
Newbie
 
Posts: 4
Joined: Fri Apr 23, 2010 12:45 pm

Re: Interface to handle JavaScript errors

Postby magreenblatt » Thu May 20, 2010 9:07 am

Probably the most useful solution is integrating the WebKit Inspector into CEF. See this post for further information:
viewtopic.php?f=10&t=69&start=10#p284

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Interface to handle JavaScript errors

Postby lodle » Thu Jun 17, 2010 2:39 am

lodle
Techie
 
Posts: 32
Joined: Tue Jun 01, 2010 4:36 am

Re: Interface to handle JavaScript errors

Postby myrtlee » Sun May 08, 2011 12:46 am

How do you program Javascript running on program load? We have to program an example of Javascript running on program load. What is program load? I cant find any tutorials or explanations any where. If someone could please tell me and show me some code for this I would appreciate it.
myrtlee
Newbie
 
Posts: 1
Joined: Sat May 07, 2011 4:48 am

Re: Interface to handle JavaScript errors

Postby Czarek » Sat Jul 21, 2012 6:50 am

Starting with Chrome 10 (or something) you can use "window.onerror" event to catch javascript errors.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Interface to handle JavaScript errors

Postby Czarek » Sun Sep 23, 2012 8:05 am

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.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am


Return to Feature Request Forum

Who is online

Users browsing this forum: No registered users and 12 guests