D
D
dpablo_escobarr2020-11-09 19:56:30
JavaScript
dpablo_escobarr, 2020-11-09 19:56:30

Is it possible to prevent a minimized tab, or a closed Google Chrome browser, from falling asleep?

Is it possible to make it so that after some time, let's say an hour or two, the tabs in the minimized browser do not fall asleep and are not updated when the cursor accesses these tabs? Required for the extension to run in the background

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2020-11-09
@dpablo_escobarr

Yes, in theory, you can disable the unloading of tabs by applying 2 tricks.
Add to background.js :

chrome.tabs.onCreated.addListener(function(tab) {
    chrome.tabs.update(tab.id, {
        autoDiscardable: false
    });
});

chrome.tabs.onReplaced.addListener(function(tabId) {
    chrome.tabs.update(tabId, {
        autoDiscardable: false
    });
});

chrome.runtime.onInstalled.addListener(function(details) {
    chrome.tabs.query({}, function(tabs) {
        tabs.forEach(function(tab) {
            chrome.tabs.update(tab.id, {
                autoDiscardable: false
            });
        });
    });
});

In the extension manifest, you must have the appropriate permissions:
...
"permissions" : [ "tabs" ],
"background" : { "persistent": true, "scripts": [ "background.js" ] },
...

In addition, you need to place an mp3 track on the active tab and run it in an infinite loop:
<video id="antifreeze" style="position: fixed; right: 30px; bottom: 30px; z-index: 99999; height: 55px; width: 300px;" controls loop name="media">
    <source src="https://qna.habr.com/silence.mp3" type="audio/mpeg">
</video>

Starting with version 81 of chrome, tabs freeze after 5 minutes after minimizing. The exception is the tabs in which some kind of medical content is played (video there or music).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question