cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Bowser (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (CB-2303) Add event for script errors
Date Wed, 18 Sep 2013 23:18:52 GMT

     [ https://issues.apache.org/jira/browse/CB-2303?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Joe Bowser resolved CB-2303.
----------------------------

    Resolution: Won't Fix

This was abandoned, but I believe this is more trouble than it is worth at this point. I'm
going to close this for now.
                
> Add event for script errors
> ---------------------------
>
>                 Key: CB-2303
>                 URL: https://issues.apache.org/jira/browse/CB-2303
>             Project: Apache Cordova
>          Issue Type: New Feature
>          Components: Android
>            Reporter: Jonathan Prince
>            Assignee: Joe Bowser
>
> Android webview does not support window.onerror for catching unexpected javascript errors.
This makes cross platform error logging and analysis very difficult (especially on released
software).
> A new event could easily be added to enable developers to track javascript errors.
> e.g. in CordovaChromeClient.java change the onConsoleMessage override from 
> {code:title=CordovaChromeClient.java - Current method|borderStyle=solid}
>     @TargetApi(8)
>     @Override
>     public boolean onConsoleMessage(ConsoleMessage consoleMessage)
>     {
>         if (consoleMessage.message() != null)
>             LOG.d(TAG, consoleMessage.message());
>         return super.onConsoleMessage(consoleMessage);
>     }
> {code}
> All this currently does is re-log messages. Changing the method to the below also triggers
a scripterror event for errors (this is just proof of concept code but works correctly). Developers
can easily map this event to call a standard error handler.
> {code:title=CordovaChromeClient.java - Suggested method|borderStyle=solid}
>     @TargetApi(8)
>     @Override
>     public boolean onConsoleMessage(ConsoleMessage consoleMessage)
>     {
>         if (consoleMessage.message() != null)
>         {
>             if (consoleMessage.messageLevel().name() == "ERROR")
>             {
>             	String errorUrl = "javascript:cordova.fireDocumentEvent('scripterror', {msg:
\"" + consoleMessage.message() + "\", line: " + consoleMessage.lineNumber() + ", url: \""
+ consoleMessage.sourceId() + "\"});";
>                 this.appView.loadUrl(errorUrl);
>             	LOG.e(TAG, consoleMessage.message() + " line " + consoleMessage.lineNumber()
+ " in " + consoleMessage.sourceId());
>             }
>             else
>             {
>                 LOG.d(TAG, consoleMessage.message());
>             }
>         }
>         return super.onConsoleMessage(consoleMessage);
>     }
> {code}
> The only quirk I have found with this approach is that javascript calls to console.error
also trigger the scripterror event. This actually seems logical but developers should be aware
of it.
> Otherwise; unexpected script errors and thrown errors trigger the event and handled errors
(in try...catch blocks) don't.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message