MicrosoftEdge / MicrosoftEdge/WebView2Samples
Javascript bridge window.external.notify
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1k
- Forks
- 521
- Avg merge
- 13m
- Merged PRs (30d)
- 1
Description
Add a sample demonstrating best practice to communicate events between the host and javascript both ways.
An messaging abstraction would benefit the WebView2 spec. There is a supported 'WebMessageReceived' API but is only from Host originated events which await a JS response.
The WebView2_spec says: "WebMessageReceived – Occurs when the content contained in the WebView2 control passes a string to the application by using JavaScipt."
a sample showing how to send messages from JavaScript to the Native application hosting the WebView would be very useful.
"Win32 WebViewControl did not support ObjectForScripting or AddWebAllowedObject", @rjmurillo made a fine example of a necessary workaround to create a Javascript to Natvie notification 'JavaScriptBridge'.
It's basis was :
window.external.notify(event.data);
The browser MDN web docs on Window.external say it is deprecated. What would be the Chrome equivalent?
An iOS Safari webView compatible example:
https://github.com/lovesunstar/WKBridge/blob/fb30c123e68b4dcd4c4a2a8087d7383dbac0afe9/Example/WKBridge/test.html
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the WebView2_spec WebMessageReceived section and the referenced JavaScriptBridge/Bridge.html example, then inspect the repository for an existing WebView2 sample entry point. Define a supported sample that demonstrates host-to-JavaScript and JavaScript-to-native event communication, with completion verified by both directions working without relying on the deprecated window.external API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript
- Domain
- api, desktop
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100