扩展程序可选权限请求:什么被视为用户手势?

huangapple go评论66阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月26日 16:53:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定