Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-5037

Cordova fails to fire deviceready on page reload

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.2.0
    • cordova-ios
    • None
    • iOS 5.
      Device or Network plugins (any plugin that adds itself as a dependency to the deviceready event).

    Description

      Reproduction Steps:

      1. Create a new cordova project for iOS
      2. Add the Device and Network plugins
      3. Add a logging plugin of some kind
      4. Add client code that calls the logging plugin before issuing a window.location.reload(). In our situation we have lots of logging happening just before we do a reload.

      Expected Results:
      The application reloads, successfully invoking the deviceready event.

      Actual Results:
      The application reloads but is stopped waiting for deviceready.

      Cause:
      Race condition on request ID reset.

      Let the first instance of cordova be instanceA and the second instance of cordova be instanceB.

      1. instanceA issues commands that are queued to be handled by the native bridge.
      2. instanceA reloads the page.
      3. The native bridge handles webViewDidStartLoad and resets the largest request ID to 0.
      4. The native bridge continues to process the large queue from instanceA incrementing the largest request ID to X (perhaps the XHR request has come in after the webViewDidStartLoad is handled?)
      5. instanceB starts up,
      6. The Device plugin for instanceB tries to getDeviceInfo,
      7. The native bridge sees the instanceB request with ID 0 and ignores it because it is less than request ID X.
      8. The Device plugin never gets a callback and therefore prevents the deviceready event from firing.

      Possible Solutions:

      1. Cordova should make an initial XHR request to reset the request ID on the native bridge. Perhaps "gap_init" instead of "gap_exec".

      Attachments

        Activity

          People

            agrieve Andrew Grieve
            Lowkay Luke Terry
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: