Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap 3 contains an alert box in which "OK" crashes browser

I can't come up with a good explanation for this, but when I include

<script type="text/javascript" src="phonegap.js"></script> 

In my Phonegap app, which I have not modified, 2 pops will appear on screen.

//The first popup gap:["PluginManager","startup","PluginManager224542697"]  //the second gap:["App","show","App224542698"] 

I have to cancel both popups and would really love to understand the reasoning.

The two lines in question are on line 21117 and 21118 of phonegap.js

 // Tell the native code that a page change has occurred.  require('cordova/exec')(null, null, 'PluginManager', 'startup', []);  require('cordova/channel').onNativeReady.fire(); 

This of course does not break when its in the app, but it does mean that development is next to impossible.

like image 889
Jamie Hutber Avatar asked Sep 04 '13 20:09

Jamie Hutber


1 Answers

For me the issue was occurring because phonegap.js was falling back to PROMPT based mode when running outside of phonegap. I believe this mode is intended for phonegap below Android 3.2, where all communication is via alert prompts (which is what you're seeing).

I fixed the problem by setting the following variable before loading phonegap.js:

window._cordovaNative = true;

This tricks phonegap into thinking you're running above phonegap 3.2 hence never enters Prompt mode.

Of course, if you're targeting devices below 3.2 then doing this will probably break all communication with Phonegap on those devices...

like image 147
antscode Avatar answered Oct 02 '22 11:10

antscode