Boscop / web-view

Rust bindings for webview, a tiny cross-platform library to render web-based GUIs for desktop applications
MIT License
1.92k stars 175 forks source link

No `external` in Ubuntu 20.04 applications #289

Open SomeoneToIgnore opened 3 years ago

SomeoneToIgnore commented 3 years ago

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 commented 3 years ago

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.

randall-coding commented 3 years ago

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

randall-coding commented 3 years ago

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?

SomeoneToIgnore commented 3 years ago

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')
}
randall-coding commented 3 years ago

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!