MicrosoftEdge / MicrosoftEdge/WebView2Feedback
certain flavor of prototype.js can break web message functionality
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Description
Native - JS web messaging is broken on some sites utilizing prototype.js.
Version
SDK: 1.0.1418.22
Runtime: 107.0.1418.62
Framework: WPF
OS: Win10
Repro Steps
I ran into the issue while I was visiting our Jenkins site, but I managed to narrow down the issue and make it reproducible.
-
Get the Jenkins flavor of prototype.js
-
Inject the following code - make sure to do it before starting navigation:
webView2.CoreWebView2.WebMessageReceived += WebMessageReceived; // Downloaded from: https://raw.githubusercontent.com/jenkinsci/jenkins/master/war/src/main/webapp/scripts/prototype.js var prototypeJS = File.ReadAllText(@"prototype.js"); await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync(prototypeJS); await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.chrome.webview.postMessage([{\"age\": 21}, {\"age\": 23}]);"); private void WebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs e) { var message = e.WebMessageAsJson; try { var info = System.Text.Json.JsonSerializer.Deserialize<Info[]>(message); Debug.WriteLine(info); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } public class Info { [JsonPropertyName("age")] public int Age { get; set; } }``` -
Start the browser - it won't be able to deserialize the web message
Notes:
- The issue can only be reproduced with arrays
- See the diff between the official prototype.js and Jenkins flavor of prototype.js.
E.g. see the change in the Array.prototype:
function toJSON() {
var results = [];
this.each(function(object) {
var value = Object.toJSON(object);
if (value !== undefined) results.push(value);
});
return '[' + results.join(', ') + ']';
}
- This issue might happen with any sites overriding certain prototypes
- When prototype.js is injected into the page the
e.WebMessageAsJsonlooks like this (BAD version):
"\"[{\\\"age\\\": 21}, {\\\"age\\\": 23}]\""
- When prototype.js is NOT injected into the page,
e.WebMessageAsJsonlooks like this (GOOD version):
"[{\"age\":21},{\"age\":23}]"
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.
Assessment
This issue has not been assessed yet.