I've been trying to implement ScreenOrientation.lock()
according to the documentation, but I'm having trouble getting it to work correctly.
https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/lock
When I use
window.screen.orientation.lock("portrait");
on Chrome desktop, I receive an error stating that screen.orientation.lock() is not available on this device.
. Is there a way to determine if a device supports screen orientation locking?
I have already included "orientation":"portrait"
in my manifest.json
, but this only sets the default orientation and does not lock it.
https://www.w3.org/TR/appmanifest/#orientation-member
On a side note:
I had some difficulty understanding how to properly call the method. If anyone else encounters these errors:
ScreenOrientation.prototype.lock("portrait");
window.ScreenOrientation.prototype.lock("portrait");
It results in the following exception:
Unhandled Rejection (TypeError): Failed to execute 'lock' on 'ScreenOrientation': Illegal invocation
(ScreenOrientation as any).lock("portrait");
This leads to the following exception:
TypeError: ScreenOrientation.lock is not a function