英文:
Extension optional permissions request: What counts as a user gesture?
问题
我试图使用 chrome.permissions.request
API 请求可选权限。
然而,chrome.permissions.request 需要用户手势。
什么算作用户手势?我无法在扩展的页面操作图标被点击时直接请求权限。
我已经尝试确保在调用 chrome.permissions.request
时事件处理程序是同步的,但这并没有帮助。我收到的错误是:
Uncaught (in promise) Error: 必须在用户手势期间调用此函数
英文:
I'm trying to use the chrome.permissions.request
API to request optional permissions.
However, chrome.permissions.request requires a user gesture.
What counts as a user gesture? I'm unable to request permissions as a direct response to the extension's page action icon being clicked.
I've tried ensuring that the event handler is synchronous when calling chrome.permissions.request
, but this does not help. The error I get is:
> Uncaught (in promise) Error: This function must be called during a
> user gesture
答案1
得分: 1
Mozilla在其页面上描述了用户手势。
他们如下所述 - 为了遵循“不出乎意料”的原则,像这样的API只能从用户操作的处理程序内调用。用户操作包括以下内容:
- 单击扩展的浏览器操作或页面操作。
- 选择由扩展定义的上下文菜单项。
- 激活由扩展定义的键盘快捷键(这只在Firefox 63及以后被视为用户操作)。
- 单击扩展捆绑的页面中的按钮。
这些手势应该能够触发请求。
英文:
Mozilla has a page describing user gestures
They write as follows - to follow the principle of "no surprises", APIs like this can only be called from inside the handler for a user action. User actions include the following:
- Clicking the extension's browser action or page action.
- Selecting a context menu item defined by the extension.
- Activating a keyboard shortcut defined by the extension (this only
treated as a user action from Firefox 63 onwards). - Clicking a button in a page bundled with the extension.
Those gestures should be able to activate the request.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论