web-view icon indicating copy to clipboard operation
web-view copied to clipboard

No `external` in Ubuntu 20.04 applications

Open SomeoneToIgnore opened this issue 4 years ago • 5 comments

I've cloned this repo, navigated into webview-examples and run cargo run --example todo.

Expected: TODO app runs and works Actual: app starts, but no UI elements are displayed in the app

Seems like there's no external (window.external) object in the page: image

On the other hand, minimal example works just fine, displaying a Wiki page. Also both examples work on macOS and Windows for me.

I'm using stock Ubuntu with a few packages installed to successfully compile the examples.

lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal

Is there any way to fix it or at least do debug it further?

SomeoneToIgnore avatar May 25 '21 07:05 SomeoneToIgnore

Looks like it's available in window.webkit.messageHandlers.external.postMessage on this platform, so can be workarounded. But still weird to not to see it available as window.external there too.

SomeoneToIgnore avatar Jun 02 '21 10:06 SomeoneToIgnore

This must be the same issue I'm running into https://github.com/Boscop/web-view/issues/296

randall-coding avatar Jul 13 '21 02:07 randall-coding

I wonder if you can help me understand what the implication of this is. Does this mean the Ubuntu 20.04 version of the app should be coded differently? Or is there a way to check and use window.external only when it is available?

randall-coding avatar Jul 13 '21 04:07 randall-coding

the same issue

Indeed looks like the same issue. What if we close a less detailed one as a duplicate?

Does this mean the Ubuntu 20.04 version of the app should be coded differently?

A bit, yes. I've used this function as a workaround and it worked fine for me on both macOs and Ubuntu:

function sendMessageToServer(cmd) {
    if (window.external !== undefined) {
        return window.external.invoke(cmd);
    } else if (window.webkit.messageHandlers.external !== undefined) {
        return window.webkit.messageHandlers.external.postMessage(cmd);
    }
    throw new Error('Failed to locate webkit external handler')
}

SomeoneToIgnore avatar Jul 13 '21 10:07 SomeoneToIgnore

the same issue

Indeed looks like the same issue. What if we close a less detailed one as a duplicate?

Does this mean the Ubuntu 20.04 version of the app should be coded differently?

A bit, yes. I've used this function as a workaround and it worked fine for me on both macOs and Ubuntu:

function sendMessageToServer(cmd) {
    if (window.external !== undefined) {
        return window.external.invoke(cmd);
    } else if (window.webkit.messageHandlers.external !== undefined) {
        return window.webkit.messageHandlers.external.postMessage(cmd);
    }
    throw new Error('Failed to locate webkit external handler')
}

Sure thing. Thanks a lot!

randall-coding avatar Jul 14 '21 22:07 randall-coding