TruckMovers / cordova-plugin-remote-injection

DEPRECATED: Cordova plugin to allow a remote site to interact with cordova's javascript APIs when loaded within a cordova app.
Apache License 2.0
91 stars 95 forks source link

Suppressing the "Connection Error - Unable to contact the site." message #17

Closed Jammmmm closed 7 years ago

Jammmmm commented 7 years ago

On occasion I get a very quick error that says "Connection Error" "Unable to contact the site.". By quick, I mean it flashes for about a second and then disappears and continues loading, like there's nothing wrong. I'm puzzled why it shows up in the first place.

connectionerror

Is there a way of permanently disabling this message? I have CRIPageLoadPromptInterval set to a high value, however that seems to only prolong the "Wait/Retry" message that appears.

A quick search reveals the offending file to be "CDVRemoteInjectionWebViewBaseDelegate.m" in the "ios" directory, so it's presumably an iOS only issue?

bradleyjames commented 7 years ago

That's odd. I haven't seen this personally. To turn off the retry prompt you can set the CRIPageLoadPromptInterval to 0 but I'm not sure that will address your issue. This message should only display if the request to load the page failed. Have you tried debugging what is happening with the connection? Can your app connect to your server?

Jammmmm commented 7 years ago

I believe this really only happens when I'm not really in the app... I'll explain.

When the device is ready, my app calls "window.location.href = 'http://www.example.com/'. From this point on, Cordova itself is never touched, other than some calls to determine the platform being used (cordova-plugin-device) and some code to handle push notifications (phonegap-plugin-push). The app simply acts as a normal web browser. I'm not really sure why I'd get the "Unable to contact the site." message at this point, but it definitely does happen, even if it is just a flash. It doesn't happen all the time, but I've had several reports from users seeing it.

The connection is fine when this happens since the following page loads normally.

The app itself connects without any problems to the server.

This is why I'd love an option to disable it altogether. It does not seem to be reporting correctly, at least not in my use case.

bradleyjames commented 7 years ago

Can you reproduce the issue inside Xcode? If so adding a breakpoint in that method might help debug what resource it's saying has failed to load. Adding an option would certainly work but I'm concerned there's something else going on here that this would just be masking.

By chance are you using Crosswalk? If not what version of the iOS webview are you using: UIWebView or the WKWebView? The life cycle events appear to behave differently in Crosswalk (#15).

Can you provide a sample project that reproduces the issue?

Jammmmm commented 7 years ago

I can't reproduce it as I've personally only ever seen it happen once.

I'm not using Crosswalk on the iOS version of the app, but I do use cordova-plugin-wkwebview-engine to utilize WKWebView.

Unfortunately I can't provide a sample project. The project that it's happening in is proprietary. I could come up with a similar project for the purpose of attempting to reproduce the issue, but it may not ever happen since I have no idea how to consistently reproduce the issue. I'll see what I can come up with later.

dmitriy-baltak commented 7 years ago

I have exactly the same problem, but reproducible on every first opening of an app. Is it possible to disable this message at all because it's simply misleading and doesn't reflect reality?

bradleyjames commented 7 years ago

Can you provide an example that demonstrates the issue? If not see my previous comment that started with "Can you reproduce the issue inside Xcode?" in order to debug the issue and help get to the bottom of this.

Jammmmm commented 7 years ago

@Alivejke I'm glad it's not just me. I no longer see it, and have tried to reproduce the project several times since my initial post, but I'm not able to. My customer's don't seem very receptive to helping me debug the problem.

I hope you're able to provide a reproduction to @bradleyjames

davidyarham commented 7 years ago

Easy to reproduce, set these in your config :

<content src="https://www.asitethatdoesnotexist.com" /> <allow-navigation href="https://www.asitethatdoesnotexist.com" /> <preference name="ErrorUrl" value="error.html"/>

error.html is located in the www folder, and does redirect correctly but I get the prompt for a split second.

bradleyjames commented 7 years ago

@davidyarham, thanks. The use of an ErrorUrl is definitely not a use case I considered. In light of that I'll provide a way to turn off the dialog.

davidyarham commented 7 years ago

Perfect thanks, I am definitely chasing, but do you have a timeframe for it?

bradleyjames commented 7 years ago

I don't. It shouldn't take me long to do but finding the time is the hardest part. It's the top priority though for the project. If anyone wants to take a crack at it a PR would be fantastic.

bradleyjames commented 7 years ago

I've released v0.5.0 of the plugin to address the iOS issue. Take a look at the CRIShowConnectionErrorDialog preference in the README.

I don't think this affected Android so there's nothing new on that platform.

Let me know if you run into issues.