Hassaan Hafeez
Hassaan Hafeez

Reputation: 107

Messages to Devtools if Devtools not open

If I send messages from the background page to the devtools panel, but the devtools panel is not open I want those messages to get sent when it does open. I'm not sure how to go about implementing this.

Upvotes: 0

Views: 67

Answers (1)

WouterH
WouterH

Reputation: 1356

https://github.com/sindresorhus/devtools-detect is a library which allows you to detect if the devtools are open or not. So if you've determined the devtools are closed, push your messages to a stack, then log those messages once you've detected that the devtools have been opened.

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());
    }
});

Upvotes: 1

Related Questions