m1k1o / neko

A self hosted virtual browser that runs in docker and uses WebRTC.
https://neko.m1k1o.net/
Apache License 2.0
5.96k stars 449 forks source link

Use Keyboard API to lock screen for supported browsers #232

Closed Dishwasha closed 1 year ago

Dishwasha commented 1 year ago

When using fullscreen mode, hitting the escape key will exit out of fullscreen mode. To stay in fullscreen mode but pass the escape key through, we can use the Keyboard API to require the escape key be held down https://wicg.github.io/keyboard-lock/#escape-key.

Tested in Chrome which supports Keyboard API and Firefox which does not https://caniuse.com/?search=navigator.keyboard with no errors in either case.

m1k1o commented 1 year ago

How could be then full-screen mode exited? By pressing F11 again?

Dishwasha commented 1 year ago

https://wicg.github.io/keyboard-lock/#fullscreen-considerations explains that F11 is a user-initiated fullscreen which isn't compatible with Keyboard API. It only works with javascript initiated fullscreen API calls (i.e. via the fullscreen "fa-expand" onscreen button). The browser message will actually change from "Press Esc to exit fullscreen" to "Press and hold Esc to exit fullscreen", so the user has to hold down the Escape key rather than just press it. Alternatively if they move the mouse to the top of the screen the big circle X still appears which they can click on to exit fullscreen mode as well.

m1k1o commented 1 year ago

Looks good. I'd rather be, if lock and unlock function were in the same file. E.g. in video.vue inside requestFullscreen() function.

Dishwasha commented 1 year ago

Makes sense. How's this change look? Re-tested and it works.

m1k1o commented 1 year ago

Looks much better, thank you!