You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I handle a window.open and create a Form with a certain size, outerHeight incorrectly matches innerHeight and outerWidth matches innerWidth
This doesn't happen if I don't intercept NewWindowRequested and let WebView create the window for me. In that case, if I call window.open(url, name, "width=500,height=500"), outerHeight is 570 and innerHeight is 500.
If I intercept the event and create my own Form with the size passed to window.open, both outerHeight and innerHeight are 461 (where 461 is actually the inner height [based on what the value is in my Electron app])
And both outerWidth and innerWidth are 484.
In my Electron app, the inner height and width are 461 and 484, respectively, but the outer height and width match what I passed into window.open.
It seems like in WebView2, the inner bounds gets set to what was passed into window.open (when intercepting NewWindowRequested or not).
And in the case of intercepting the event and creating my own Form, the outer bounds matches the inner bounds.
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
128.0.2739.67
SDK Version
1.0.2535.41
Framework
Winforms
Operating System
Windows 11
OS Version
22631.4169
Repro steps
run the code below
click Show Form which opens a window with bounds 500,500
open devtools for that window and log outerHeight and innerHeight to see that they match
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.WinForms;
namespace WebView2LostDeferral
{
public partial class Form1 : Form
{
private CoreWebView2Environment? _webView2Environment;
public Form1()
{
InitializeComponent();
}
private async void Form1_Load(object sender, EventArgs e)
{
_webView2Environment = await CoreWebView2Environment.CreateAsync(null);
await webView21.EnsureCoreWebView2Async(_webView2Environment, _webView2Environment.CreateCoreWebView2ControllerOptions());
webView21.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
webView21.CoreWebView2.Navigate("https://www.msn.com");
}
private async void CoreWebView2_NewWindowRequested(object? sender, CoreWebView2NewWindowRequestedEventArgs e)
{
e.Handled = true;
Form secondForm = new()
{
StartPosition = FormStartPosition.CenterScreen,
Size = new(800, (int)e.WindowFeatures.Height)
};
WebView2 webView = new()
{
Dock = DockStyle.Fill
};
secondForm.Controls.Add(webView);
secondForm.Show();
using (e.GetDeferral())
{
await webView.EnsureCoreWebView2Async(_webView2Environment, _webView2Environment!.CreateCoreWebView2ControllerOptions());
e.NewWindow = webView.CoreWebView2; // must do this after calling AddScriptToExecuteOnDocumentCreatedAsync
}
}
private void btnShowForm_Click(object sender, EventArgs e)
{
_ = webView21.CoreWebView2.ExecuteScriptAsync("window.open('https://www.example.com', 'a', 'height=500,width=500');");
}
}
}
designer file:
namespace WebView2LostDeferral
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
webView21 = new Microsoft.Web.WebView2.WinForms.WebView2();
btnShowForm = new Button();
((System.ComponentModel.ISupportInitialize)webView21).BeginInit();
SuspendLayout();
//
// webView21
//
webView21.AllowExternalDrop = true;
webView21.CreationProperties = null;
webView21.DefaultBackgroundColor = Color.White;
webView21.Dock = DockStyle.Bottom;
webView21.Location = new Point(0, 49);
webView21.Name = "webView21";
webView21.Size = new Size(800, 401);
webView21.TabIndex = 0;
webView21.ZoomFactor = 1D;
//
// btnShowForm
//
btnShowForm.Location = new Point(12, 12);
btnShowForm.Name = "btnShowForm";
btnShowForm.Size = new Size(113, 25);
btnShowForm.TabIndex = 1;
btnShowForm.Text = "Show Form";
btnShowForm.UseVisualStyleBackColor = true;
btnShowForm.Click += btnShowForm_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(btnShowForm);
Controls.Add(webView21);
Name = "Form1";
Text = "Form1";
Load += Form1_Load;
((System.ComponentModel.ISupportInitialize)webView21).EndInit();
ResumeLayout(false);
}
#endregion
private Microsoft.Web.WebView2.WinForms.WebView2 webView21;
private Button btnShowForm;
}
}
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
The text was updated successfully, but these errors were encountered:
What happened?
When I handle a window.open and create a Form with a certain size,
outerHeight
incorrectly matchesinnerHeight
andouterWidth
matchesinnerWidth
This doesn't happen if I don't intercept
NewWindowRequested
and let WebView create the window for me. In that case, if I callwindow.open(url, name, "width=500,height=500")
,outerHeight
is 570 andinnerHeight
is 500.If I intercept the event and create my own Form with the size passed to
window.open
, bothouterHeight
andinnerHeight
are 461 (where 461 is actually the inner height [based on what the value is in my Electron app])And both
outerWidth
andinnerWidth
are 484.In my Electron app, the inner height and width are 461 and 484, respectively, but the outer height and width match what I passed into
window.open
.It seems like in WebView2, the inner bounds gets set to what was passed into window.open (when intercepting NewWindowRequested or not).
And in the case of intercepting the event and creating my own Form, the outer bounds matches the inner bounds.
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
128.0.2739.67
SDK Version
1.0.2535.41
Framework
Winforms
Operating System
Windows 11
OS Version
22631.4169
Repro steps
designer file:
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
The text was updated successfully, but these errors were encountered: