Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discover why canvas.requestFullscreen() failed?

Task at hand is to add support for fullscreen mode to an WebGL application written in Dart.

canvas.requestFullscreen() works for simple test cases, but fails on the full app.

Please point out the way to tell what is preventing the browser from switching to fullscreen.

The code is:

void trapFullscreenError() {
  document.onFullscreenError.listen((e) {
    log("fullscreenerror: $e");
  });
}

void toggleFullscreen(CanvasElement c) {
  log(
      "fullscreenSupport=${document.fullscreenEnabled} fullscreenElement=${document.fullscreenElement}"
      );

  if (document.fullscreenElement != null) {
    log("exiting fullscreen");
    document.exitFullscreen();
  } else {
    log("requesting fullscreen");
    c.requestFullscreen();
  }
}

In Chrome that code results in:

fullscreenSupport=true fullscreenElement=null
requesting fullscreen
fullscreenerror: Instance of 'Event' 

Dartium debugger shows these fields:

Event [id=4]
_selector null
bubbles true
cancelable false
clipboardData null
currentTarget #document [id=5]
defaultPrevented false
eventPhase 3
hashCode 234642739
path NodeList[6] [id=6]
target canvas#main_canvas [id=7]
timeStamp 1398779450832
type "webkitfullscreenerror"
like image 461
Everton Avatar asked Oct 18 '25 14:10

Everton


1 Answers

For security reasons requestFullscreen can only be called in an event handler of a keyboard or click event.

see also Javascript request fullscreen is unreliable

like image 155
Günter Zöchbauer Avatar answered Oct 21 '25 03:10

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!