Giter Site home page Giter Site logo

apache / cordova-plugin-inappbrowser Goto Github PK

View Code? Open in Web Editor NEW
1.1K 95.0 2.1K 1.95 MB

Apache Cordova InAppBrowser Plugin

Home Page: https://cordova.apache.org/

License: Apache License 2.0

Java 36.69% JavaScript 25.85% Objective-C 33.99% CSS 0.42% HTML 3.05%
cordova library objective-c java nodejs javascript mobile android hacktoberfest ios

cordova-plugin-inappbrowser's Introduction

title description
Inappbrowser
Open an in-app browser window.

cordova-plugin-inappbrowser

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

You can show helpful articles, videos, and web resources inside of your app. Users can view web pages without leaving your app.

To get a few ideas, check out the sample at the bottom of this page or go straight to the reference content.

This plugin provides a web browser view that displays when calling cordova.InAppBrowser.open().

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');

window.open

The cordova.InAppBrowser.open() function is defined to be a drop-in replacement for the window.open() function. Existing window.open() calls can use the InAppBrowser window, by replacing window.open:

window.open = cordova.InAppBrowser.open;

If you change the browsers window.open function this way, it can have unintended side effects (especially if this plugin is included only as a dependency of another plugin).

The InAppBrowser window behaves like a standard web browser, and can't access Cordova APIs. For this reason, the InAppBrowser is recommended if you need to load third-party (untrusted) content, instead of loading that into the main Cordova webview. The InAppBrowser is not subject to the whitelist, nor is opening links in the system browser.

The InAppBrowser provides by default its own GUI controls for the user (back, forward, done).

Installation

cordova plugin add cordova-plugin-inappbrowser

If you want all page loads in your app to go through the InAppBrowser, you can simply hook window.open during initialization. For example:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
}

Preferences

config.xml

  • InAppBrowserStatusBarStyle [iOS only]: (string, options 'lightcontent', 'darkcontent' or 'default'. Defaults to 'default') set text color style for iOS. 'lightcontent' is intended for use on dark backgrounds. 'darkcontent' is only available since iOS 13 and intended for use on light backgrounds.
<preference name="InAppBrowserStatusBarStyle" value="lightcontent" />

cordova.InAppBrowser.open

Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.

var ref = cordova.InAppBrowser.open(url, target, options);
  • ref: Reference to the InAppBrowser window when the target is set to '_blank'. (InAppBrowser)

  • url: The URL to load (String). Call encodeURI() on this if the URL contains Unicode characters.

  • target: The target in which to load the URL, an optional parameter that defaults to _self. (String)

    • _self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser.
    • _blank: Opens in the InAppBrowser.
    • _system: Opens in the system's web browser.
  • options: Options for the InAppBrowser. Optional, defaulting to: location=yes. (String)

    The options string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive.

    All platforms support:

    • location: Set to yes or no to turn the InAppBrowser's location bar on or off.

    Android supports these additional options:

    • hidden: set to yes to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to no (default) to have the browser open and load normally.
    • beforeload: set to enable the beforeload event to modify which pages are actually loaded in the browser. Accepted values are get to intercept only GET requests, post to intercept on POST requests or yes to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set beforeload=post it will raise an error).
    • clearcache: set to yes to have the browser's cookie cache cleared before the new window is opened
    • clearsessioncache: set to yes to have the session cookie cache cleared before the new window is opened
    • closebuttoncaption: set to a string to use as the close button's caption instead of a X. Note that you need to localize this value yourself.
    • closebuttoncolor: set to a valid hex color string, for example: #00ff00, and it will change the close button color from default, regardless of being a text or default X. Only has effect if user has location set to yes.
    • footer: set to yes to show a close button in the footer similar to the iOS Done button. The close button will appear the same as for the header hence use closebuttoncaption and closebuttoncolor to set its properties.
    • footercolor: set to a valid hex color string, for example #00ff00 or #CC00ff00 (#aarrggbb) , and it will change the footer color from default. Only has effect if user has footer set to yes.
    • hardwareback: set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. If there is no previous page, the InAppBrowser will close. The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser.
    • hidenavigationbuttons: set to yes to hide the navigation buttons on the location toolbar, only has effect if user has location set to yes. The default value is no.
    • hideurlbar: set to yes to hide the url bar on the location toolbar, only has effect if user has location set to yes. The default value is no.
    • navigationbuttoncolor: set to a valid hex color string, for example: #00ff00, and it will change the color of both navigation buttons from default. Only has effect if user has location set to yes and not hidenavigationbuttons set to yes.
    • toolbarcolor: set to a valid hex color string, for example: #00ff00, and it will change the color the toolbar from default. Only has effect if user has location set to yes.
    • lefttoright: Set to yes to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is no.
    • zoom: set to yes to show Android browser's zoom controls, set to no to hide them. Default value is yes.
    • mediaPlaybackRequiresUserAction: Set to yes to prevent HTML5 audio or video from autoplaying (defaults to no).
    • shouldPauseOnSuspend: Set to yes to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in CB-11013).
    • useWideViewPort: Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is no, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is yes and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to yes).
    • fullscreen: Sets whether the InappBrowser WebView is displayed fullscreen or not. In fullscreen mode, the status bar is hidden. Default value is yes.

    iOS supports these additional options:

    • hidden: set to yes to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to no (default) to have the browser open and load normally.
    • beforeload: set to enable the beforeload event to modify which pages are actually loaded in the browser. Accepted values are get to intercept only GET requests, post to intercept on POST requests or yes to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set beforeload=post it will raise an error).
    • clearcache: set to yes to have the browser's cookie cache cleared before the new window is opened
    • clearsessioncache: set to yes to have the session cookie cache cleared before the new window is opened. For WKWebView, requires iOS 11+ on target device.
    • cleardata: set to yes to have the browser's entire local storage cleared (cookies, HTML5 local storage, IndexedDB, etc.) before the new window is opened
    • closebuttoncolor: set as a valid hex color string, for example: #00ff00, to change from the default Done button's color. Only applicable if toolbar is not disabled.
    • closebuttoncaption: set to a string to use as the Done button's caption. Note that you need to localize this value yourself.
    • disallowoverscroll: Set to yes or no (default is no). Turns on/off the the bounce of the WKWebView's UIScrollView.
    • hidenavigationbuttons: set to yes or no to turn the toolbar navigation buttons on or off (defaults to no). Only applicable if toolbar is not disabled.
    • navigationbuttoncolor: set as a valid hex color string, for example: #00ff00, to change from the default color. Only applicable if navigation buttons are visible.
    • toolbar: set to yes or no to turn the toolbar on or off for the InAppBrowser (defaults to yes)
    • toolbarcolor: set as a valid hex color string, for example: #00ff00, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
    • toolbartranslucent: set to yes or no to make the toolbar translucent(semi-transparent) (defaults to yes). Only applicable if toolbar is not disabled.
    • lefttoright: Set to yes to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left.
    • enableViewportScale: Set to yes or no to prevent viewport scaling through a meta tag (defaults to no).
    • mediaPlaybackRequiresUserAction: Set to yes to prevent HTML5 audio or video from autoplaying (defaults to no).
    • allowInlineMediaPlayback: Set to yes or no to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's video element must also include the webkit-playsinline attribute (defaults to no).
    • presentationstyle: Set to pagesheet, formsheet or fullscreen to set the presentation style (defaults to fullscreen).
    • transitionstyle: Set to fliphorizontal, crossdissolve or coververtical to set the transition style (defaults to coververtical).
    • toolbarposition: Set to top or bottom (default is bottom). Causes the toolbar to be at the top or bottom of the window.
    • hidespinner: Set to yes or no to change the visibility of the loading indicator (defaults to no).

Supported Platforms

  • Android
  • Browser
  • iOS

Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes');

OSX Quirks

At the moment the only supported target in OSX is _system.

_blank and _self targets are not yet implemented and are ignored silently. Pull requests and patches to get these to work are greatly appreciated.

iOS Quirks

Since the introduction of iPadOS 13, iPads try to adapt their content mode / user agent for the optimal browsing experience. This may result in iPads having their user agent set to Macintosh, making it hard to detect them as mobile devices using user agent string sniffing. You can change this with the PreferredContentMode preference in config.xml.

<preference name="PreferredContentMode" value="mobile" />

The example above forces the user agent to contain iPad. The other option is to use the value desktop to turn the user agent to Macintosh.

Browser Quirks

  • Plugin is implemented via iframe,

  • Navigation history (back and forward buttons in LocationBar) is not implemented.

InAppBrowser

The object returned from a call to cordova.InAppBrowser.open when the target is set to '_blank'.

Methods

  • addEventListener
  • removeEventListener
  • close
  • show
  • hide
  • executeScript
  • insertCSS

InAppBrowser.addEventListener

Adds a listener for an event from the InAppBrowser. (Only available when the target is set to '_blank')

ref.addEventListener(eventname, callback);
  • ref: reference to the InAppBrowser window (InAppBrowser)

  • eventname: the event to listen for (String)

    • loadstart: event fires when the InAppBrowser starts to load a URL.
    • loadstop: event fires when the InAppBrowser finishes loading a URL.
    • loaderror: event fires when the InAppBrowser encounters an error when loading a URL.
    • exit: event fires when the InAppBrowser window is closed.
    • beforeload: event fires when the InAppBrowser decides whether to load an URL or not (only with option beforeload set).
    • message: event fires when the InAppBrowser receives a message posted from the page loaded inside the InAppBrowser Webview.
    • download: (Android Only) event fires when the InAppBrowser loads a URL that leads in downloading of a file.
  • callback: the function that executes when the event fires. The function is passed an InAppBrowserEvent object as a parameter.

Example

var inAppBrowserRef;

function showHelp(url) {

    var target = "_blank";

    var options = "location=yes,hidden=yes,beforeload=yes";

    inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);

    inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);

    inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);

    inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);

    inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack);

    inAppBrowserRef.addEventListener('message', messageCallBack);
}

function loadStartCallBack() {

    $('#status-message').text("loading please wait ...");

}

function loadStopCallBack() {

    if (inAppBrowserRef != undefined) {

        inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;}" });

        inAppBrowserRef.executeScript({ code: "\
            var message = 'this is the message';\
            var messageObj = {my_message: message};\
            var stringifiedMessageObj = JSON.stringify(messageObj);\
            webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);"
        });

        $('#status-message').text("");

        inAppBrowserRef.show();
    }

}

function loadErrorCallBack(params) {

    $('#status-message').text("");

    var scriptErrorMesssage =
       "alert('Sorry we cannot open that page. Message from the server is : "
       + params.message + "');"

    inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);

    inAppBrowserRef.close();

    inAppBrowserRef = undefined;

}

function executeScriptCallBack(params) {

    if (params[0] == null) {

        $('#status-message').text(
           "Sorry we couldn't open that page. Message from the server is : '"
           + params.message + "'");
    }

}

function beforeloadCallBack(params, callback) {

    if (params.url.startsWith("http://www.example.com/")) {

        // Load this URL in the inAppBrowser.
        callback(params.url);
    } else {

        // The callback is not invoked, so the page will not be loaded.
        $('#status-message').text("This browser only opens pages on http://www.example.com/");
    }

}

function messageCallBack(params){
    $('#status-message').text("message received: "+params.data.my_message);
}

Download event Example

Whenever the InAppBrowser receives or locates to a url which leads in downloading a file, the callback assigned to the "download" event is called. The parameter passed to this callback is an object with the the following properties

  • type it contains the String value "download" always
  • url The url that leaded to the downloading of file. Basically, the download link of file
  • userAgent User Agent of the webview
  • contentDisposition If the url contains "content-disposition" header, then this property holds the value of that field else this field is empty
  • contentLength If the link of the file allows to obtain file size then this property holds the file size else it contains int value 0
  • mimetype The MIME type of the file

function downloadListener(params){
    var url = params.url;
    var mimetype = params.mimetype;

    var xhr = new XMLHttpRequest();
    xhr.open("GET", params.url);
    xhr.onload = function() {
        var content = xhr.responseText;
    };
    xhr.send();

}

InAppBrowserEvent Properties

  • type: the eventname, either loadstart, loadstop, loaderror, message or exit. (String)
  • url: the URL that was loaded. (String)
  • code: the error code, only in the case of loaderror. (Number)
  • message: the error message, only in the case of loaderror. (String)
  • data: the message contents , only in the case of message. A stringified JSON object. (String)

Supported Platforms

  • Android
  • Browser
  • iOS

Browser Quirks

loadstart, loaderror, message events are not fired.

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert(event.url); });

InAppBrowser.removeEventListener

Removes a listener for an event from the InAppBrowser. (Only available when the target is set to '_blank')

ref.removeEventListener(eventname, callback);
  • ref: reference to the InAppBrowser window. (InAppBrowser)

  • eventname: the event to stop listening for. (String)

    • loadstart: event fires when the InAppBrowser starts to load a URL.
    • loadstop: event fires when the InAppBrowser finishes loading a URL.
    • loaderror: event fires when the InAppBrowser encounters an error loading a URL.
    • exit: event fires when the InAppBrowser window is closed.
    • message: event fires when the InAppBrowser receives a message posted from the page loaded inside the InAppBrowser Webview.
    • download: (Android only) event fires when the InAppBrowser loads a URL that leads in downloading of a file.
  • callback: the function to execute when the event fires. The function is passed an InAppBrowserEvent object.

Supported Platforms

  • Android
  • Browser
  • iOS

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', myCallback);
ref.removeEventListener('loadstart', myCallback);

InAppBrowser.close

Closes the InAppBrowser window.

ref.close();
  • ref: reference to the InAppBrowser window (InAppBrowser)

Supported Platforms

  • Android
  • Browser
  • iOS

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.close();

InAppBrowser.show

Displays an InAppBrowser window that was opened hidden. Calling this has no effect if the InAppBrowser was already visible.

ref.show();
  • ref: reference to the InAppBrowser window (InAppBrowser)

Supported Platforms

  • Android
  • Browser
  • iOS

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'hidden=yes');
// some time later...
ref.show();

InAppBrowser.hide

Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden.

ref.hide();
  • ref: reference to the InAppBrowser window (InAppBrowser)

Supported Platforms

  • Android
  • iOS

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank');
// some time later...
ref.hide();

InAppBrowser.executeScript

Injects JavaScript code into the InAppBrowser window. (Only available when the target is set to '_blank')

ref.executeScript(details, callback);
  • ref: reference to the InAppBrowser window. (InAppBrowser)

  • injectDetails: details of the script to run, specifying either a file or code key. (Object)

    • file: URL of the script to inject.
    • code: Text of the script to inject.
  • callback: the function that executes after the JavaScript code is injected.

    • If the injected script is of type code, the callback executes with a single parameter, which is the return value of the script, wrapped in an Array. For multi-line scripts, this is the return value of the last statement, or the last expression evaluated.

Supported Platforms

  • Android
  • Browser
  • iOS

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstop', function() {
    ref.executeScript({file: "myscript.js"});
});

Browser Quirks

  • only code key is supported.

InAppBrowser.insertCSS

Injects CSS into the InAppBrowser window. (Only available when the target is set to '_blank')

ref.insertCSS(details, callback);
  • ref: reference to the InAppBrowser window (InAppBrowser)

  • injectDetails: details of the script to run, specifying either a file or code key. (Object)

    • file: URL of the stylesheet to inject.
    • code: Text of the stylesheet to inject.
  • callback: the function that executes after the CSS is injected.

Supported Platforms

  • Android
  • iOS

Quick Example

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstop', function() {
    ref.insertCSS({file: "mystyles.css"});
});

__

Sample: Show help pages with an InAppBrowser

You can use this plugin to show helpful documentation pages within your app. Users can view online help documents and then close them without leaving the app.

Here's a few snippets that show how you do this.

Give users a way to ask for help

There's lots of ways to do this in your app. A drop down list is a simple way to do that.

<select id="help-select">
    <option value="default">Need help?</option>
    <option value="article">Show me a helpful article</option>
    <option value="video">Show me a helpful video</option>
    <option value="search">Search for other topics</option>
</select>

Gather the users choice in the onDeviceReady function of the page and then send an appropriate URL to a helper function in some shared library file. Our helper function is named showHelp() and we'll write that function next.

$('#help-select').on('change', function (e) {

    var url;

    switch (this.value) {

        case "article":
            url = "https://cordova.apache.org/docs/en/latest/"
                        + "reference/cordova-plugin-inappbrowser/index.html";
            break;

        case "video":
            url = "https://youtu.be/F-GlVrTaeH0";
            break;

        case "search":
            url = "https://www.google.com/#q=inAppBrowser+plugin";
            break;
    }

    showHelp(url);

});

Load a help page

We'll use the open function to load the help page. We're setting the hidden property to yes so that we can show the browser only after the page content has loaded. That way, users don't see a blank browser while they wait for content to appear. When the loadstop event is raised, we'll know when the content has loaded. We'll handle that event shortly.

function showHelp(url) {

    var target = "_blank";

    var options = "location=yes,hidden=yes";

    inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);

    inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);

    inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);

    inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);

}

Let users know that you're getting their page ready

Because the browser doesn't immediately appear, we can use the loadstart event to show a status message, progress bar, or other indicator. This assures users that content is on the way.

function loadStartCallBack() {

    $('#status-message').text("loading please wait ...");

}

Show the help page

When the loadstopcallback event is raised, we know that the content has loaded and we can make the browser visible. This sort of trick can create the impression of better performance. The truth is that whether you show the browser before content loads or not, the load times are exactly the same.

function loadStopCallBack() {

    if (inAppBrowserRef != undefined) {

        inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;}" });

        $('#status-message').text("");

        inAppBrowserRef.show();
    }

}

You might have noticed the call to the insertCSS function. This serves no particular purpose in our scenario. But it gives you an idea of why you might use it. In this case, we're just making sure that the font size of your pages have a certain size. You can use this function to insert any CSS style elements. You can even point to a CSS file in your project.

Handle page errors

Sometimes a page no longer exists, a script error occurs, or a user lacks permission to view the resource. How or if you handle that situation is completely up to you and your design. You can let the browser show that message or you can present it in another way.

We'll try to show that error in a message box. We can do that by injecting a script that calls the alert function. That said, this won't work in browsers on Windows devices so we'll have to look at the parameter of the executeScript callback function to see if our attempt worked. If it didn't work out for us, we'll just show the error message in a <div> on the page.

function loadErrorCallBack(params) {

    $('#status-message').text("");

    var scriptErrorMesssage =
       "alert('Sorry we cannot open that page. Message from the server is : "
       + params.message + "');"

    inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);

    inAppBrowserRef.close();

    inAppBrowserRef = undefined;

}

function executeScriptCallBack(params) {

    if (params[0] == null) {

        $('#status-message').text(
           "Sorry we couldn't open that page. Message from the server is : '"
           + params.message + "'");
    }

}

More Usage Info

Local Urls ( source is in the app package )

var iab = cordova.InAppBrowser;

iab.open('local-url.html');                  // loads in the Cordova WebView
iab.open('local-url.html', '_self');         // loads in the Cordova WebView
iab.open('local-url.html', '_system');       // Security error: system browser, but url will not load (iOS)
iab.open('local-url.html', '_blank');        // loads in the InAppBrowser
iab.open('local-url.html', 'random_string'); // loads in the InAppBrowser
iab.open('local-url.html', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar

Whitelisted Content

var iab = cordova.InAppBrowser;

iab.open('https://whitelisted-url.com');                  // loads in the Cordova WebView
iab.open('https://whitelisted-url.com', '_self');         // loads in the Cordova WebView
iab.open('https://whitelisted-url.com', '_system');       // loads in the system browser
iab.open('https://whitelisted-url.com', '_blank');        // loads in the InAppBrowser
iab.open('https://whitelisted-url.com', 'random_string'); // loads in the InAppBrowser

iab.open('https://whitelisted-url.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar

Urls that are not white-listed

var iab = cordova.InAppBrowser;

iab.open('https://url-that-fails-whitelist.com');                  // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', '_self');         // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', '_system');       // loads in the system browser
iab.open('https://url-that-fails-whitelist.com', '_blank');        // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
iab.open('https://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar

cordova-plugin-inappbrowser's People

Contributors

agrieve avatar alsorokin avatar breautek avatar cjpearson avatar clelland avatar cmarcelk avatar darron1217 avatar dblotsky avatar dpa99c avatar erisu avatar filmaj avatar hermwong avatar infil00p avatar janpio avatar jcesarmobile avatar ldeluca avatar macdonst avatar mosabab avatar mrbberra avatar niklasmerz avatar purplecabbage avatar riknoll avatar sailingsteve avatar sgrebnov avatar shazron avatar steinaragustli avatar stevengill avatar surajpindoria avatar timbru31 avatar zalun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-inappbrowser's Issues

No option to use camera when uploading files on Android

This seems to be a known issue previously, but using inappbrowser simply won't give me the normal options on android for uploading files in a browser form, whereas ios seems fine (once I'd added the permissions to the config.xml). I can see there are various pull requests that fix this so I suspect I'm doing something wrong.

I've tried adding various native plugins to add permissions in case that changes it, or used the config.xml to add the permissions to the androidmanifest.xml for the camera in case it's that that's stopping it but I'm never granted the permissions.

My app.module.ts is

import { BrowserModule } from "@angular/platform-browser";
import { ErrorHandler, NgModule } from "@angular/core";
import { IonicApp, IonicErrorHandler, IonicModule } from "ionic-angular";

import { MyApp } from "./app.component";
import { HomePage } from "../pages/home/home";
import { ListPage } from "../pages/list/list";

import { StatusBar } from "@ionic-native/status-bar";
import { SplashScreen } from "@ionic-native/splash-screen";
import { InAppBrowser } from "@ionic-native/in-app-browser";
import { AndroidPermissions } from "@ionic-native/android-permissions";

@NgModule({
  declarations: [MyApp, HomePage, ListPage],
  imports: [BrowserModule, IonicModule.forRoot(MyApp)],
  bootstrap: [IonicApp],
  entryComponents: [MyApp, HomePage, ListPage],
  providers: [
    StatusBar,
    SplashScreen,
    { provide: ErrorHandler, useClass: IonicErrorHandler },
    InAppBrowser,
    AndroidPermissions
  ]
})
export class AppModule {}

home.ts

import { Component, OnInit } from "@angular/core";
import { NavController } from "ionic-angular";
import {
  InAppBrowser,
  InAppBrowserOptions
} from "@ionic-native/in-app-browser";
import { AndroidPermissions } from "@ionic-native/android-permissions";

@Component({
  selector: "page-home",
  templateUrl: "home.html"
})
export class HomePage {
  constructor(
    public navCtrl: NavController,
    private inAppBrowser: InAppBrowser,
    private androidPermissions: AndroidPermissions
  ) {}
  openWebpage(url: string) {
    const options: InAppBrowserOptions = {
      zoom: "no",
      location: "no",
      hidenavigationbuttons: "yes",
      hideurlbar: "yes",
      footer: "yes",
      toolbar: "yes",
      closebuttoncaption: "Return to home",
      toolbarcolor: "#ffffff"
    };

    // Opening a URL and returning an InAppBrowserObject
    const browser = this.inAppBrowser.create(url, "_blank", options);

    this.androidPermissions
      .checkPermission(
        this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE
      )
      .then(
        result => console.log("Has permission?", result.hasPermission),
        err =>
          this.androidPermissions.requestPermission(
            this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE
          )
      );

    this.androidPermissions
      .checkPermission(this.androidPermissions.PERMISSION.CAMERA)
      .then(
        result => console.log("Has permission?", result.hasPermission),
        err =>
          this.androidPermissions.requestPermission(
            this.androidPermissions.PERMISSION.CAMERA
          )
      );

    this.androidPermissions.requestPermissions([
      this.androidPermissions.PERMISSION.CAMERA
    ]);

    // Inject scripts, css and more with browser.X
  }
}

ionic info

ionic info
✔ Gathering environment info - done!

Ionic:

   ionic (Ionic CLI)  : 4.1.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.11

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.1.1, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic 5.0.5, cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.0.3, (and 8 other plugins)

System:

   Android SDK Tools : 26.1.1
   ios-deploy        : 2.0.0
   NodeJS            : v8.11.3 (/usr/local/bin/node)
   npm               : 5.6.0
   OS                : macOS High Sierra
   Xcode             : Xcode 9.4.1 Build version 9F2000

Environment:

   ANDROID_HOME : /Users/Paul/Library/Android/sdk

plugins installed (some aren't used now, I added file, and camera to see if they added the camera permissions to the app)

ionic cordova plugins list
> cordova plugin ls
cordova-plugin-android-permissions 1.0.0 "Permissions"
cordova-plugin-camera 4.0.3 "Camera"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic 5.0.5 "cordova-plugin-ionic"
cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.0.3 "cordova-plugin-ionic-webview"
cordova-plugin-media-capture 3.0.2 "Capture"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-whitelist 1.3.3 "Whitelist"

I'm running the app on a Mac, using the command 'ionic cordova run android --device'

I have an unlocked Galaxy s7 in usb debug mode connected which is running the app. When I access the same webpages in the normal browser I get all the camera options I'd expect. The android version is 8.0.0, with the Samsung Experience of 9.0

The output from the debug console tells me that I have file write permissions, but not camera permissions. I also can't add that permission in the android settings as it never appears.

iOS: Inappbrowser close method successcallback called before the inappbrowser viewcontroller is actually dismissed

In cordova inappbrowser ios implementation, after presenting an inappbrowser viewcontroller, the javascript code can call close method to close it, then immediately present another inappbrowser viewcontroller.

Basically the javascript code starts the second inappbrowser instance in the first inappbrowser's close's successcallback method.

However, with the current ios implementation, the close method's successcallback is called in browserExit method. At that moment, the inappbrowser viewcontroller may not yet be dismissed, as a result, opening the second inappbrowser viewcontroller may fail randomly due to this timing issue.

One possible solution is, instead of calling the close methods' succcesscallback from the browserExit method, it can be called on inappbrowser's dismissViewControllerAnimated's completion block. At that moment, the current inappbrowser is already dismissed, and it is safe to open a new inappbrowser instance.

Change ios inappbrowser default value for browserOptions.usewkwebview

For the new ios inappbrowser plugin, it uses usewkWebView to decide whether using UIWebView or WKWebView, and the default value is NO.

Assuming a cordova project currently uses UIWebView for inappbrowser plugin and cordova main webview. Later the project is upgraded to use wkwebview, usually the developers want to use wkwebview in both inappbrowser and main webview after the upgrading. In that case, the developer needs to update the project to explicitly set the browserOptions.usewkwebview in all the places when inappbrowser is opened.

This change can be avoided if the default value of browserOptions.usewebview can be decided based on the main cordova UIWebView type. So in case the caller does not explicitly set the browserOptions.usewebview value, if the main cordova UIWebView uses wkwebview, then inappbrowser can automatically set usewkwebview to true. Otherwise setting it to false.

With this approach, the project can be upgraded to use wkwebview without any change the code. While it still allows developers to explicitly set usewkwebview if the default behavior does not fit.

This approach is currently used in our cordova projects, but if this is a common issue for others, then it makes sense to have this logic implemented in inappbrowser plugin.

Thanks
Jonathan

Service Worker Support?

I am using a website built with Create React App that utilizes a service worker to allow the application to be opened and viewed when offline. It appears that the inappbrowser does not have built in support for this. Would it be possible to add this or is there another recommended method of serving offline content with inappbrowser?

[Tests/CI/Travis] android-7.0 tests are failing

This is the configration that is failing:

  "os": "linux",
  "env": "PLATFORM=android-7.0",
  "jdk": "oraclejdk8",

Last successful build was:
https://travis-ci.org/apache/cordova-plugin-inappbrowser/builds/344652192
(Feb 22)

First failing build was:
https://travis-ci.org/apache/cordova-plugin-inappbrowser/builds/357149499
(Mar 21)

(end of page #1 of https://github.com/apache/cordova-plugin-inappbrowser/commits/master right now)

Error message on Travis was:

...
..............................................
cordova-paramedic: connecting to app
cordova-paramedic: waiting for test results
cordova-paramedic: Tests failed to complete; ending appium session. The error is:
Error: Seems like device not connected to local server in 300 secs
    at null._onTimeout (/tmp/paramedic/lib/paramedic.js:467:24)
    at Timer.listOnTimeout (timers.js:92:15)
Running Appium tests on Sauce Labs
Couldn't find Appium tests, skipping...
Completed tests at 10:02:21 AM
Getting saucelabs jobs details...
============================================================================================
Job name: travis-plugin-inappbrowser-436.10
Job ID: 11b69418b01a4cc1b09607b000b9e40c
Job URL: https://saucelabs.com/beta/tests/11b69418b01a4cc1b09607b000b9e40c
...

Commit was: 65a825a So nothing concerning Android, so probably more a testing environment thing.

Most commits after that one were failing with the same test failing.
Some succeeded without a real reason.
Some other more recent commits succeeded because the test was just removed.


More recent test run that is failing, where the video and logs are still available on Saucelabs:

cordova-paramedic: connecting webdriver
...........................
cordova-paramedic: connecting to app
cordova-paramedic: waiting for test results
cordova-paramedic: Tests failed to complete; ending appium session. The error is:
Error: waitForTests: Seems like device not connected to local server in 540 secs
    at null._onTimeout (/tmp/paramedic/lib/paramedic.js:467:24)
    at Timer.listOnTimeout (timers.js:92:15)
Running Appium tests on Sauce Labs
Couldn't find Appium tests, skipping...
Completed tests at 1:25:20 PM
Getting saucelabs jobs details...
============================================================================================
Job name: travis-plugin-inappbrowser-516.10
Job ID: 8a2a6c5d12714125b366852914355361
Job URL: https://saucelabs.com/beta/tests/8a2a6c5d12714125b366852914355361
Video: https://assets.saucelabs.com/jobs/8a2a6c5d12714125b366852914355361/video.flv
Appium logs: https://assets.saucelabs.com/jobs/8a2a6c5d12714125b366852914355361/selenium-server.log
Logcat logs: https://saucelabs.com/jobs/8a2a6c5d12714125b366852914355361/logcat.log
============================================================================================

The screenshot indicates that the tests run and and finish just fine.

'loadstop' event stopped working in iOS 12.0

Hi All,

We have got a critical production issue in Cordova mobile application related to in-App browser with iOS 12.0 version.

The issue is loadStop() event of InAppBrowser is not being triggered if the URL contains “?” symbol, for normal URL’s it is working fine.

This is the URL we are using to open website from InAppBrowser.

URL: https://aamobile-qa.farmcredit.net/accountsmobi/index.html?https://aamobile-qa.farmcredit.net/AccountAccessService/ServiceContracts

This issue has been raised after device being updated to latest iOS version 12.0.
Request you to kindly provide your support for the same.

Thanks in advance.

Android: executeScript failing for large return values (length greater than 10240)

Since Android updated to webview v 69.0.3497.91, any script that runs that returns content longer than 10240 bytes fails as the message gets truncated

Bug appears here: https://github.com/apache/cordova-plugin-inappbrowser/blob/master/src/android/InAppChromeClient.java#L114

JSONException occurs as message is invalid JSON (truncated string)

Bug has been lodged with Chrome but they won't fix it:

https://bugs.chromium.org/p/chromium/issues/detail?id=884100

In the bug they report:

I don't think you should rely on prompt() as a means of passing data from JS to Java. There are other APIs that are properly suited to this task.

I am about to try a few ideas either addJavascriptInterface or evaluateJavascipt instead of prompt but would be open to suggestions of other interfaces

Note: This works OK if chrome is uninstalled and the default Android WebView is used

window.prompt as IPC unreliable as of ChromeWebView version 69

Chrome recently introduced a limit to the length of data that can be passed through the window.prompt interface. It is now limited to 10240 bytes.

This interface has been (mis-)used for message passing in the Android implementation.

Unfortunately, this results in some quite unexpected behaviour, when Javascript evaluation results exceed 10240 bytes.

No description for "replace?" parameter

While url, target and options are documented, there is no description/documentation for the optional replace parameter in the index.d.ts file (line 45). The function is:
open(url: string, target?: string, options?: string, replace?: boolean): InAppBrowser;

I'm curious whats replace about.

iOS CDVWKInAppBrowser evaluateJavascript method randomly gets blocked on iOS 12

Hi,
While testing the new ios inappbrowser plugin with wkwebview on iOS 12 device, when the javascript code calls injectScriptCode method, the application may hang.
The reason is in CDVWKInAppBrowser.m, the completing block of evaluateJavascrip method is not called, so the method stuck in the while (!finished) loop

_- (NSString *)evaluateJavaScript:(NSString *)script {
__block NSString resultString = nil;
__block BOOL finished = NO;
__block NSString
_script = script;
NSLog(@"evaluateJavaScript: %@", script);
[self.inAppBrowserViewController.webView evaluateJavaScript:script completionHandler:^(id result, NSError *error) {
NSLog(@"evaluatejavascript result: %@, %@", result, error);
if (error == nil) {
if (result != nil) {
resultString = result;
NSLog(@"%@", resultString);
}
} else {
NSLog(@"evaluateJavaScript error : %@ : %@", error.localizedDescription, _script);
}
finished = YES;
}];

while (!finished)
{
    NSLog(@"CDVWKInAppbrowser evaluateJavaScript runloop");
    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
NSLog(@"evaluateJavaScript: %@", resultString);
return resultString;

}_

The xcode console log has the below output. After calling evaluatejavascript method, it calls runloop method few times in while block, and then just stops, the app is idle.

2018-11-02 09:44:32.646767-0400 wk[5669:2032638] evaluateJavaScript: (function(w){if(!w._cdvMessageHandler) {w._cdvMessageHandler = function(id,d){w.webkit.messageHandlers.cordova_iab.postMessage({d:d, id:id});}}})(window)
2018-11-02 09:44:39.013119-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.013583-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.013827-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.014057-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.014336-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.014561-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.014789-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.015012-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.015234-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.015455-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.015676-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.015898-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.016120-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.016400-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.016622-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.016848-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.017239-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.021299-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.037837-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:44:39.054533-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop
2018-11-02 09:45:47.383791-0400 wk[5669:2032638] CDVWKInAppbrowser evaluateJavaScript runloop

I saw someone else also reported the same issue on ios 12 device testing at
https://stackoverflow.com/questions/26778955/wkwebview-evaluate-javascript-return-value
(see the first answer), so this may relate to the iOS 12 behavior change.

Thanks for help.

Jonathan

Android - Footer Overlaps WebView

On Android, when setting footer to yes, the footer bar overlaps the WebView content, causing it to cover up the bottom slice of the WebView.

I was able to fix the issue by forking the library and using setMargins on the WebView's LinearLayout.LayoutParams equal to the height of the footer, but I only did that because I could not get any other way to work so I am not sure if this is the best way to fix the problem.

My fix is below.

FROM:

inAppWebView = new WebView(cordova.getActivity());
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

TO:

int footerSize = this.dpToPixels(44);

inAppWebView = new WebView(cordova.getActivity());

LinearLayout.LayoutParams webViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

if (showFooter) {
    webViewLayoutParams.setMargins(0, 0, 0, footerSize); // Adding margin the same size as the footer
}

inAppWebView.setLayoutParams(webViewLayoutParams);

loaderror not getting called on iOS 12

For example, if I’m on our external network and try to hit an internal url it use to call loaderror… now I just get a blank page and no event. This mostly happens on an iPhone X. It occasionally happens on my iPhone 7 (running iOS 12).

body被toolbar遮挡

inappbrowser v3.0.0
使用如下配置:location=no, toolbar=no,hidenavigationbuttons=yes,closebuttoncaption=X,disallowoverscroll=yes,toolbarcolor=#eaeffa,toolbarposition=top,transitionstyle=fliphorizontal,toolbartranslucent=yes'

在iOS11系列的机器上,body顶部被toolbar遮挡,有可配置的参数吗

Video doesn't toggle to fullscreen on the inappbrowser

I built an app that gathers links and opens them in the inappbrowser.
The links open in the inappbrowser and some of the links contain videos. However they do NOT play fullscreen on android.

Any help will be appreciated. Thank you.

iPhone X support

On iPhone X and higher the inappbrowser looks like this (I'm referring to the status bar):

img_0108

I have added the new splashscreen image and the app itself looks great. Is there a way to fix this?

Is there also a way to keep the content of the inappbrowser from going under the "homebar"?

img_0107

Phonegap uses "constant(safe-area-inset-bottom)" and "env(safe-area-inset-bottom)" for this.

usewkwebview will crash on iOS 9.0 ~ 9.3

usewkwebview=yes will crash on iOS 9.0 ~ 9.3
10.3.1, 11.0.1, 12.0 work correctly.

Xcode debug console output
XApp[16531:942778] -[WKWebViewConfiguration setIgnoresViewportScaleLimits:]: unrecognized selector sent to instance 0x7fcabdd1fe00

XApp[16531:942778] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WKWebViewConfiguration setIgnoresViewportScaleLimits:]: unrecognized selector sent to instance 0x7fcabdd1fe00'
...
libc++abi.dylib: terminating with uncaught exception of type NSException

InApp browser not support in iPhone X devices

Hi
Currently, i am using latest inappbrowser plugin 3.0.0
node v8.11.1
npm v5.6.0
PhoneGap cli-8.0.0

Facing some issues in iPhone X device.
Current behavior:

  1. inappbrowser distorted UI in the status bar section.
  2. In the bottom bar URL load section shown in the safe area.
  3. website load under the toolbar section.

Expected behavior

  1. toolbar covers the status bar section also like other apps.
  2. Bottom load URL show above the safe area.
  3. Load website starts after the toolbar section.

Option Fileds that I am using.
Code :
hidden=yes,mediaPlaybackRequiresUserAction=yes,closebuttoncaption=Done,toolbarposition=top,enableViewportScale=yes,toolbar=yes,toolbarcolor=#8bc34a,hidenavigationbuttons=no,navigationbuttoncolor=#ffffff,closebuttoncolor=#8bc34a

image

Thanks In Advance 🙏:skin-tone-2:

InAppBrowser unable to handle nested content?

I have some help docs that I want to render in the InAppBrowser. They are a series of nested HTML, JS and CSS files; when I point to the top level .htm file, the IAB comes up blank since there is nothing in the body; it is used to load other HTML files. However, when I point to a file deeper in the nest, say Home.htm, I can see that page's content, but none of the dynamic content works: the hamburger menu doesn't function, navigation to other pages does not work, etc. The site was built using MadCap Flare; here is one of their example projects that exhibits the same symptoms: https://github.com/skrawn/madcap_example Any ideas about what could cause it?

UI rendering problem with _blank target

I am using InAppBrowser to open a web page from an ionic 3 app. The page which I open has a alphascroll component which is similar to https://github.com/rossmartin/ionic2-alpha-scroll. If I open the page using the InAppBrowser browser target as _blank, when I scroll through the alphascroll to move up and down the lists in alphabetical order, there is a noticeable lag in updating the list and after few scrolls the list goes blank. If I use the targert option as _self or _system the scroll works perfectly. Does anybody know why these rendering issues are seen with the _blank target?

iOS 11.4.1 XCode 10.0 after inAppBrowser closed, app does not respond to touch events

After the inAppBrowser is closed (after viewing a website), the app does not respond to normal touch events - touch, swipe etc.

The app still handles timer events in the background, so potentially this is an issue with how events are intercepted between the inAppBrowser and the underlying app, but the interceptor is not removed correctly when the inAppBrowser is closed.

Keep status bar color when browser popup

I set the system status bar color as green on startup, but when inappbrowser popup, the status bar turn black, is there any way to keep it as green?
call code:

onButtonClick(itemInfo) {
    let descUrl = itemInfo.desc_url;
    this.inAppBrowser.create(descUrl, '_self', 'hideurlbar=yes,toolbarcolor=#009999,closebuttoncolor=#FFFFFF,navigationbuttoncolor=#FFFFFF');
  }

executeScript does not fire - issue ionic 3

I am using this plugin in ionic 3.
Here is the piece of code

browser.on('loadstop').subscribe(event => {

    console.log(event,"event inside browser on")
 browser.executeScript({code: 'mycallback'}).then(data=>{
     console.log("script executed",data);
    },err=>{
      console.log(err,"error in executing the script");
    })

});

loadstop event is working fine, but executeScript doesnot work. Its not going to err section also.

Getting an error while upgrading Cordova android to 7.1.1

While

updating the Android Cordova 6.2.3 to 7.1.1 getting the following error, I am sure the issue is with the AndroidManifest.xml file but as per the Cordova release notes I have pushed the changes to my config file but still getting this error.

: Error: ENOENT: no such file or directory, open '/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/AndroidManifest.xml'
   at Object.fs.openSync (fs.js:646:18)
   at Object.fs.readFileSync (fs.js:551:33)
   at Object.parseElementtreeSync (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
   at new AndroidManifest (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/lib/AndroidManifest.js:29:20)
   at AndroidProject.getPackageName (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/lib/AndroidProject.js:99:12)
   at Api.addPlugin (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/Api.js:223:57)
   at handleInstall (/Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/src/plugman/install.js:594:10)
   at /Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/src/plugman/install.js:357:28
   at _fulfilled (/Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/node_modules/q/q.js:787:54)
   at self.promiseDispatch.done (/Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/node_modules/q/q.js:816:30)
(node:76349) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/AndroidManifest.xml'
   at Object.fs.openSync (fs.js:646:18)
   at Object.fs.readFileSync (fs.js:551:33)
   at Object.parseElementtreeSync (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
   at new AndroidManifest (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/lib/AndroidManifest.js:29:20)
   at AndroidProject.getPackageName (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/lib/AndroidProject.js:99:12)
   at Api.addPlugin (/Users/brains05/KK/PoolTrackr/mobile_app/platforms/android/cordova/Api.js:223:57)
   at handleInstall (/Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/src/plugman/install.js:594:10)
   at /Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/src/plugman/install.js:357:28
   at _fulfilled (/Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/node_modules/q/q.js:787:54)
   at self.promiseDispatch.done (/Users/brains05/KK/PoolTrackr/mobile_app/node_modules/cordova-lib/node_modules/q/q.js:816:30)
(node:76349) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting apromise which was not handled with .catch(). (rejection id: 1)
(node:76349) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Its an ionic project and here its my info

Ionic:

  ionic (Ionic CLI) : 4.1.1 (/usr/local/lib/node_modules/ionic)
  Ionic Framework   : ionic1 1.3.0
  @ionic/v1-toolkit : 1.0.0

Cordova:

  cordova (Cordova CLI) : 8.0.0
  Cordova Platforms     : none
  Cordova Plugins       : no whitelisted plugins (27 plugins total)

System:

  Android SDK Tools : 26.0.2 (/usr/local/opt/android-sdk)
  ios-deploy        : 2.0.0
  NodeJS            : v8.11.3 (/usr/local/bin/node)
  npm               : 6.4.0
  OS                : macOS High Sierra
  Xcode             : Xcode 9.4.1 Build version 9F2000

When In app browser is shown, base Cordova Webview does not honour page visibility

The Page Visibility API allows an app to know whether a page is currently being displayed to a user or not.

It seems that the typical in app browser use case does not honour this.

For example, if a Cordova app shows an in app browser to allow a user to login, the base Cordova web view should report that it is not visible.

The current (IMO incorrect behaviour) is for the page visibility API to return visible for the Cordova web view when the IAB is shown, rendering the page visibility API as useless in Cordova 😞

Authentication prompt not happening in inappbrowser

I am trying make authentication to the server. When i open the url in browser it prompts for authentication.
The same i have tried with inappbrowser but it wont prompts for authentication directly it redirects to unauthorised access. Unable to get authentication prompt to authenticate

Below is the prompt when i open in browser

image

Typings does not export cordova.InAppBrowser.open

Hi,
This is a great plugin! thanks for all the hard work!
In the documentation it is suggested to do the following:
window.open = cordova.InAppBrowser.open;
However when using typescript this is not possible without using any or something similar.
Please add the relevant declaration to the types file.

loadError raise NSURLErrorDomain error -999 on iOS

Hi,

I've experienced error "NSURLErrorDomain error -999" on iOS (tested on iOS12) using [email protected] with [email protected]

image

var ref = window.open(url, target, options);

ref.addEventListener('loadstart', loadStartCallBack);
ref.addEventListener('loadstop', loadStopCallBack);
ref.addEventListener('loaderror', loadErrorCallBack);
			
function loadErrorCallBack(params) {
  
  $('#status-message').text("");
  
  var scriptErrorMesssage =
  "alert('Sorry we cannot open that page. Message from the server is : "
  + params.message + "');"
  
  ref.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
  
  ref.close();
  
  ref = undefined;
}

function executeScriptCallBack(params) {
  
  if (params[0] == null) {
    
    $('#status-message').text(
      "Sorry we couldn't open that page. Message from the server is : '"
      + params.message + "'");
  }
}

I've found a workaround on following issue. It works well only if I remove ref.addEventListener('loaderror', loadErrorCallBack);

Properly handle custom URL schemes?

It seems that custom URL schemes are not correctly handled, at least on Android.

For example, this plugin (https://github.com/EddyVerbruggen/Custom-URL-scheme) suggests that users use a forked version of the in app browser to handle these custom URL schemes (
https://github.com/Innovation-District/cordova-plugin-inappbrowser).

The problem is that an in-app-browser & custom URL scheme setup is particularly useful for OAuth authentications in Cordova apps. So trusting some random fork of the In App Browser plugin for these security sensitive use cases seems like a bad idea.

From looking at the source code for In App Browser, it seems that it additionally rejects custom URL schemes and attempts to re-write them, seemingly making intercepting the custom url scheme page loads with the 'loadstart' event not possible: http://git.lunargravity.be/project/Dag-secret-calculator/blob/3587c7a66a932c7de7183776880a55b4047eeb78/plugins/cordova-plugin-inappbrowser/src/android/InAppBrowser.java#L872

To be clear, this only appears to be an issue on android - for whatever reason iOS is perfectly happy loading custom URL schemes from the In App Browser.

With the new ios inappbrowser change for wkwebview support, the main webview content is disabled

Just upgrade our product ios Fiori client app with the updated inappbrowser plugin for master with the wkwebview support.

However, somehow after loading the web content in the main webView (UIWebView or WKWebView), the UI element in the main webview is disabled. Clicking on the button or other UI element does not have any response.

The same app with inappbrowser version 2.0 works as expected.

To repeat the issue, the three ios projects are shared at the below folder:
https://sap-my.sharepoint.com/:f:/p/jonathan_li/EmulfDR6x9RBuQdj5u1-NrwBYchculWO6RAfoC_NTM8XLw?e=YzzUkh

2.0WithUIWebView.zip
Fiori client build with inappbrowser plugin version 2.0.x. The main webview uses UIWebView.

masterWithUIWebview.zip
Fiori client build with inappbrowser plugin from master. The main webview uses UIWebView.

masterWithWKWebView.zip
Fiori client built with inappbrowser plugin from master. The main webview uses WKWebView.

Steps to repeat the issue:

  1. build the xcode project and deploy to ios device. My device is iPhone 7 with iOS 12.0.1
  2. after start the app, click "Demo Mode" button
  3. Once the web content is shown, click the "See it in action" button.

When the project is built with inappbrowser 2.0 and UIWebView (2.0WithUIWebView.zip), click the "See it in action" button will go to the next page. In addition, double tab on the screen will show the toolbar items.

But after upgrading the project to latest inappbrowser plugin (masterWithUIWebview.zip), the main UIWebview does not response to the button click, or double tab. I also built a project with WKWebView as main UIwebView (masterWithWKWebView.zip), and got the same result.

Please look into this issue and see what causes this behavior change, particularly for the case when UIWebView is used as main webView.

Thanks
Jonathan

usewkwebview = yes crash iOS 9.X

usewkwebview=yes will crash on iOS 9.0 ~ 9.3
10.3.1, 11.0.1, 12.0 work correctly.

Xcode debug console output
XApp[16531:942778] -[WKWebViewConfiguration setIgnoresViewportScaleLimits:]: unrecognized selector sent to instance 0x7fcabdd1fe00

XApp[16531:942778] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WKWebViewConfiguration setIgnoresViewportScaleLimits:]: unrecognized selector sent to instance 0x7fcabdd1fe00'
...
libc++abi.dylib: terminating with uncaught exception of type NSException

pdf is not opening in android inappbrower using ionic 3.

I am using ionic 3 plugin to view pdf inappbrowser. It is working fine in ios but not working in android.

I am using following code :

this.iab.create("pdfurlhere", "_blank").show();

I am getting any error and log in new window.

Share code between ios CDVWKInAppBrowser and CDVUIInaAppBrowser

Hi,
Currently both CDVWKInAppBrowser and CDVUIInAppBrowser are inherited from generic root interface of CDVPlugin. However, since CDVWKInAppBrowser and CDVUIInAppBrowser have the similar functions, they have many functions with the same implementation.

In order to avoid the duplicated code for easy maintenance, it is better to have a common base interface (like CDVInAppBrowserBase) containing the common code for both CDVUIInAppBrowser and CDVWKInAppBrowser interface.

Actually, it makes sense if the logic can be refactored to use CDVInAppBrowser as the base interface, and then derives CDVWKWebView and CDVUIWebView from it, instead of deriving all of them from CDVPlugin.

Thanks
Jonathan

SSL errors handling in Android

Currently when I open a website with InAppBrowser and Android which have an invalid certificate (because of a missing chaining certificate) InAppBrowser only display a black screen and dispatch two event, a "loadstart" event and a "loadend" event.

I think that InAppBrowser should fire a "loaderror" event in order to known that something bad happened with ssl.

Download file not working

I am using the inappbrowser to download an .apk file, but the download does not start.
I've tested the HTML page by using several mobile browser and everything works.
Any feedbacks?

HTTP and HTTPS mixed content errors.

Need an option to toggle/allow it ->
WebSettings settings = inAppWebView.getSettings(); settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
fixes the blocked issue, which is big because I am running an http webpage through google translate which is https. Both inwhich I cannot manage, google translate is https only, the webpage is only http.

InAppBrowser.java:260: error: cannot find symbol

I tried update the plugin to the latest version and tried to build the apk and I got this error.

F:\Work\androidProject\platforms\android\src\org\apache\cordova\inappbrowser\InAppBrowser.java:260: error: cannot find symbol

                ((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
                                                 ^

symbol: method getWebViewClient()

location: variable inAppWebView of type WebView

Any idea about this?
I am using Ionic 1 and platform android 6.1.0

Edit:
Downgrade to v3.0.0 and successfully built the apk. seems the error happened on v3.0.1-dev

No sound from YouTube video when iOS on silent

It is normal for sound to play when playing YouTube videos in browsers or in apps when the phone is on silent - however this doesn't happen in the inappbrowser, as such I'm needing to add a warning instructing users if they hear no sound to un-mute the phone - please can there be an option to allow audio from the inappbrowser even when the phone is on silent.

Youtube, Vimeo, others - second played video crashes the app when opened in native player - IOS

cordova-lib: 7.1.0
cordova-ios: 4.5.4
cordova-plugin-inappbrowser: 3.0.0
Same behavior in cordova-plugin-inappbrowser-wkwebview

Tested with IPhone 6 - IOS latest Beta of 12, Xcode10 and Simulator for Iphone 6, IOS11.4, Simulator for Iphone XS IOS 12.

Open a Youtube link in inappbrowser. The native video player starts, all OK. Stop, tap on another suggested video. In real device app closes down. In Simulator app freezes.

The highlight in red is displayed right after tap to watch the second video.

Meaning of EXC_BAD_ACCESS

Later Edit: after more testing, I guess it happens with any video source and it seems to be an issue between the inapbrowser and the native video player.
Later..er Edit: all ok if 'allowInlineMediaPlayback=yes' and the native player is not opened. However, if the video is pushed to full screen (native player) -> go to the top of this text.

screen shot 2018-09-14 at 12 09 54

Hide both location and toolbar on ios

Hello,

I would like to disappear the toolbar and url address for ios. But it seems it doesn't work.

inAppBrowserRef = cordova.InAppBrowser.open('url', '_blank', 'location=no, zoom=no, toolbar=no');

The toolbar just being there. What is the problem?

Improve beforeload event

In #276 (CB-14188) the beforeload event was added.
This event currently uses the same callback mechanism as other events, but it is different in one important aspect: instead of just notifying that something happened, it expects an action to be called. It would be good to allow a synchronous callback instead.

App freezing after opening the InAppBrowser on specific URLs / Inputs

I would like to bring to attention an issue (I believe it's a bug, could be wrong) which I've come across. I believe it is easy to reproduce, and managed to successfully reproduce it repeatedly myself on a test environment. Zip file linked bottom of issue containing the test environment. GIF showing the issue added below.

In brief, the problem is that on some particular sites, whenever navigation / keyboard is triggered in the InAppBrowser window, it is causing the underlying application to freeze and become unresponsive to any user actions.

Environment: Cordova 8, iOS 4.5.5 and Ionic 3
Affected Platform : iOS
Versions: iOS v11.4
Devices Affected: iPhone 5 up to 6S/Plus

Steps to reproduce:

  1. Create a blank project (Ionic, whatever flavour you prefer).
  2. Add reference to the InAppBrowser plugin
  3. Run use case below:
  • Open https://www.google.com in InAppBrowser
  • Locate the search bar on the page and type something.
  • Click / tap outside of the search bar
  • Close the InAppBrowser instance
  • App will be unresponsive

ezgif com-gif-maker

Link to test environment : iab-test.zip

Issue with status bar on iPhone X when toolbar is at the top (v3.0.0)

There is an issue with the status bar and the iPhone X as described at https://stackoverflow.com/questions/47399938/issue-with-status-bar-using-cordova-inappbrowser-and-ios-11-and-iphone-x

When the inappbrowser toolbar is at the top of the screen, the status bar on the iPhone X is half white and half gray.

Changing the following line in CDVInAppBrowser.m solves the problem and makes the whole status bar gray. Change line:
statusBarFrame.size.height = STATUSBAR_HEIGHT;
to
statusBarFrame.size.height = 0;

This does not seem to negatively affect other iPhones or iPads.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.