Phil Phil - 1 year ago 113
Android Question

Increasing timeout to get rid of "The server is taking longer than expected to respond" in a Cordova/PhoneGap app

I am using Cordova/PhoneGap for an iOS and Android app. All the app does is call "window.location.replace" in the onDeviceReady () function to redirect the browser to an external site. From then on, the "app" simply uses Cordova/PhoneGap's inbuilt browser for everything (not InAppBrowser).

One thing I have found is on occasion I receive this popup when the server may be running a little slower than usual:

Connection Error: The server is taking longer than expected to respond.

The popup appears way too early, usually after just a few seconds. As I said, this happens on both iOS and Android.

Is it possible to increase the timeout in the Cordova/PhoneGap browser to something higher (eg. 60 seconds)? If that's not possible, is it possible to prevent this popup from showing up at all?


Answer Source

I managed to solve this myself.

The "Connection Error" popup that appears is not part of the core Cordova/PhoneGap code, but it is actually part of the cordova-plugin-progress plugin. It has a setting that defaults to 10 seconds before displaying that popup:


<preference name="CRIPageLoadPromptInterval" value="5" />

Type: int

Default: 10

If the site hasn't loaded after this interval the user will be provided a choice to continue waiting or to retry loading the site. This is turned on by default. If not wanting the prompt the user set the value to 0.

Setting this value in your config.xml file to a higher number (such as 60 if you want a 1 minute timeout) solves the problem. I have confirmed this by setting the value to a 1 second timeout and seeing the popup appear constantly.

I hope this helps anyone else that may have the same problem in future.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download