Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What does it mean to Photino that window.external is deprecated by browsers? #124

Open
raddevus opened this issue Feb 17, 2023 · 5 comments
Labels
All OS enhancement New feature or request

Comments

@raddevus
Copy link

Just discovered that window.external is being deprecated by browsers.
You can see the deprecation warning on the MDN at: https://developer.mozilla.org/en-US/docs/Web/API/Window/external

What will this mean for Photino.NET moving forward?

@vvollers
Copy link

I doubt it will mean much since the window.external object is being initialized/created by Photino itself. In the end it is a wrapper around window.chrome.webview.postMessage (Windows/Webview2), window.webkit.messageHandlers.Photinointerop (a custom handler, Linux/WebkitGTK) and window.webkit.messageHandlers.photinointerop (Mac/Webkit).

see for example (windows) https://github.com/tryphotino/photino.Native/blob/24be1c50d3dcb4c92c33a0081160ecc10959553c/Photino.Native/Photino.Windows.cpp#L751

window.external = {
    sendMessage: function(message) {
        window.chrome.webview.postMessage(message);
    },
    receiveMessage: function(callback) {
        window.chrome.webview.addEventListener('message', function(e) {
            callback(e.data);
        });
    }
};

The initialization is a raw declaration of a new object, regardless if 'window.external' already existed, which javascript allows (try overwriting console.log with a new function sometime). So the deprecation of a mechanism which wasn't used doesn't affect the project I think.

@raddevus
Copy link
Author

That is excellent info and great news. thanks for pointing out that this is actually a wrapper around those other (supported) methods.

@raddevus
Copy link
Author

Closed since window.external is a Photino wrapper around the proper code.

@MikeYeager
Copy link
Collaborator

Going forward, we may need to implement this on a platform-by-platform basis.

WebView2 (Windows): https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.addhostobjecttoscript?view=webview2-dotnet-1.0.2151.40#Microsoft_Web_WebView2_Core_CoreWebView2_AddHostObjectToScript_System_String_System_Object

WebKitGTK (Linux): maybe this? https://webkitgtk.org/reference/webkit2gtk/stable/method.WebView.run_javascript.html

WebKit (Mac): maybe this? https://stackoverflow.com/questions/62035494/how-to-call-postmessage-in-wkwebview-to-js

For now, to get around TypeScript compile errors you can do a work-around like (myObject as any).myMethod() or myObject.myMethod?.()

@MikeYeager MikeYeager reopened this Nov 30, 2023
@stevesobol
Copy link

stevesobol commented Nov 30, 2023

That would work.

I played around a bit and discovered // @ts-ignore works too. The code runs, it just won't transpile because it isn't valid TypeScript.

We should look into the options you talked about, but I think there will still be an issue with TypeScript. This may not be a problem that requires us to make changes. I'm not sure.

@MikeYeager MikeYeager added enhancement New feature or request All OS labels Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
All OS enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants