Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0A3BFE4B9 for ; Wed, 9 Jan 2013 03:26:15 +0000 (UTC) Received: (qmail 77220 invoked by uid 500); 9 Jan 2013 03:26:14 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 77194 invoked by uid 500); 9 Jan 2013 03:26:14 -0000 Mailing-List: contact dev-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list dev@cordova.apache.org Received: (qmail 77177 invoked by uid 500); 9 Jan 2013 03:26:14 -0000 Delivered-To: apmail-incubator-callback-dev@incubator.apache.org Received: (qmail 77166 invoked by uid 99); 9 Jan 2013 03:26:14 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Jan 2013 03:26:14 +0000 Date: Wed, 9 Jan 2013 03:26:14 +0000 (UTC) From: "Jesse MacFadyen (JIRA)" To: callback-dev@incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CB-2166) The deviceReady event may not be received because of asynchronous JavaScript loading MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-2166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13547591#comment-13547591 ] Jesse MacFadyen commented on CB-2166: ------------------------------------- This is NOT possible, as calls to document.addEventListener("deviceready") will simply disappear. Without having cordova code loaded before user code, there is no way to hijack these addListener calls. I would like to see an example posted that demonstrates the issue, even if it is intermittent, because the series of events as described do not make sense. For this to happen as described, you would need to be using a script loader, or the new async script methods. http://caniuse.com/#search=async > The deviceReady event may not be received because of asynchronous JavaScript loading > ------------------------------------------------------------------------------------ > > Key: CB-2166 > URL: https://issues.apache.org/jira/browse/CB-2166 > Project: Apache Cordova > Issue Type: Bug > Components: CordovaJS, Docs > Affects Versions: 2.2.0 > Environment: Cordova 2.2, Android 2.3.4 > Reporter: Thomas Dinger > Assignee: Filip Maj > > HTML page includes Cordova script first, then my Cordova-dependent script. My script registers a listener for the deviceReady event. Occasionally the listener is not called. I've determined the problem is due to the timing of the asynchronous loading of the script files. Because of the way cordova "hijacks" the document.addEventListener function, my event handler may be registered with the document object instead of Cordova, depending on whether the Cordova script is executed before my script. > Would it be possible for Cordova to look at the document object and determine whether there are existing event listeners for the deviceReady event? And if there are, to "hijack" these event handlers so they are called correctly when Cordova sends the deviceReady event? > I have changed my code to wait for the DOMContentLoaded event before registering my deviceReady event handler. This has been successful for me, and might be an approach that could be used in the Cordova documentation. -- 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