Can't enter fullscreen second time(flutter UI widget on click) in web chrome:
void requestFullScreen() {
print("entering fullscreen");
Future<void>? future = document.documentElement?.requestFullscreen();
future?.catchError(
(Object obj) {
window.alert("Can't enter full screen mode, forbidden by browser with error: ${obj.toString()}");
return;
},
);
}
void exitFullScreen() {
print("exiting fullscreen");
document.exitFullscreen();
}
void notActualFunctionButUserClickingOnWidgetFlow() {
requestFullScreen();
await Future.delayed(const Duration(seconds: 2));
exitFullScreen();
await Future.delayed(const Duration(seconds: 2));
requestFullScreen();
await Future.delayed(const Duration(seconds: 2));
exitFullScreen();
}
So the story is the following: First 'enterFullscreen' works fine, exits fine, but next fullscreen call throws
Uncaught (in promise) TypeError: Permissions check failed
at [dartx.requestFullscreen] (html_dart2js.dart:13993:11)
at Object.requestFullScreen (dio_adapter_web.dart:21:29)
at dio_adapter_web.dart:52:5
at Generator.next (<anonymous>)
at async_patch.dart:45:50
at _RootZone.runUnary (zone.dart:1661:54)
at _FutureListener.thenAwait.handleValue (future_impl.dart:162:18)
at handleValueCallback (future_impl.dart:846:44)
at _Future._propagateToListeners (future_impl.dart:875:13)
at [_complete] (future_impl.dart:638:7)
at future.dart:424:15
at internalCallback (isolate_helper.dart:48:11)
Why it's alright to enter fullscreen first time, but for next you need permission, and how to request it?
I tried to do some 'magic' with:
window.navigator.permissions?.request({"name": "fullscreen"})
Actually, just crashes with any param, because not every browser seems to be capable of doing this new feature(according to other SOF questions), but there is no way to request fullscreen permission any other way, unless I'm missing something.
PS. It can be some kind of 'you need to call specific widget.onclick' or whatever, I can create demo project on request.
To pass the browser security check the user has to interact with your website before you make a call to
requestFullscreen.We can solve this issue by showing a overlay which waits for the user to click before attempting to make the page fullscreen. It's not the best solution but unfortunately it's what you have to do.
If you have any quesstions please let me know.