cordova-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lorin Beer (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CB-2303) Add event for script errors
Date Thu, 11 Apr 2013 04:29:15 GMT

    [ https://issues.apache.org/jira/browse/CB-2303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13628656#comment-13628656
] 

Lorin Beer edited comment on CB-2303 at 4/11/13 4:29 AM:
---------------------------------------------------------

What's are support horizon for 2.3? Last I heard, about 60% of devices in the wild were running
ginger bread. My humble inquiry would be that if the majority of devices are running the os
version that this issue would target, does that not lend weight to it's addition?

--edit--
60% figure a little out of date (Sept 2012), latest suggests ~40% of devices are running ginger
bread http://arstechnica.com/gadgets/2013/04/jelly-bean-reaches-1-in-4-android-devices-tablets-lag-at-10-percent/
                
      was (Author: lorin.beer):
    What's are support horizon for 2.3? Last I heard, about 60% of devices in the wild were
running ginger bread. My humble inquiry would be that if the majority of devices are running
the os version that this issue would target, does that not lend weight to it's addition?
                  
> 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