cordova-plugin-inappbrowser
Advanced tools
Comparing version 3.0.0 to 3.1.0
{ | ||
"name": "cordova-plugin-inappbrowser", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Cordova InAppBrowser Plugin", | ||
@@ -21,3 +21,3 @@ "types": "./types/index.d.ts", | ||
"bugs": { | ||
"url": "https://issues.apache.org/jira/browse/CB" | ||
"url": "https://github.com/apache/cordova-plugin-inappbrowser/issues" | ||
}, | ||
@@ -24,0 +24,0 @@ "keywords": [ |
@@ -38,2 +38,4 @@ --- | ||
### `window.open` | ||
The `cordova.InAppBrowser.open()` function is defined to be a drop-in replacement | ||
@@ -70,6 +72,2 @@ for the `window.open()` function. Existing `window.open()` calls can use the | ||
Report issues with this plugin on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22cordova-plugin-inappbrowser%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC) | ||
## <a id="reference">Reference</a> | ||
## Installation | ||
@@ -115,2 +113,3 @@ | ||
- __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 | ||
@@ -130,2 +129,3 @@ - __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened | ||
- __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 left and close button to the right. | ||
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. | ||
@@ -138,5 +138,8 @@ - __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). | ||
- __usewkwebview__: set to `yes` to use WKWebView engine for the InappBrowser. Omit or set to `no` (default) to use UIWebView. Note: Using `usewkwebview=yes` requires that a WKWebView engine plugin be installed in the Cordova project (e.g. [cordova-plugin-wkwebview-engine](https://github.com/apache/cordova-plugin-wkwebview-engine) or [cordova-plugin-ionic-webview](https://github.com/ionic-team/cordova-plugin-ionic-webview)). | ||
- __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 | ||
- __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. | ||
@@ -150,7 +153,8 @@ - __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself. | ||
- __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled. | ||
- __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`) | ||
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). | ||
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). | ||
- __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`). Only applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`) on iOS 10+. | ||
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`). | ||
- __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`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`). | ||
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). Only applicable to UIWebView (`usewkwebview=no`). | ||
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`). | ||
- __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle) (defaults to `fullscreen`). | ||
@@ -221,2 +225,4 @@ - __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle) (defaults to `coververtical`). | ||
- __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. | ||
@@ -235,3 +241,3 @@ - __callback__: the function that executes when the event fires. The function is passed an `InAppBrowserEvent` object as a parameter. | ||
var options = "location=yes,hidden=yes"; | ||
var options = "location=yes,hidden=yes,beforeload=yes"; | ||
@@ -246,2 +252,5 @@ inAppBrowserRef = cordova.InAppBrowser.open(url, target, options); | ||
inAppBrowserRef.addEventListener('beforeload', beforeloadCallBack); | ||
inAppBrowserRef.addEventListener('message', messageCallBack); | ||
} | ||
@@ -261,2 +270,9 @@ | ||
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(""); | ||
@@ -296,2 +312,20 @@ | ||
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); | ||
} | ||
``` | ||
@@ -301,3 +335,3 @@ | ||
- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, or `exit`. _(String)_ | ||
- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, `message` or `exit`. _(String)_ | ||
@@ -310,3 +344,5 @@ - __url__: the URL that was loaded. _(String)_ | ||
- __data__: the message contents , only in the case of `message`. A stringified JSON object. _(String)_ | ||
### Supported Platforms | ||
@@ -322,4 +358,8 @@ | ||
`loadstart` and `loaderror` events are not being fired. | ||
`loadstart`, `loaderror`, `message` events are not fired. | ||
### Windows Quirks | ||
`message` event is not fired. | ||
### Quick Example | ||
@@ -344,2 +384,3 @@ | ||
- __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. | ||
@@ -346,0 +387,0 @@ - __callback__: the function to execute when the event fires. |
{ | ||
"name": "cordova-plugin-inappbrowser-tests", | ||
"version": "1.7.1-dev", | ||
"version": "3.1.0", | ||
"description": "", | ||
@@ -13,3 +13,3 @@ "cordova": { | ||
"author": "", | ||
"license": "Apache 2.0" | ||
"license": "Apache-2.0" | ||
} |
@@ -26,2 +26,4 @@ /* | ||
var isWindows = cordova.platformId === 'windows'; | ||
var isIos = cordova.platformId === 'ios'; | ||
var isAndroid = cordova.platformId === 'android'; | ||
var isBrowser = cordova.platformId === 'browser'; | ||
@@ -36,119 +38,156 @@ | ||
exports.defineAutoTests = function () { | ||
var createTests = function (platformOpts) { | ||
platformOpts = platformOpts || ''; | ||
describe('cordova.InAppBrowser', function () { | ||
describe('cordova.InAppBrowser', function () { | ||
it('inappbrowser.spec.1 should exist', function () { | ||
expect(cordova.InAppBrowser).toBeDefined(); | ||
}); | ||
it('inappbrowser.spec.1 should exist', function () { | ||
expect(cordova.InAppBrowser).toBeDefined(); | ||
}); | ||
it('inappbrowser.spec.2 should contain open function', function () { | ||
expect(cordova.InAppBrowser.open).toBeDefined(); | ||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function)); | ||
it('inappbrowser.spec.2 should contain open function', function () { | ||
expect(cordova.InAppBrowser.open).toBeDefined(); | ||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function)); | ||
}); | ||
}); | ||
}); | ||
describe('open method', function () { | ||
describe('open method', function () { | ||
if (cordova.platformId === 'osx') { | ||
pending('Open method not fully supported on OSX.'); | ||
return; | ||
} | ||
if (cordova.platformId === 'osx') { | ||
pending('Open method not fully supported on OSX.'); | ||
return; | ||
} | ||
var iabInstance; | ||
var originalTimeout; | ||
var url = 'https://dist.apache.org/repos/dist/dev/cordova/'; | ||
var badUrl = 'http://bad-uri/'; | ||
var iabInstance; | ||
var originalTimeout; | ||
var url = 'https://dist.apache.org/repos/dist/dev/cordova/'; | ||
var badUrl = 'http://bad-uri/'; | ||
beforeEach(function () { | ||
beforeEach(function () { | ||
// increase timeout to ensure test url could be loaded within test time | ||
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; | ||
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; | ||
iabInstance = null; | ||
}); | ||
iabInstance = null; | ||
}); | ||
afterEach(function (done) { | ||
afterEach(function (done) { | ||
// restore original timeout | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; | ||
if (iabInstance !== null && iabInstance.close) { | ||
iabInstance.close(); | ||
if (iabInstance !== null && iabInstance.close) { | ||
iabInstance.close(); | ||
} | ||
iabInstance = null; | ||
// add some extra time so that iab dialog is closed | ||
setTimeout(done, 2000); | ||
}); | ||
function verifyEvent (evt, type) { | ||
expect(evt).toBeDefined(); | ||
expect(evt.type).toEqual(type); | ||
// `exit` event does not have url field, browser returns null url for CORS requests | ||
if (type !== 'exit' && !isBrowser) { | ||
expect(evt.url).toEqual(url); | ||
} | ||
} | ||
iabInstance = null; | ||
// add some extra time so that iab dialog is closed | ||
setTimeout(done, 2000); | ||
}); | ||
function verifyEvent (evt, type) { | ||
expect(evt).toBeDefined(); | ||
expect(evt.type).toEqual(type); | ||
// `exit` event does not have url field, browser returns null url for CORS requests | ||
if (type !== 'exit' && !isBrowser) { | ||
expect(evt.url).toEqual(url); | ||
function verifyLoadErrorEvent (evt) { | ||
expect(evt).toBeDefined(); | ||
expect(evt.type).toEqual('loaderror'); | ||
expect(evt.url).toEqual(badUrl); | ||
expect(evt.code).toEqual(jasmine.any(Number)); | ||
expect(evt.message).toEqual(jasmine.any(String)); | ||
} | ||
} | ||
function verifyLoadErrorEvent (evt) { | ||
expect(evt).toBeDefined(); | ||
expect(evt.type).toEqual('loaderror'); | ||
expect(evt.url).toEqual(badUrl); | ||
expect(evt.code).toEqual(jasmine.any(Number)); | ||
expect(evt.message).toEqual(jasmine.any(String)); | ||
} | ||
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () { | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts); | ||
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () { | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank'); | ||
expect(iabInstance).toBeDefined(); | ||
expect(iabInstance).toBeDefined(); | ||
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.close).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.show).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.hide).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.executeScript).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function)); | ||
}); | ||
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.close).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.show).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.hide).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.executeScript).toEqual(jasmine.any(Function)); | ||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function)); | ||
}); | ||
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) { | ||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) { | ||
verifyEvent(evt, 'loadstart'); | ||
}); | ||
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) { | ||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) { | ||
verifyEvent(evt, 'loadstart'); | ||
}); | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank'); | ||
iabInstance.addEventListener('loadstart', onLoadStart); | ||
iabInstance.addEventListener('loadstop', function (evt) { | ||
verifyEvent(evt, 'loadstop'); | ||
if (!isBrowser) { | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts); | ||
iabInstance.addEventListener('loadstart', onLoadStart); | ||
iabInstance.addEventListener('loadstop', function (evt) { | ||
verifyEvent(evt, 'loadstop'); | ||
if (!isBrowser) { | ||
// according to documentation, "loadstart" event is not supported on browser | ||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1 | ||
expect(onLoadStart).toHaveBeenCalled(); | ||
} | ||
done(); | ||
expect(onLoadStart).toHaveBeenCalled(); | ||
} | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('inappbrowser.spec.5 should support exit event', function (done) { | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank'); | ||
iabInstance.addEventListener('exit', function (evt) { | ||
verifyEvent(evt, 'exit'); | ||
done(); | ||
it('inappbrowser.spec.5 should support exit event', function (done) { | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts); | ||
iabInstance.addEventListener('exit', function (evt) { | ||
verifyEvent(evt, 'exit'); | ||
done(); | ||
}); | ||
iabInstance.addEventListener('loadstop', function (evt) { | ||
iabInstance.close(); | ||
iabInstance = null; | ||
}); | ||
}); | ||
iabInstance.close(); | ||
iabInstance = null; | ||
}); | ||
it('inappbrowser.spec.6 should support loaderror event', function (done) { | ||
if (isBrowser) { | ||
it('inappbrowser.spec.6 should support loaderror event', function (done) { | ||
if (isBrowser) { | ||
// according to documentation, "loaderror" event is not supported on browser | ||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1 | ||
pending('Browser platform doesn\'t support loaderror event'); | ||
} | ||
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank'); | ||
iabInstance.addEventListener('loaderror', function (evt) { | ||
verifyLoadErrorEvent(evt); | ||
done(); | ||
pending('Browser platform doesn\'t support loaderror event'); | ||
} | ||
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts); | ||
iabInstance.addEventListener('loaderror', function (evt) { | ||
verifyLoadErrorEvent(evt); | ||
done(); | ||
}); | ||
}); | ||
it('inappbrowser.spec.7 should support message event', function (done) { | ||
if (!isAndroid && !isIos) { | ||
return pending(cordova.platformId + ' platform doesn\'t support message event'); | ||
} | ||
var messageKey = 'my_message'; | ||
var messageValue = 'is_this'; | ||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts); | ||
iabInstance.addEventListener('message', function (evt) { | ||
// Verify message event | ||
expect(evt).toBeDefined(); | ||
expect(evt.type).toEqual('message'); | ||
expect(evt.data).toBeDefined(); | ||
expect(evt.data[messageKey]).toBeDefined(); | ||
expect(evt.data[messageKey]).toEqual(messageValue); | ||
done(); | ||
}); | ||
iabInstance.addEventListener('loadstop', function (evt) { | ||
var code = '(function(){\n' + | ||
' var message = {' + messageKey + ': "' + messageValue + '"};\n' + | ||
' webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));\n' + | ||
'})()'; | ||
iabInstance.executeScript({ code: code }); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
if (isIos) { | ||
createTests('usewkwebview=no'); | ||
createTests('usewkwebview=yes'); | ||
} else { | ||
createTests(); | ||
} | ||
}; | ||
@@ -158,2 +197,11 @@ | ||
var platformOpts = ''; | ||
var platform_info = ''; | ||
if (isIos) { | ||
platformOpts = 'usewkwebview=no'; | ||
platform_info = '<h1>Webview</h1>' + | ||
'<p>Use this button to toggle the Webview implementation.</p>' + | ||
'<div id="webviewToggle"></div>'; | ||
} | ||
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) { | ||
@@ -189,2 +237,5 @@ numExpectedRedirects = numExpectedRedirects || 0; | ||
} else { | ||
if (platformOpts) { | ||
params += (params ? ',' : '') + platformOpts; | ||
} | ||
iab = cordova.InAppBrowser.open(url, target, params, callbacks); | ||
@@ -312,2 +363,5 @@ } | ||
var shopt = (startHidden) ? 'hidden=yes' : ''; | ||
if (platformOpts) { | ||
shopt += (shopt ? ',' : '') + platformOpts; | ||
} | ||
hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt); | ||
@@ -479,7 +533,7 @@ if (!hiddenwnd) { | ||
MSApp.execUnsafeLocalFunction(function () { | ||
contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests + | ||
contentEl.innerHTML = info_div + platform_info + 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 + 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 + | ||
contentEl.innerHTML = info_div + platform_info + 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 + hardwareback_tests; | ||
@@ -498,2 +552,16 @@ } | ||
var videohtml = basePath + 'video.html'; | ||
if (isIos) { | ||
createActionButton('Webview=UIWebView', function () { | ||
var webviewOption = 'usewkwebview='; | ||
var webviewToggle = document.getElementById('webviewToggle'); | ||
var button = webviewToggle.getElementsByClassName('topcoat-button')[0]; | ||
if (platformOpts === webviewOption + 'yes') { | ||
platformOpts = webviewOption + 'no'; | ||
button.textContent = 'Webview=UIWebView'; | ||
} else { | ||
platformOpts = webviewOption + 'yes'; | ||
button.textContent = 'Webview=WKWebView'; | ||
} | ||
}, 'webviewToggle'); | ||
} | ||
@@ -689,3 +757,3 @@ // Local | ||
createActionButton('no hardwareback -> hardwareback=no -> no hardwareback', function () { | ||
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes'); | ||
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : '')); | ||
ref.addEventListener('loadstop', function () { | ||
@@ -695,3 +763,3 @@ ref.close(); | ||
ref.addEventListener('exit', function () { | ||
var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no'); | ||
var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no' + (platformOpts ? ',' + platformOpts : '')); | ||
ref2.addEventListener('loadstop', function () { | ||
@@ -701,3 +769,3 @@ ref2.close(); | ||
ref2.addEventListener('exit', function () { | ||
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes'); | ||
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : '')); | ||
}); | ||
@@ -704,0 +772,0 @@ }); |
@@ -5,5 +5,7 @@ // Type definitions for Apache Cordova InAppBrowser plugin | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// | ||
// | ||
// Copyright (c) Microsoft Open Technologies Inc | ||
// Licensed under the MIT license. | ||
// TypeScript Version: 2.3 | ||
type channel = "loadstart" | "loadstop" | "loaderror" | "exit" | "message"; | ||
@@ -19,30 +21,3 @@ interface Window { | ||
*/ | ||
open(url: string, target?: "_self", options?: string): InAppBrowser; | ||
/** | ||
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser. | ||
* @param url The URL to load. | ||
* @param target The target in which to load the URL, an optional parameter that defaults to _self. | ||
* @param options Options for the InAppBrowser. Optional, defaulting to: location=yes. | ||
* 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. | ||
*/ | ||
open(url: string, target?: "_blank", options?: string): InAppBrowser; | ||
/** | ||
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser. | ||
* @param url The URL to load. | ||
* @param target The target in which to load the URL, an optional parameter that defaults to _self. | ||
* @param options Options for the InAppBrowser. Optional, defaulting to: location=yes. | ||
* 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. | ||
*/ | ||
open(url: string, target?: "_system", options?: string): InAppBrowser; | ||
/** | ||
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser. | ||
* @param url The URL to load. | ||
* @param target The target in which to load the URL, an optional parameter that defaults to _self. | ||
* @param options Options for the InAppBrowser. Optional, defaulting to: location=yes. | ||
* 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. | ||
*/ | ||
open(url: string, target?: string, options?: string, replace?: boolean): InAppBrowser; | ||
open(url: string, target?: string, options?: string): InAppBrowser; | ||
} | ||
@@ -55,11 +30,10 @@ | ||
interface InAppBrowser extends Window { | ||
onloadstart: (type: InAppBrowserEvent) => void; | ||
onloadstop: (type: InAppBrowserEvent) => void; | ||
onloaderror: (type: InAppBrowserEvent) => void; | ||
onexit: (type: InAppBrowserEvent) => void; | ||
onloadstart(type: Event): void; | ||
onloadstop(type: InAppBrowserEvent): void; | ||
onloaderror(type: InAppBrowserEvent): void; | ||
onexit(type: InAppBrowserEvent): void; | ||
// addEventListener overloads | ||
/** | ||
* Adds a listener for an event from the InAppBrowser. | ||
* @param type the event to listen for | ||
* loadstart: event fires when the InAppBrowser starts to load a URL. | ||
* @param type loadstart: event fires when the InAppBrowser starts to load a URL. | ||
* loadstop: event fires when the InAppBrowser finishes loading a URL. | ||
@@ -71,47 +45,3 @@ * loaderror: event fires when the InAppBrowser encounters an error when loading a URL. | ||
*/ | ||
addEventListener(type: "loadstart", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Adds a listener for an event from the InAppBrowser. | ||
* @param type the event to listen for | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an InAppBrowserEvent object as a parameter. | ||
*/ | ||
addEventListener(type: "loadstop", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Adds a listener for an event from the InAppBrowser. | ||
* @param type the event to listen for | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an InAppBrowserEvent object as a parameter. | ||
*/ | ||
addEventListener(type: "loaderror", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Adds a listener for an event from the InAppBrowser. | ||
* @param type the event to listen for | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an InAppBrowserEvent object as a parameter. | ||
*/ | ||
addEventListener(type: "exit", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Adds a listener for an event from the InAppBrowser. | ||
* @param type the event to listen for | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an Event object as a parameter. | ||
*/ | ||
addEventListener(type: string, callback: (event: Event) => void): void; | ||
addEventListener(type: channel, callback: InAppBrowserEventListenerOrEventListenerObject): void; | ||
// removeEventListener overloads | ||
@@ -128,47 +58,3 @@ /** | ||
*/ | ||
removeEventListener(type: "loadstart", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Removes a listener for an event from the InAppBrowser. | ||
* @param type The event to stop listening for. | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an InAppBrowserEvent object as a parameter. | ||
*/ | ||
removeEventListener(type: "loadstop", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Removes a listener for an event from the InAppBrowser. | ||
* @param type The event to stop listening for. | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an InAppBrowserEvent object as a parameter. | ||
*/ | ||
removeEventListener(type: "loaderror", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Removes a listener for an event from the InAppBrowser. | ||
* @param type The event to stop listening for. | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an InAppBrowserEvent object as a parameter. | ||
*/ | ||
removeEventListener(type: "exit", callback: (event: InAppBrowserEvent) => void): void; | ||
/** | ||
* Removes a listener for an event from the InAppBrowser. | ||
* @param type The event to stop listening for. | ||
* 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. | ||
* @param callback the function that executes when the event fires. The function is | ||
* passed an Event object as a parameter. | ||
*/ | ||
removeEventListener(type: string, callback: (event: Event) => void): void; | ||
removeEventListener(type: channel, callback: InAppBrowserEventListenerOrEventListenerObject): void; | ||
/** Closes the InAppBrowser window. */ | ||
@@ -192,14 +78,4 @@ close(): void; | ||
*/ | ||
executeScript(script: { code: string }, callback: (result: any) => void): void; | ||
executeScript(script: { code: string } | { file: string }, callback: (result: any) => void): void; | ||
/** | ||
* Injects JavaScript code into the InAppBrowser window. | ||
* @param script Details of the script to run, specifying either a file or code key. | ||
* @param 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. | ||
*/ | ||
executeScript(script: { file: string }, callback: (result: any) => void): void; | ||
/** | ||
* Injects CSS into the InAppBrowser window. | ||
@@ -209,11 +85,13 @@ * @param css Details of the script to run, specifying either a file or code key. | ||
*/ | ||
insertCSS(css: { code: string }, callback: () => void): void; | ||
/** | ||
* Injects CSS into the InAppBrowser window. | ||
* @param css Details of the script to run, specifying either a file or code key. | ||
* @param callback The function that executes after the CSS is injected. | ||
*/ | ||
insertCSS(css: { file: string }, callback: () => void): void; | ||
insertCSS(css: { code: string } | { file: string }, callback: () => void): void; | ||
} | ||
type InAppBrowserEventListenerOrEventListenerObject = InAppBrowserEventListener | InAppBrowserEventListenerObject; | ||
type InAppBrowserEventListener = (evt: InAppBrowserEvent) => void; | ||
interface InAppBrowserEventListenerObject { | ||
handleEvent(evt: InAppBrowserEvent): void; | ||
} | ||
interface InAppBrowserEvent extends Event { | ||
@@ -228,2 +106,6 @@ /** the eventname, either loadstart, loadstop, loaderror, or exit. */ | ||
message: string; | ||
} | ||
} | ||
interface Cordova { | ||
InAppBrowser: InAppBrowser; | ||
} |
@@ -36,2 +36,3 @@ /* | ||
this.channels = { | ||
'beforeload': channel.create('beforeload'), | ||
'loadstart': channel.create('loadstart'), | ||
@@ -41,3 +42,4 @@ 'loadstop': channel.create('loadstop'), | ||
'exit': channel.create('exit'), | ||
'customscheme': channel.create('customscheme') | ||
'customscheme': channel.create('customscheme'), | ||
'message': channel.create('message') | ||
}; | ||
@@ -49,5 +51,13 @@ } | ||
if (event && (event.type in this.channels)) { | ||
this.channels[event.type].fire(event); | ||
if (event.type === 'beforeload') { | ||
this.channels[event.type].fire(event, this._loadAfterBeforeload); | ||
} else { | ||
this.channels[event.type].fire(event); | ||
} | ||
} | ||
}, | ||
_loadAfterBeforeload: function (strUrl) { | ||
strUrl = urlutil.makeAbsolute(strUrl); | ||
exec(null, null, 'InAppBrowser', 'loadAfterBeforeload', [strUrl]); | ||
}, | ||
close: function (eventname) { | ||
@@ -54,0 +64,0 @@ exec(null, null, 'InAppBrowser', 'close', []); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
718
429004
50
1588
1