1.0.1 • Published 4 years ago
cordova-plugin-wkuserscript v1.0.1
title: WKUserScript
description: Plugin to add WKUserScripts in WKWebView (iOS).
cordova-plugin-wkuserscript
Plugin to add WKUserScripts in WKWebView (iOS). This can be used to inject JS code to all iframes of your app, for example to intercept window.open calls.
Please notice that this plugin requires you to use WKWebView.
Installation
You can install the plugin using the following command:
cordova plugin add cordova-plugin-wkuserscriptMethods
This plugin defines global WKUserScript object.
Although in the global scope, it is not available until after the deviceready event.
function onDeviceReady() {
console.log(WKUserScript);
}
document.addEventListener("deviceready", onDeviceReady, false);WKUserScript.addScript
Adds a user script that will be injected to all iframes of the app (and also to the WebView, be careful with that). You can either pass the JS code to inject or the path of a JS script to inject.
Supported Platforms
- iOS 11+
Quick Example
WKUserScript.addScript({
code: 'window.myGlobalVar = "Test";',
}).then(function() {
// Success.
}).catch(function() {
// Error.
});