WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

disable print

Open codes-shiv opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe.

Describe the solution you'd like and alternatives you've considered

AB#44960339

codes-shiv avatar Jun 07 '23 10:06 codes-shiv

@codes-shiv Can you see below solutions works for your case?

  1. 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');
};

  1. Disable printing from ctrl+p - Disable accelerator keys using CoreWebView2Settings.AreBrowserAcceleratorKeysEnabled

  2. Disable print from context menu - Remove Print context menu using Contextmenurequested , https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/context-menus

monica-ch avatar Jun 07 '23 22:06 monica-ch

@codes-shiv do the workarounds above address your scenario?

nishitha-burman avatar Jul 26 '23 21:07 nishitha-burman

@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 avatar Feb 16 '24 10:02 yadav-shivam

@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 avatar Mar 02 '24 00:03 nishitha-burman

@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

pushkin- avatar Apr 26 '24 18:04 pushkin-

@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.

pushkin- avatar Apr 26 '24 18:04 pushkin-