In a recent Firefox (64.0) you'll see this error:
TypeError: The expression cannot be converted to return the specified type.
in Chrome (71.0.x):
TypeError: Document not active
The solution is to check whether we are currently in fullscreen mode.
Run it in jsfiddle, for testing the fullscreen mode.