我收到此错误:
Uncaught (in promise) DOMException: lockOrientation() is not available on this device.
code: 9
message: "lockOrientation() is not available on this device."
name: "NotSupportedError"
当我在 Chrome 中运行以下代码时:
try {
screen.orientation.lock('portrait');
} catch (error) {
// whatever
}
由于桌面 Chrome 不支持方向锁定,因此会引发错误这一事实是意料之中的。我想捕捉错误,这样它就不会乱扔控制台,但将它包装在一个try...catch
块中似乎不起作用。
为什么我抓不到?我错过了什么吗?