如何调试后台/活动页面暂停状态 [英] How to debug background/event page suspended state
问题描述
我想调试后台脚本(非持久性)在进入睡眠状态并醒来(并再次返回到睡眠状态)时所做的操作。
单击在背景页面上将阻止后台脚本进入挂起状态,但是如果我杀掉页面并在一段时间后打开它,则只会显示新的日志,而不是打开背景页面之前打印的日志(从
所以我想知道我们如何调试事件页面的挂起/唤醒状态?
<编辑:将背景故事转移到它自己的问题上
如何在唤醒事件页面时防止/检测处理和恢复店铺数据之间的竞争状态
您可以同时登录到控制台和非易失性存储。
您可以使用自定义日志记录功能,或重载 console.log
:
console._log = console.log;
console.log = function(){
var args = arguments;
console._log.apply(console,args);
chrome.storage.local.get({consoleLog:[]},function(data){
data.consoleLog.push(args);
chrome.storage.local.set({ consoleLog:data.consoleLog});
});
}
当然,它应该只在您主动调试时使用。
I would like to debug what the background script (non persistent) does when it goes to sleep and wakes up (and goes back to sleep again).
Clicking on the "background page" will prevent the background script from going into suspended state, but if I kill the page and open it after a while, only fresh logs are displayed, not the ones that were printed before opening the background page (from the extensions page).
So I am wondering how do we debug the suspended/wake states of an event page?
Edit: Moved the backstory to its own question here
You could log to the console AND non-volatile storage at the same time.
You can either use a custom logging function, or overload console.log
:
console._log = console.log;
console.log = function() {
var args = arguments;
console._log.apply(console, args);
chrome.storage.local.get({consoleLog : []}, function(data) {
data.consoleLog.push(args);
chrome.storage.local.set({consoleLog: data.consoleLog});
});
}
Of course, it should probably only be used while you're actively debugging.
这篇关于如何调试后台/活动页面暂停状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!