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

[Problem/Bug]: CoreWebView2PrintSettings.ScaleFactor is not working when Windows's Microsoft WebView2 Runtime automatically upgade to 118.0.2088.46 verson #4091

Closed
kekoke opened this issue Oct 23, 2023 · 9 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@kekoke
Copy link

kekoke commented Oct 23, 2023

What happened?

Development Environment:
Windows 11

.net core 3.1 Winform
Microsoft.Web.WebView2 nuget version is 1.0.2088.41

My code as below:

private async Task<CoreWebView2PrintSettings> GetPrintSettingsAsync(WebView2 webView)
{
    CoreWebView2PrintSettings settings = webView.CoreWebView2.Environment.CreatePrintSettings();
    try
    {
        await webView.EnsureCoreWebView2Async();
        settings.MarginTop = _printSettings.MarginTop;
        settings.MarginLeft = _printSettings.MarginLeft;
        settings.MarginRight = _printSettings.MarginRight;
        settings.ScaleFactor = 0.4;//设置打印缩放
        //settings.Copies = 2;
        settings.Orientation = _printSettings.Orientation; //CoreWebView2PrintOrientation.Landscape; //横向
    }
    catch (Exception ex)
    {
        LogHelper.Error($"打印机配置错误,错误信息:{ex.Message}");
    }
    return settings;
}

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

118.0.2088.46

SDK Version

1.0.2088.41

Framework

Winforms

Operating System

Windows 10, Windows 11

OS Version

No response

Repro steps

  1. load url
webBrowser.CoreWebView2.Navigate(newUrl);
  1. in WebBrowser1_NavigationCompleted event, call Print function
private async Task<CoreWebView2PrintSettings> GetPrintSettingsAsync(WebView2 webView)
{
    CoreWebView2PrintSettings settings = webView.CoreWebView2.Environment.CreatePrintSettings();
    try
    {
        await webView.EnsureCoreWebView2Async();
        settings.MarginTop = _printSettings.MarginTop;
        settings.MarginLeft = _printSettings.MarginLeft;
        settings.MarginRight = _printSettings.MarginRight;
        settings.ScaleFactor = 0.4;//设置打印缩放
        //settings.Copies = 2;
        settings.Orientation = _printSettings.Orientation; //CoreWebView2PrintOrientation.Landscape; //横向
    }
    catch (Exception ex)
    {
        LogHelper.Error($"打印机配置错误,错误信息:{ex.Message}");
    }
    return settings;
}

 private async Task SendToPrinter()
        {
            //等待界面渲染完成
            CoreWebView2PrintSettings coreWebView2PrintSettings = await GetPrintSettingsAsync(_webBrowser);
            try
            {
                LogHelper.Info($"Step3 - 开始 - 调用浏览器打印");
                Thread.Sleep(_cmesConfig.ThreadSleep);//等待浏览器渲染
                var printResult = await _webBrowser.CoreWebView2.PrintAsync(coreWebView2PrintSettings);
                LogHelper.Info($"Step4 - 结束 - 调用浏览器打印,打印结果:【{JsonConvert.SerializeObject(printResult.ToString())}】");
            }
            catch (Exception ex)
            {
                LogHelper.Error($"连接打印机错误,错误信息:{ex.Message}");
            }
        }

Regression

Regression in newer Runtime

Last working version (if regression)

SDK 1.0.1722.45, Runtime 115.0.1901.203

AB#47211445

@kekoke kekoke added the bug Something isn't working label Oct 23, 2023
@kekoke kekoke changed the title [Problem/Bug]: CoreWebView2PrintSettings.ScaleFactor setting is invalid when windows Microsoft WebView2 Runtime automatically upgade to 118.0.2088.46 verson [Problem/Bug]: CoreWebView2PrintSettings.ScaleFactor setting is invalid when Windows's Microsoft WebView2 Runtime automatically upgade to 118.0.2088.46 verson Oct 23, 2023
@sln162
Copy link

sln162 commented Oct 23, 2023

#4082 Is it the same problem?

@kekoke
Copy link
Author

kekoke commented Oct 23, 2023

#4082 Is it the same problem?

The problem is similar, but not the same.

@lflores-ms lflores-ms added the tracked We are tracking this work internally. label Oct 23, 2023
@lflores-ms
Copy link
Contributor

Thanks for the report @kekoke. Can you clarify what you mean by "setting is invalid"?

@monica-ch will this be addressed by the fix to #4082?

@monica-ch monica-ch self-assigned this Oct 23, 2023
@monica-ch
Copy link
Contributor

If the issue is related to improper scaling in the print output, other bug should solve the problem. I have a fix which is in review, I'll let you know when it is Edge canary for validation.

@kekoke
Copy link
Author

kekoke commented Oct 24, 2023

Thanks for the report @kekoke. Can you clarify what you mean by "setting is invalid"?

@monica-ch will this be addressed by the fix to #4082?

Sorry, it means that CoreWebView2PrintSettings.ScaleFactor does not work, thanks @lflores-ms.

@kekoke
Copy link
Author

kekoke commented Oct 24, 2023

If the issue is related to improper scaling in the print output, other bug should solve the problem. I have a fix which is in review, I'll let you know when it is Edge canary for validation.

Thank you for letting me know. I appreciate your efforts in finding a fix for the improper scaling issue in the print output. Please keep me updated on the progress of the fix and let me know when it is available in Edge Canary for validation. I look forward to testing it out.

@kekoke kekoke changed the title [Problem/Bug]: CoreWebView2PrintSettings.ScaleFactor setting is invalid when Windows's Microsoft WebView2 Runtime automatically upgade to 118.0.2088.46 verson [Problem/Bug]: CoreWebView2PrintSettings.ScaleFactor is not working when Windows's Microsoft WebView2 Runtime automatically upgade to 118.0.2088.46 verson Oct 24, 2023
@monica-ch
Copy link
Contributor

monica-ch commented Oct 26, 2023

@kekoke This is now fixed in Edge canary channel 120.0.2184.0+. Please test and let us know if you still see issues.

https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel

@jagrut-patel
Copy link

When would this fix be distributed for production usage of WebView2 Runtime. We cannot use canary channel in production.

Evergreen Runtime distribution mode has updated to latest version that has introduced this bug for us. We need an option to either go back to previous version of WebView2 Runtime or an official Microsoft Update is available with this fix.

@monica-ch
Copy link
Contributor

@jagrut-patel WebView2 next stable version is scheduled for 12/7 that has a fix. Sorry, there isn't a way to go back to previous evergreen versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

5 participants