Javascript Chrome扩展:强制事件页面保持打开状态?

Javascript Chrome扩展:强制事件页面保持打开状态?,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,我正在使用chrome.tabCapture.capture从我的背景页面捕获选项卡的音频: chrome.tabCapture.capture({ audio: true, video: false }, (stream) => { if (null == stream) { chrome.extension.sendMessage({ ty

我正在使用
chrome.tabCapture.capture
从我的背景页面捕获选项卡的音频:

chrome.tabCapture.capture({
           audio: true,
           video: false
       }, (stream) => {
           if (null == stream) {
               chrome.extension.sendMessage({
                   type: "powerOff"
               });
           } else {
               methods.createAudio(stream);
           })
通过从弹出窗口发送请求来捕获和取消捕获选项卡

我希望在选项卡未捕获时扩展不在后台运行,但是当我在清单中将后台持久性切换为“false”时,当我从捕获的窗口切换焦点时,事件页面停止工作(捕获)

活动页面显示: 如果使用消息传递,请确保关闭未使用的消息端口。在关闭所有消息端口之前,事件页不会关闭

所以我在考虑使用:

setInterval(function () {
        console.log("Tab Captured. Forcing event page to stay open..");
        chrome.runtime.sendMessage("CAPTURING");
    }, 1000);
这是为了通过每秒向弹出窗口发送消息来强制页面保持打开状态

这种方法安全吗?推荐的间隔值是多少

Manifest:  
{
"background": {
   "scripts": ["js/bg/bg.html" ],
   "persistent": false
},
 "browser_action": {
  "default_icon": "style/128_off.png",
  "default_popup": "popup.html",
  "default_title": "__MSG_mainTitle__"
},
"default_locale": "en",
"description": "__MSG_description__",
"icons": {
  "128": "style/128_on.png"
},
"manifest_version": 2,
"name": "__MSG_name__",
"offline_enabled": true,
"options_page": "options.html",
"permissions": [ "*://*/*", "tabCapture", "tabs", "storage" ],
"version": "2.3.9"
}

是的,1000是安全的。另一种方法是只打开一个持久端口连接。