如何在 Manifest V3 中使用 chrome.tabs.captureVisibleTab

QC *_*CAI 6 google-chrome-extension

我尝试将清单版本从 2 更新到 3。并且 chrome.tabs.captureVisibleTab 抛出错误

Unchecked runtime.lastError: Either the '<all_urls>' or 'activeTab' permission is required.
Run Code Online (Sandbox Code Playgroud)

由于“<all_urls>”在 Manifest 3 中不可用,因此我声明了“activeTab”权限。但这不起作用。

作为我在Background.ts中的代码

Unchecked runtime.lastError: Either the '<all_urls>' or 'activeTab' permission is required.
Run Code Online (Sandbox Code Playgroud)

清单.json

{
  ...,
  "permissions": [
    "contextMenus",
    "tabs",
    "activeTab"
  ],
}
Run Code Online (Sandbox Code Playgroud)

那么如何在Manifest 3中使用这个api进行截图呢?或者我应该使用另一个api?

QC *_*CAI 1

有两种使用 chrome.tabs.captureVisibleTab 的方法:

  1. 声明 '<all-urls>' 权限,但在 Manifest V3 中被放弃。

  2. 声明“activeTabs”权限。但只有当用户调用Chrome 扩展文档中提到的扩展时,它才起作用。因此,如果直接使用 chrome.tabs.captureVisibleTab ,则会抛出错误。

  • `&lt;all_urls&gt;` 在 MV3 中可用。它应该在`host_permissions`中声明。请参阅[迁移指南](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/)。 (3认同)