Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cordova-plugin-inappbrowser

Package Overview
Dependencies
Maintainers
5
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-plugin-inappbrowser - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

.github/PULL_REQUEST_TEMPLATE.md

16

package.json
{
"name": "cordova-plugin-inappbrowser",
"version": "1.4.0",
"version": "1.5.0",
"description": "Cordova InAppBrowser Plugin",

@@ -44,8 +44,12 @@ "cordova": {

},
"engines": [
{
"name": "cordova",
"version": ">=3.1.0"
"engines": {
"cordovaDependencies": {
"0.2.3": {
"cordova": ">=3.1.0"
},
"2.0.0": {
"cordova": ">100"
}
}
],
},
"author": "Apache Software Foundation",

@@ -52,0 +56,0 @@ "license": "Apache-2.0",

@@ -0,1 +1,5 @@

---
title: Inappbrowser
description: Open an in-app browser window.
---
<!--

@@ -20,6 +24,12 @@ # license: Licensed to the Apache Software Foundation (ASF) under one

[![Build Status](https://travis-ci.org/apache/cordova-plugin-inappbrowser.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-inappbrowser)
|Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI |
|:-:|:-:|:-:|:-:|:-:|:-:|
|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-inappbrowser.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-inappbrowser)|
# cordova-plugin-inappbrowser
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](#sample) at the bottom of this page or go straight to the [reference](#reference) content.
This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`.

@@ -63,3 +73,3 @@

## <a id="reference">Reference
## Installation

@@ -84,3 +94,3 @@

- __ref__: Reference to the `InAppBrowser` window. _(InAppBrowser)_
- __ref__: Reference to the `InAppBrowser` window when the target is set to `'_blank'`. _(InAppBrowser)_

@@ -109,2 +119,3 @@ - __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL contains Unicode characters.

- __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](https://issues.apache.org/jira/browse/CB-11013)).

@@ -132,2 +143,3 @@ iOS only:

- __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window.
- __hardwareback__: works the same way as on Android platform.

@@ -197,3 +209,3 @@ ### Supported Platforms

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

@@ -226,2 +238,72 @@ ### Methods

## Example
```javascript
var inAppBrowserRef;
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);
}
function loadStartCallBack() {
$('#status-message').text("loading please wait ...");
}
function loadStopCallBack() {
if (inAppBrowserRef != undefined) {
inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" });
$('#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 + "'");
}
}
```
### InAppBrowserEvent Properties

@@ -404,1 +486,202 @@

});
__
## <a id="sample"></a>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](#give).
* [Load a help page](#load).
* [Let users know that you're getting their page ready](#let).
* [Show the help page](#show).
* [Handle page errors](#handle).
### <a id="give"></a>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.
```html
<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.
```javascript
$('#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);
});
```
### <a id="load"></a>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.
```javascript
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);
}
```
### <a id="let"></a>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.
```javascript
function loadStartCallBack() {
$('#status-message').text("loading please wait ...");
}
```
### <a id="show"></a>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.
```javascript
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.
### <a id="handle"></a>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.
```javascript
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('http://whitelisted-url.com'); // loads in the Cordova WebView
iab.open('http://whitelisted-url.com', '_self'); // loads in the Cordova WebView
iab.open('http://whitelisted-url.com', '_system'); // loads in the system browser
iab.open('http://whitelisted-url.com', '_blank'); // loads in the InAppBrowser
iab.open('http://whitelisted-url.com', 'random_string'); // loads in the InAppBrowser
iab.open('http://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('http://url-that-fails-whitelist.com'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', '_self'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', '_system'); // loads in the system browser
iab.open('http://url-that-fails-whitelist.com', '_blank'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
```

@@ -23,8 +23,31 @@ <!--

### 1.5.0 (Sep 08, 2016)
* [CB-11795](https://issues.apache.org/jira/browse/CB-11795) Add 'protective' entry to cordovaDependencies
* Add intent scheme to be handled by OS
* Plugin uses `Android Log class` and not `Cordova LOG class`
* Adding links to guide content and reference content at the top of the readme file Github: close #163
* [CB-10973](https://issues.apache.org/jira/browse/CB-10973) **Browser**: wrong height of webview with `location=yes`
* Size and position in browser platform
* [CB-10973](https://issues.apache.org/jira/browse/CB-10973) **Windows**: wrong height of webview with `location=yes`
* [CB-11013](https://issues.apache.org/jira/browse/CB-11013) IAB enabling background play of YouTube videos?
* [CB-10467](https://issues.apache.org/jira/browse/CB-10467) Hardware back button, while `InAppBrowser` is opened, closes the app too in addition to closing `InAppBrowser`
* [CB-11178](https://issues.apache.org/jira/browse/CB-11178) allow to open other apps on **iOS 9**
* fix some calls which used api level 16
* [CB-5402](https://issues.apache.org/jira/browse/CB-5402) added extra content from wiki page
* [CB-2063](https://issues.apache.org/jira/browse/CB-2063) (**ios**) Fixed presentation style
* [CB-11012](https://issues.apache.org/jira/browse/CB-11012) added some clarifications about `InAppBrowser` object
* [CB-3360](https://issues.apache.org/jira/browse/CB-3360) Set custom `inappbrowser` user agent for **ios**
* Add badges for paramedic builds on Jenkins
* [CB-11381](https://issues.apache.org/jira/browse/CB-11381) android: Does not pass sonarqube scan
* Add pull request template.
* [CB-10866](https://issues.apache.org/jira/browse/CB-10866) Adding engine requirements to `package.json`
* [CB-110003](https://issues.apache.org/jira/browse/CB-110003) Adding samples to Readme.
* [CB-10996](https://issues.apache.org/jira/browse/CB-10996) Adding front matter to README.md
### 1.4.0 (Apr 15, 2016)
* CB-7679 add fix for **iOS** upload.
* CB-10944 `NoSuchMethodError` in `InAppBrowser` plugin
* CB-10937 fix stretched icons
* CB-10760 Fixing README for display on Cordova website
* CB-10636 Add `JSHint` for plugins
* [CB-7679](https://issues.apache.org/jira/browse/CB-7679) add fix for **iOS** upload.
* [CB-10944](https://issues.apache.org/jira/browse/CB-10944) `NoSuchMethodError` in `InAppBrowser` plugin
* [CB-10937](https://issues.apache.org/jira/browse/CB-10937) fix stretched icons
* [CB-10760](https://issues.apache.org/jira/browse/CB-10760) Fixing README for display on Cordova website
* [CB-10636](https://issues.apache.org/jira/browse/CB-10636) Add `JSHint` for plugins

@@ -53,4 +76,4 @@ ### 1.3.0 (Feb 09, 2016)

### 1.2.0 (Jan 15, 2016)
* CB-8180: Changing methods of interception in `WebViewClient` class
* CB-10009 Improve `InAppBrowser` toolbar look and feel on **Windows**
* [CB-8180](https://issues.apache.org/jira/browse/CB-8180) Changing methods of interception in `WebViewClient` class
* [CB-10009](https://issues.apache.org/jira/browse/CB-10009) Improve `InAppBrowser` toolbar look and feel on **Windows**
* Open a new window on the **Browser** platform

@@ -60,9 +83,9 @@

* CB-9445 Improves executeScript callbacks on iOS
* CB-10035 Incremented plugin version.
* CB-10040 - re-fix: backwards compatible with cordova-ios < 4.0
* CB-8534: Allow plugins to respond to onReceivedHttpAuthRequest. This closes #82
* CB-3750: Fixes spinner on iOS. This closes #89
* CB-7696 Document target=_self behavior for Windows
* CB-10040 - Compile Error in InAppBrowser Plugin for iOS - No known instance method for selector 'URLIsWhitelisted:'
* [CB-9445](https://issues.apache.org/jira/browse/CB-9445) Improves executeScript callbacks on iOS
* [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Incremented plugin version.
* [CB-10040](https://issues.apache.org/jira/browse/CB-10040) - re-fix: backwards compatible with cordova-ios < 4.0
* [CB-8534](https://issues.apache.org/jira/browse/CB-8534) Allow plugins to respond to onReceivedHttpAuthRequest. This closes #82
* [CB-3750](https://issues.apache.org/jira/browse/CB-3750) Fixes spinner on iOS. This closes #89
* [CB-7696](https://issues.apache.org/jira/browse/CB-7696) Document target=_self behavior for Windows
* [CB-10040](https://issues.apache.org/jira/browse/CB-10040) - Compile Error in InAppBrowser Plugin for iOS - No known instance method for selector 'URLIsWhitelisted:'

@@ -69,0 +92,0 @@ ### 1.1.0 (Nov 18, 2015)

@@ -80,5 +80,8 @@ /*

browserWrap.style.position = "absolute";
browserWrap.style.top = "0";
browserWrap.style.left = "0";
browserWrap.style.boxSizing = "border-box";
browserWrap.style.borderWidth = "40px";
browserWrap.style.width = "calc(100% - 80px)";
browserWrap.style.height = "calc(100% - 80px)";
browserWrap.style.width = "100vw";
browserWrap.style.height = "100vh";
browserWrap.style.borderStyle = "solid";

@@ -108,2 +111,3 @@ browserWrap.style.borderColor = "rgba(0,0,0,0.25)";

popup.style.height = "calc(100% - 60px)";
popup.style.marginBottom = "-4px";

@@ -110,0 +114,0 @@ navigationButtonsDiv = document.createElement("div");

@@ -36,3 +36,4 @@ /*

bodyOverflowStyle,
navigationEventsCallback;
navigationEventsCallback,
hardwareBackCallback;

@@ -109,2 +110,4 @@ // x-ms-webview is available starting from Windows 8.1 (platformId is 'windows')

popup = null;
document.removeEventListener("backbutton", hardwareBackCallback, false);
}

@@ -178,5 +181,41 @@ });

popup.style.width = "100%";
popup.style.marginBottom = "-3px";
browserWrap.appendChild(popup);
var closeHandler = function (e) {
setTimeout(function () {
IAB.close(navigationEventsCallback);
}, 0);
};
if (features.indexOf("hardwareback=yes") > -1 || features.indexOf("hardwareback") === -1) {
hardwareBackCallback = function () {
if (browserWrap.style.display === 'none') {
// NOTE: backbutton handlers have to throw an exception in order to prevent
// returning 'true' inside cordova-js, which would mean that the event is handled by user.
// Throwing an exception means that the default/system navigation behavior will take place,
// which is to exit the app if the navigation stack is empty.
throw 'Exit the app';
}
if (popup.canGoBack) {
popup.goBack();
} else {
closeHandler();
}
};
} else if (features.indexOf("hardwareback=no") > -1) {
hardwareBackCallback = function () {
if (browserWrap.style.display === 'none') {
// See comment above
throw 'Exit the app';
}
closeHandler();
};
}
document.addEventListener("backbutton", hardwareBackCallback, false);
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {

@@ -216,7 +255,3 @@ popup.style.height = "calc(100% - 70px)";

closeButton.className = "app-bar-action action-close";
closeButton.addEventListener("click", function (e) {
setTimeout(function () {
IAB.close(navigationEventsCallback);
}, 0);
});
closeButton.addEventListener("click", closeHandler);

@@ -223,0 +258,0 @@ if (!isWebViewAvailable) {

@@ -441,2 +441,10 @@ /*

var hardwareback_tests = '<h1>HardwareBack</h1>' +
'<p/> <div id="openHardwareBackDefault"></div>' +
'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' +
'<p/> <div id="openHardwareBackYes"></div>' +
'Expected result: hardwareback=yes pressing back button should navigate backwards in history then close InAppBrowser' +
'<p/> <div id="openHardwareBackNo"></div>' +
'Expected result: hardwareback=no pressing back button should close InAppBrowser regardless history';
// CB-7490 We need to wrap this code due to Windows security restrictions

@@ -447,7 +455,7 @@ // see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details

contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests;
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
});
} else {
contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests;
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
}

@@ -637,2 +645,13 @@

}, 'openAnchor2');
// Hardwareback
createActionButton('no hardwareback (defaults to yes)', function () {
doOpen('http://cordova.apache.org', '_blank');
}, 'openHardwareBackDefault');
createActionButton('hardwareback=yes', function () {
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=yes');
}, 'openHardwareBackYes');
createActionButton('hardwareback=no', function () {
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no');
}, 'openHardwareBackNo');
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc