initialxy / cordova-plugin-themeablebrowser

Fork of org.apache.cordova.inappbrowser in an attempt to make it a bit more themeable and configurable to add some custom actions.
Apache License 2.0
294 stars 221 forks source link

Ionic v3 webkit undefined #204

Open poohia opened 3 years ago

poohia commented 3 years ago

With InAppBrowser it's possible to use webkit.messageHandlers.cordova_iab.postMessage. But with ThemeableBrowser webkit is undefined

private options: ThemeableBrowserOptions = {
        statusbar: {
            color: "#ffffffff",
        },
        toolbar: {
            color: "#ffffffff",
            height: 44,
        },
        title: {
            color: "#ffffffff",
            showPageTitle: false,
        },
        backButton: {
            wwwImage: "assets/icon/arrow-back.png",
            align: "left",
            event: "backPressed",
        },
        closeButton: {
            wwwImage: "assets/icon/close.png",
            align: "right",
            event: "closePressed",
        },
        backButtonCanClose: false,
        hidden: true,
    };

const browserSSO: ThemeableBrowserObject = this.themeableBrowser.create(
            this.currentPage,
            "_blank",
            this.options
        );

browserSSO.on("loadstop").subscribe(() => {
            if (browserSSO != undefined) {
                browserSSO.executeScript({
                    code: "\
                     var message = 'this is the message';\
                     var messageObj = {my_message: message};\
                     var stringifiedMessageObj = JSON.stringify(messageObj);\
                     webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj);",
                });

                browserSSO.show();
            }
        });

browserSSO.on("message").subscribe(e => {
           alert("message received");
});