A quick PhoneGap fix for http / https external browser launch problem

I’ve been using PhoneGap for a while – 0.8.something was the first version I used.  As such, you sometimes take certain things for granted – for instance:

<a href=”http://www.midnightryder.com”>Click Me</a>

Would result in opening the native browser, pointed at MidnightRyder.com.  Easy cheesy, and if you don’t specify a URL handler, it’s assumed to be a local file, and it loads it locally.

Not so with 0.9.3!   I’m assuming it’s a bug, not a feature, but now clicking the link would open MidnightRyder.com IN the application, with no way to get back out of it.  And since 0.9.3 multitasks (quite nicely, I’ll add), hitting home then relaunching the app brings up the now broken application unless the user shuts it down.

After searching through the forums for answers, I finally started digging in and discovered it was a pretty simple problem in PhoneGapDelegate.m, line 551  – 557:

/*

* If a URL is being loaded that’s a file/http/https URL, just load it internally

*/

else if ([url isFileURL])  ||

[[url scheme] isEqualToString:@”http”] ||

[[url scheme] isEqualToString:@”https”])

{

Cool… but I don’t want HTTP requested to be loaded internally.  So, quick and dirty hack if you happen to have the same problem:

/*

* If a URL is being loaded that’s a file/http/https URL, just load it internally

*/

else if ([url isFileURL]) /* ||

[[url scheme] isEqualToString:@”http”] ||

[[url scheme] isEqualToString:@”https”]) */

{

Now file://, gap://, etc. will be handled internally (as will any URL that doesn’t have a protocol in front of it), but http and http are now launched externally.

Unfortunately, I shipped TWO apps that have that bug.  No one has reported them (since the links are fundamental to the apps, but it does tell me how often people are reporting bugs or clicking on the ‘about’ section of the app, then clicking on the stuff that appears are “more apps from Midnight Ryder Technologies” 🙂  Oh well – that gives me an excuse to do a couple other fixes anyways, then release updates.

Word of warning:  I have not tested this in all possible scenarios.  For instance, I have no idea what it might do to JSON requests, for instance, or any other external data requests.  In theory, I don’t think it’s going to affect anything, but at the moment consider this to be a dirty hack, not a true bug fix.

4 thoughts on “A quick PhoneGap fix for http / https external browser launch problem”

  1. Can we get more attention to this issue? It’s kind of a pain, especially for compiled PhoneGap source files.

  2. Pingback: A Webapp By Another Name II – The many pitfalls of using the application cache on mobile platforms | Chris's Excellent Adventure In JavaScript

  3. Pingback: Scott Logic » A Webapp By Another Name II – The many pitfalls of using the application cache on mobile platforms

Leave a Comment