检查是否启用了用户手势window.navigator.vibrate?

时间:2017-10-30 22:02:30

标签: javascript google-chrome

最近Chrome 60发生了变化,window.navigator.vibrate在跨源i帧中返回false,并且在该窗口中执行用户手势之前不会振动。有没有办法将监听器附加到窗口以查看何时启用此功能,这样我就可以避免在允许此权限之前调用vibrate

目前,如果您尝试运行该功能,它将在控制台中发出错误并一直这样做,直到您与窗口进行交互为止。

我要避免在控制台上打印的输出示例:

[Intervention] Blocked call to navigator.vibrate because user hasn't tapped on the frame or any embedded frame yet: https://www.chromestatus.com/feature/5644273861001216

0 个答案:

没有答案