gpt4 book ai didi

javascript - 在没有浏览操作的情况下捕获 chrome 选项卡

转载 作者:行者123 更新时间:2023-11-30 16:12:44 24 4
gpt4 key购买 nike

我有一个捕获当前选项卡的简单方法,它仅在通过单击扩展按钮(即 browserAction)触发此方法时才有效。

但是当我在 setTimeout 事件中使用此方法时,它失败并出现以下错误:

Unchecked runtime.lastError while running tabCapture.capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.

我的简单抓包方法是:

function captureTab() {
var constraints = ...
chrome.tabCapture.capture(constraints, function (stream) {
if (!stream) {
console.error("couldn't record tab");
return;
}
// recording succeeded
});
}

当它触发时它会工作,如下所示:

chrome.browserAction.onClicked.addListener(function () {
chrome.tabs.getSelected(null, function (tab) {
captureTab();
});
});

触发时如下:

setTimeout(function () {
chrome.tabs.getSelected(1, function (tab) {
captureTab();
});
}, 1 * 30 * 1000);

重要说明:我的扩展程序不是公共(public)扩展程序,它仅在我的浏览器上运行,因此如果需要,我可以在启动时添加任何命令行开关(以禁用此限制)。

最佳答案

请注意chrome.tabCapture.capture只能在调用扩展后在当前事件的选项卡上启动。

Captures the visible area of the currently active tab. Capture can only be started on the currently active tab after the extension has been invoked.

当你声明 activeTab权限,只有以下用户手势才能启用它

  • Executing a browser action
  • Executing a page action
  • Executing a context menu item
  • Executing a keyboard shortcut from the commands API
  • Accepting a suggestion from the omnibox API

因此,当您使用setTimeOut 时,您无法确保当前选项卡处于事件状态。

关于javascript - 在没有浏览操作的情况下捕获 chrome 选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35985266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com