You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2020/12/26 13:59:16 UTC

[GitHub] [cordova-ios] breautek commented on issue #723: Pass Launch Parameters to Cordova App

breautek commented on issue #723:
URL: https://github.com/apache/cordova-ios/issues/723#issuecomment-751358167


   So if I understand correctly, the race condition is `deviceready` may fire and as a result, may attempt to call `handleOpenURL`, before the application has a chance to set `handleOpenURL`.
   
   I don't think `setTimeout` is the proper solution here.
   
   `NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof h` the javascript being invoked from native adds a listener to `deviceready`. This means it will either wait until the `deviceready` event is fired, or if it's already fired then `deviceready` will be fired immediately. Adding a `setTimeout` to that logic will force execution to be delayed until the next JS callstack, but I don't think that will guarantee to solve the race condition.
   
   The document parses the script tags synchronously by default. As long as you don't have the `async` or `defer` attributes set and you're not using Javascript Modules (which are async by default). So for example if you had the following html:
   
   ```html
   <script src="cordova.js"></script>
   <script src="myapp.js"></script>
   ```
   
   This should work as expected, as long as `myapp.js` sets `handleOpenURL` synchronously. The webview will parse and execute `cordova.js` then `myapp.js`. It should never fire `deviceready` before `myapp.js` is finish executing because it parses scripts synchronously.
   
   If you want to have reassurance, you could reverse the order and execute `myapp.js` before `cordova.js`, like you suggested but you'd have to keep in mind that the cordova API hasn't been loaded yet at all, thus you can't use `document.addEventListener('deviceready', ...);`


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org