我正在开发一个需要在后台运行的小型Chrome扩展程序.但是,据我所知,当我使用弹出窗口时,这是不可能的.经过一些阅读后,似乎最好的选择是创建popup.js顺序运行background.js,使用chrome.extension.getBackgroundPage()函数.
有人可以告诉我一个如何做的例子吗?
这是清单:
"browser_action": {
"permissions": ["background"],
"default_popup": "popup.html"},
"options_page": "options.html",
"background": {
"scripts": ["background.js"],
"persistent" : true
}
Run Code Online (Sandbox Code Playgroud)
我在下面列出了popup.js参考popup.html:
<script src="popup.js"></script>
Run Code Online (Sandbox Code Playgroud)
并创建了一个变量 popup.js
var bkg = chrome.runtime.getBackgroundPage();
Run Code Online (Sandbox Code Playgroud)
所以现在我需要一种方法来激活background.js
我需要内运行相关的功能background.js从popup.js,或给一个通用命令的background.js运行?
我正在使用Web音频API将我的麦克风输入流式传输到扬声器,因此我可以听到自己通过扬声器讲话:
var aCtx = new AudioContext();
navigator.mediaDevices.getUserMedia({audio: true}).then(function (stream) {
var microphone = aCtx.createMediaStreamSource(stream);
microphone.connect(aCtx.destination);
})
Run Code Online (Sandbox Code Playgroud)
它工作正常,但是只要我保持稳定的长时间语音输入,输出增益就会在几秒钟后下降。
我遵循cwilso的建议并添加了回声消除约束。但是结果仍然相同。
这是一个小提琴:https : //jsfiddle.net/hcrgL9eg/
帮助将不胜感激。
我正在尝试创建一个钢琴键盘,该键盘将使用弹性框保持其元素比例,但一旦我开始更改窗口大小,似乎无法使黑色音符保持相同的宽度或高度。
这是一个小提琴
body{
width: 800px;
height: 200px;
display: flex;
}
#kbd {
padding: 1%;
flex-flow: column;
display: flex;
flex: 4;
}
#keys {
display: flex;
flex: 8;
justify-content: center;
}
.note {
flex: 1;
display: inline-flex;
align-items: center;
}
.black {
justify-content: center;
position: absolute;
height: 45%;
background-color: #474747;
color: white;
width: 8%;
margin: 0 -4%;
}
.white {
flex-flow: column;
justify-content: flex-end;
outline: 2px solid #474747;
color: #474747;
background-color: #ffffff;
padding-bottom: 1%;
}
Run Code Online (Sandbox Code Playgroud)