Neon Papier Mâché

    cordova-plugin-wkuserscript
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    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-wkuserscript

    Methods

    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.
    });

    Install

    npm i cordova-plugin-wkuserscript

    DownloadsWeekly Downloads

    656

    Version

    1.0.1

    License

    Apache-2.0

    Unpacked Size

    23.5 kB

    Total Files

    8

    Last publish

    Collaborators

    • alfonso-salces
    • dpalou
    • moodlepty
    • andrewnicols
    • noeldemartin