WebView2Feedback
WebView2Feedback copied to clipboard
disable print
Is your feature request related to a problem? Please describe.
Describe the solution you'd like and alternatives you've considered
@codes-shiv Can you see below solutions works for your case?
- To disable printing using JS window.print - Hacky workaround could be to override window.print method using AddScriptToExecuteOnDocumentCreated with the stub:
window.print = function () {
console.log('Skip printing');
};
-
Disable printing from ctrl+p - Disable accelerator keys using CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled
-
Disable print from context menu - Remove
Print
context menu using Contextmenurequested , https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/context-menus
@codes-shiv do the workarounds above address your scenario?
@nishitha-burman This is not working for us as Disable accelerator keys will disable all accelerator keys however we want to disable print. Can we expect some API for disabling print in WebView2 ?
@yadav-shivam you can handle AcceleratorKeyPressed and mark Ctrl+P as handled or use this API: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2acceleratorkeypressedeventargs.isbrowseracceleratorkeyenabled?view=webview2-dotnet-1.0.2357-prerelease&preserve-view=true to disable print. Does this work for you?
@nishitha-burman How does one access this event if we don't have a Controller? I'm using a WinForms WebView2 control and using its KeyDown event. But how can I get a controller from that? Thought wasn't exposed unless I create one via environment.CreateCoreWebView2ControllerAsync
which I thought wasn't recommended as per the discussion here
@nishitha-burman there is KeyDown event on the control but that seems to not detect stuff like Ctrl+R. It thinks Control key isn't being pressed and e.Handled=true doesn't prevent the behavior.