How to exit FullScreen mode with native code?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to exit FullScreen mode with native code?

Postby lwttai » Tue Mar 31, 2020 7:04 am

I need to enable ESC key for exiting the full screen mode.
What I am doing now is to invoke javascript
Code: Select all
document.webkitExitFullscreen()
in OnKeyEvent callback.
As know as, js function may override by website js code like:
Code: Select all
document.webkitExitFullscreen = function(){console.log("hook webkitExitFullscreen");}

Is there any native way or any secure js code which will not be override by the js from website to exit full screen mode?
lwttai
Techie
 
Posts: 24
Joined: Mon Oct 14, 2019 12:18 am

Re: How to exit FullScreen mode with native code?

Postby magreenblatt » Tue Mar 31, 2020 12:03 pm

JavaScript could also override the ESC key handling unless you use OnPreKeyEvent instead of OnKeyEvent.

Chromium internally has a WebContents::ExitFullscreen method that is not currently exposed by CEF. It would be reasonable to add a CefBrowserHost::ExitFullscreen method to support this.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to exit FullScreen mode with native code?

Postby lwttai » Tue Mar 31, 2020 10:50 pm

magreenblatt wrote:JavaScript could also override the ESC key handling unless you use OnPreKeyEvent instead of OnKeyEvent.

Chromium internally has a WebContents::ExitFullscreen method that is not currently exposed by CEF. It would be reasonable to add a CefBrowserHost::ExitFullscreen method to support this.



Yep, seems that should be a ability provide by CEF. I will create a issue for this.
lwttai
Techie
 
Posts: 24
Joined: Mon Oct 14, 2019 12:18 am

Re: How to exit FullScreen mode with native code?

Postby amaitland » Wed Apr 01, 2020 4:00 am

You can take a copy of `document.exitFullscreen` and store it in your own global javascript variable for later execution.

OnContextCreated should be called before all other javascript has executed, so there's plenty of options at your disposal.

Alternatively you can try execute the following in OnContextCreated (this runs in devtools, never tried it in a real world application);

Code: Select all
Object.seal(document);
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 34 guests