apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 990 forks source link

Cordova onWebViewPageDidLoad delay from remote src #1250

Closed conan1150 closed 2 years ago

conan1150 commented 2 years ago

Bug Report

Problem

Cordova onWebViewPageDidLoad delay from remote src

What is expected to happen?

Screen showup when page loading

What does actually happen?

Screen webview.hidden make blank screen when I hide splash with hide command in js

Information

loading src from remote src sometime onWebViewPageDidLoad not call or delay. so app show splash screen too long

Command or Code

onWebViewPageDidLoad webview.hidden

Environment, Platform, Device

ios 14+

Version information

cordova ios 6.2.1

Checklist

breautek commented 2 years ago

Cordova onWebViewPageDidLoad delay from remote src

Is your entire application hosted remotely, or does your app just depend on sources loading remotely? If the latter, you could try to async loading or ensure that the cordova.js is loaded first. Remembering that JS is single threaded and without the async attribute it will pause when it needs to download a script source. If the connection to the remote source is slow/weak, your app is blocked until it either completes or errors out. The async attribute allows the script source to download in the background and only parse/execute it later when it's available.

If the former, it's not really a supported configuration because it breaks Section 4.7 / 4.7.1 Cordova onWebViewPageDidLoad delay from remote src of the Apple App Store policies. Ability to load in your app should be reserved for development use or at least for apps that do not require the use of native APIs.

Edit: fixed Apple guideline link

conan1150 commented 2 years ago

my application is hosted remotely. loading.js by inject later.

const dynamicScripts = [
  'assets/js/cordova-ios/cordova.js?V0005'
];
for (let i = 0; i < dynamicScripts.length; i++) {
  const node = document.createElement('script');
  node.src = dynamicScripts[i];
  node.type = 'text/javascript';
  node.async = false;
  node.charset = 'utf-8';
  document.getElementsByTagName('head')[0].appendChild(node);
}

document.addEventListener("deviceready", this.onDeviceReady, false);

then I can force hide splashscreen by navigator.splashscreen.hide();

but I see empty screen because webview was hidden at first.

I have interim solution by webview.hidden = false when ViewController is initiate.

thank you for your response.

breautek commented 2 years ago

Glad you've found a solution, albeit apparently temporarily.

Because the application code is not bundled with the app binary, I don't think there is anything Cordova can do. If the issue persists with applications bundled locally, then feel free to create a new issue. As I alluded to previously, the ability to load remote apps into the cordova container is provided for development purposes and may have legal consequences if used in a production environment. For that reason I'm closing this issue.

conan1150 commented 2 years ago

thank you for your response.