google-chrome - 为 chrome.tabCaptureAPI 指定 Tab 或 TabID?
问题描述
问题的简短版本:是否可以在给定选项卡 ID 的情况下选择我希望 tabCapture 记录的版本?
稍长的版本:我正在为自己开发一个扩展,其清单如下:
{
"name": "Getting Started Example",
"description": "Build an Extension!",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": [
"storage",
"background",
"tabs",
"tabCapture",
"<all_urls>"
],
"browser_action": {
"default_popup": "./popup.html",
"default_icon": "./icon.png"
}
}
我的 background.js 代码:
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
console.log("Background started")
async function screenRecord(tab) {
console.log("Started recording")
/* Where do i put selected tab? */
chrome.tabCapture.capture({
audio: true,
video: true
},
(stream) => {
/* Goes somewhere later*/
})
await sleep(5000);
/* stop recording of that with the ID */
}
async function startRun() {
let myTabs = []
for(let i = 0; i <= 3; i++) {
chrome.tabs.create({url:"https://www.google.com/"}, (e) => {
myTabs[i] = e;
});
await sleep(5000);
chrome.tabs.update( myTabs[i]['id'], { url: "http://stackoverflow.com//" } );
await sleep(5000);
/* Pass the tab id to be capture d*/
screenRecord(myTabs[i]['id'])
await sleep(5000);
chrome.tabs.remove(myTabs[i]['id']);
await sleep(10000);
}
}
startRun()
这个想法是,给定一个 tabID,我可以告诉 tabCapture 记录一个特定的选项卡,然后在 5 秒后停止它(在这种情况下)。
由于 tabCapture 不提供指定 ID 的方法,我怎么能做到这一点?