Answer the question
In order to leave comments, you need to log in
How to make the chrome extension prevent the browser from freezing the tab and the tab was always active?
There is a self-written extension for one site. So that the browser does not freeze the tab, a crutch was written that spins the video in the background and prevents the browser from putting the tab to sleep.
But you still need to make at least one click on the page so that the tab does not freeze. Is it possible to get around this somehow so that the tab after opening or refreshing by F5 would be active and so that the browser would not be able to freeze it, so that extension scripts could be executed without the user's first click?
Most importantly, I can't figure out how to make extensions execute arbitrary code right after the page opens.
//<editor-fold desc="Вкладки - пинаем спящие">
const video = document.createElement('video');
video.setAttribute('width', '10');
video.setAttribute('height', '10');
video.style.position = 'absolute';
video.style.top = '-10px';
video.style.left = '-10px';
document.body.appendChild(video);
const video_mp4 = document.createElement('source');
video_mp4.setAttribute('src', `chrome-extension://${document.head.dataset.extension}/video/dummy.mp4`);
video_mp4.setAttribute('type', 'video/mp4');
video.appendChild(video_mp4);
const video_ogg = document.createElement('source');
video_ogg.setAttribute('src', `chrome-extension://${document.head.dataset.extension}/video/dummy.ogv`);
video_ogg.setAttribute('type', 'video/ogg');
video.appendChild(video_ogg);
addEventListener(`click`, () => {
video.setAttribute('loop', 'loop');
video.play().catch(e => console.error(e));
setInterval(() => {
document.title = new Date(server_time()).toLocaleTimeString();
if (parent) parent.document.title = document.title;
}, 500)
}, {once: true});
//</editor-fold>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question