How to debug suspended background / event state

I would like to debug what a background script (not persistent) does when it goes to sleep and wakes up (and goes back to sleep again).

Clicking on the "man page" will prevent the background from going into a "suspended" state, but if I close the page and open it after a while, only the latest logs are displayed, not the ones that were printed before the background page (from the extensions page) was opened.

So I'm wondering how we debug suspended / side states in the event page?

Edit: moved backstory to my own question here

How to prevent / detect race condition between processing and restoring storage data on event page wakeup

+1


source to share


2 answers


You can simultaneously log into the console and non-volatile memory.

You can 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 only be used if you are actively debugging.

+2


source


Try creating a pageLog function and submitting objects that will be logged on the page.



0


source







All Articles