Bug 147753

Summary: iOS WKWebView window.onerror Callback Doesn't Get a Useful msg
Product: WebKit Reporter: Kelly Roach <kroach>
Component: WebCore JavaScriptAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: craig, ewering
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: iPhone / iPad   
OS: iOS 8.2   
Attachments:
Description Flags
JavaScript alert inside WKWebView displaying window.onerror args none

Description Kelly Roach 2015-08-06 16:06:56 PDT
Created attachment 258414 [details]
JavaScript alert inside WKWebView displaying window.onerror args

Unhandled JavaScript exceptions occurring in JavaScript code
inside a iOS WKWebView doesn't generate useful information to window.onerror
beyond msg = "Script error".  It's a pity because older UIWebView does
get better information.
    Unhandled JavaScript exceptions call user's window.onerror function
if there is a function installed.  For example, include
      function errorHandler(msg, url, line, col, errorObj) {
        try {
          alert(("msg: " + msg)
                + ("\nurl: " + url)
                + ("\nline: " + line)
                + ("\ncol: " + col)
                + ("\nerrorObj: " + errorObj));
        } catch (e) {
        }
        return true;
      }
      window.onerror = errorHandler;
along with other JavaScript code inside a <script> tag in an HTML
file.
    In case of iOS UIWebView, we at least get a msg string
with some variety indicative of the type of unhanded JavaScript
exception which occurred.  Examples:
    "INVALID_NODE_TYPE_ERR: DOM Range Exception 2:  The container ..."
    "HierarchyRequestError: DOM Exception 3:  A Node was inserted ..."
    "ReferenceError: Can't find variable: garbage"
in addition to some line and col which generally are both non-zero
integers.
    However, in case of iOS WKWebView, we find we are ALWAYS
getting only the following values passed to our errorHandler:
    msg: Script error.
    url:                   [blank]
    line: 0
    col: 0
    errorObj: undefined
This is still the case as of iOS 9 beta 4 .  We'd prefer to get
at least as much information unhandled JavaScript exceptions
when using WKWebView as we do get when using UIWebView .
    One of my coworkers spoke to an Apple representative at the
most recent WWDC about this matter.  We're informed that the
Apple representative thought it was a bug which should be reported.
Comment 1 Alexander Ewering 2016-11-29 04:34:09 PST
Still no word on this? I use an IDE which depends on onerror, it's useless this way!