breautek edited a comment 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. However, `myapp.js` should ensure it
sets `handleOpenURL` in a synchronously way. Ie don't wait to set it in any
callbacks.
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]