如果我从后台页面向devtools面板发送消息,但devtools面板没有打开,我希望在它打开时发送这些消息。我不确定如何去实现它。
发布于 2016-07-19 21:58:54
https://github.com/sindresorhus/devtools-detect是一个允许你检测devtools是否打开的库。因此,如果您已确定devtools已关闭,请将您的消息推送到堆栈,然后在检测到devtools已打开时记录这些消息。
var logStack = [];
function myLog(msg) {
if(!window.devtools.open) logStack.push(msg);
else console.log(msg);
}
window.addEventListener('devtoolschange', function (e) {
if(!e.detail.open) return;
while(logStack.length > 0) {
console.log(logStack.shift());
}
});https://stackoverflow.com/questions/38460622
复制相似问题