我尝试将清单版本从2更新到3。和chrome.tabs.captureVisibleTab抛出错误
Unchecked runtime.lastError: Either the '<all_urls>' or 'activeTab' permission is required.
作为'<all_urls>'在清单3中不可用,我声明了"activeTab"权限。但它不起作用。
作为我在Background.ts 中的代码
export const getCapture = (): Promise<string> => {
return new Promise((resolve) => {
chrome.tabs.captureVisibleTab((dataUrl) => resolve(dataUrl));
});
};
Manifest.json
{
...,
"permissions": [
"contextMenus",
"tabs",
"activeTab"
],
}
那么,我如何使用这个api在清单3中进行屏幕截图呢?或者我应该使用另一个api吗?
有两种方法可以使用chrome.tabs.captureVisibleTab:
-
声明"权限,但在Manifest V3中被放弃。
-
声明"activeTabs"权限。但只有当用户调用Chrome扩展文档中提到的扩展时,它才起作用。所以,如果您直接使用chrome.tabs.captureVisibleTab,它会抛出错误。