MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem/Bug]: variable being redeclared when a preload script loads in an iframe in google.com
@JosephJin0815 is already working on this.
Since Nov 22, 2024.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
Maybe this is more an issue with the google site, but I couldn't reproduce this in my Electron app when I have it inject a preload script into iframes.
In WebView2, if I set a preload script that declares a variable, when I open a window to google.com and search for things that result in iframes being loaded (e.g. "erg"), I get crashes like this:
Uncaught SyntaxError: Identifier 'aVar' has already been declared
Importance
Moderate. My app's user experience is affected, but still usable.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
130.0.3849.80
SDK Version
1.0.2535.41
Framework
Winforms
Operating System
Windows 11
OS Version
22631.4317
Repro steps
- download the WinForms WebView2 sample app
- intercept the newwindowrequested event:
in WebView2Control_CoreWebView2InitializationCompleted, add this.webView2Control.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
in that handler add:
private async void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
{
e.Handled = true;
using (e.GetDeferral())
{
Form form = new Form();
WebView2 webView = new WebView2();
await webView.EnsureCoreWebView2Async();
form.Controls.Add(webView);
await webView.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("let aVar = 0; console.log(aVar);");
form.Visible = true;
webView.Dock = DockStyle.Fill;
e.NewWindow = webView.CoreWebView2;
}
}
- start the app, open devtools and run
window.open("https://google.com") - open devtools for the google window
- search "erg"
- see the errors in devtools
Interestingly, replacing let with var makes it work. const fails just like let.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
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.