function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bob_buzzardbob_buzzard 

Mobile SDK 1.5 and InAppBrowser

Has anybody had any luck using the InAppBrowser?  According to the cordova docs, this is available in 2.3.0 and it appears in my config.xml.  The docs say that if I execute JavaScript of the form:

 

window.open('http://www.google.co.uk', '_blank', 'location=yes')

 then it should open the page in the InAppBrowser, leaving my existing app alone.  I've tried every combination I can think of and tinkered with the whitelisting, but all to no avail - every page opens in the cordova webview.

 

I'm trying to get this working so that I can open a PDF file via a link from my app and have a way to close it down and return to my app.  At the moment, when I open the PDF, I have no way to get back to my app.  I can workaround this to a degree using an iframe or object tag, but the interaction with the file for scrolling etc is very slow.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Kevin HawkinsKevin Hawkins

Stupid question: are you serving the cordova.js file from your VF page?  For Cordova apps in the cloud, you must serve the JS artifacts from your VF page; the ones used in the container are not sufficient.

 

I am able to successfully execute your VF scenario almost exactly (my anchor was something like <a href="javascript&colon;loadInAppBrowser('http://www.google.com');">Test InAppBrowser</a>, where loadInAppBrowser() was just a helper function I defined in my page to do your window.open, but otherwise exactly the same at the end code).

All Answers

Kevin HawkinsKevin Hawkins

Does www.google.co.uk fall into your whitelist, and if so, what's the value of OpenAllWhitelistURLsInWebView in your config.xml file.  If the former is true, and the latter is true, these links will open in your main webview, even with the window.open call you describe.

bob_buzzardbob_buzzard
Thanks for the reply Kevin. I'm pretty sure I've tried that combo, but I'll give it another go to make sure.
bob_buzzardbob_buzzard

My setup from config.xml:

 

   <preference name="OpenAllWhitelistURLsInWebView" value="false" />
...
    <access origin="www.google.co.uk"/>

 

and the link opens in the web view with the following in the log file:

 

2013-02-21 17:53:09.162 KAB Collateral[20570:707] DEBUG|0|SFHybridViewController|webView:shouldStartLoadWithRequest: Loading URL 'http://www.google.co.uk/#sclient=tablet-gws&hl=en&site=&source=hp&q=%3D&oq=%3D&gs_l=tablet-gws.3...3251.3251.0.3557.1.1.0.0.0.0.0.0..0.0.les%3B..0.0...1ac.1.4.tablet-gws.8YQI4nlY79s&pbx=1&bav=on.2,or.r_gc.r_pw.&bvm=bv.42661473,d.Yms&fp=76bfd479edbc75b1&biw=1024&bih=748'

 

If I remove www.google.co.uk from my whitelist (which according to the docs should cause it to be opened in the inappbrowser) I get an error that the link was denied due to the whitelist.

 

My app is served from Visualforce pages rather than content in the www folder of the hybrid app, if that makes any difference (I haven't found anything indicating that this is a problem).

 

 

Kevin HawkinsKevin Hawkins

So here's what I've come to find out:

 

  1. OpenAllWhitelistURLsInWebView does nothing in Cordova 2.3 (Mobile SDK 1.5), and has been removed entirely for 2.4 and beyond.  This property is now superceded by the different window.open() parameters.
  2. Setting up a basic test with InAppBrowser in a Mobile SDK 1.5 hybrid template app, using your JS configuration (window.open('http://www.google.co.uk', '_blank', 'location=yes')), I do not encounter any scenarios where InAppBrowser does *not* open.  However:
  3. Whitelisting functionality is broken in 1.5.  For InAppBrowser, whitelisting is not supposed to apply, since any URLs opened within InAppBrowser are outside of the security sandbox of the main web view.  I've isolated the problem, and will be pushing a patch shortly.

But back to your original issue, though I can reproduce whitelisting issues, I cannot reproduce a scenario where InAppBrowser does not open at all (in favor of the main web view).

Kevin HawkinsKevin Hawkins

FYI, a patch has been posted for the Mobile SDK, if you want to see if that helps at all with your problem.  It fixes the whitelisting issue, anyway.

bob_buzzardbob_buzzard

Thanks for looking into this.  I've isolated what is happening and it appears to be due to the fact that I am using a Visualforce-based application and my pages are accessed from Visualforce and I start the app using SFHybridApp.RemoteAppStartData.

 

If my visualforce page is simply:

 

<apex:page showheader="false" sidebar="false" standardstylesheets="false">
  <a href="#" onclick="window.open('http://www.google.co.uk', '_blank', 'location=yes');" rel="external">Google (External)</a><br/><br/>
</apex:page>

 the page opens in the webview.

 

If I change my app to use SFHybridApp.LocalAppStartData and put the anchor tag from above into index.html, it opens correctly.  I've been digging around to see if I can find anything to indcate that local/versus remote apps would behave differently, but I haven't come up with anything.  

 

Do you know if this is expected behaviour?  I'd prefer not to have to change to a local app as I'll be updating the information presented frequently and I'd like to avoid having to push out repeated updates.

bob_buzzardbob_buzzard

Digging a little more, I can workaround this by having the index.html in the local app open my visualforce page in the inappbrowser, and then I at least have the navigation buttons when I open PDFs etc.  I'd still be interested to know if there's any way that I can use the InAppBrowser from the remote app - the debug logs and whitelisting indicates that the app still has control over the navigation.

Kevin HawkinsKevin Hawkins

Stupid question: are you serving the cordova.js file from your VF page?  For Cordova apps in the cloud, you must serve the JS artifacts from your VF page; the ones used in the container are not sufficient.

 

I am able to successfully execute your VF scenario almost exactly (my anchor was something like <a href="javascript&colon;loadInAppBrowser('http://www.google.com');">Test InAppBrowser</a>, where loadInAppBrowser() was just a helper function I defined in my page to do your window.open, but otherwise exactly the same at the end code).

This was selected as the best answer
bob_buzzardbob_buzzard

That's the perfect question, as I was not serving cordova.js in my visualforce page!  

 

I've just added that and its working a treat.

 

Thanks for all your help!

Kevin HawkinsKevin Hawkins

Glad it turned out to be a simple fix!  Thanks in turn for unearthing some bugs that we missed. :)

Michael-FitzgeraldMichael-Fitzgerald

Thanks Kevin and Bob for the troubleshooting and resolution. This was the aspirin I was looking for to solve my headache.

 

Thanks