move visibility listener to shared content script

This commit is contained in:
ivan grachev 2023-12-12 20:21:25 +03:00
parent 90735d7e6e
commit d7c7e3c745
2 changed files with 14 additions and 14 deletions

View File

@ -131,3 +131,17 @@ function getFavicon() {
function genId() {
return new Date().getTime() + Math.floor(Math.random() * 1000);
}
function didChangeVisibility() {
if (document.pendingRequestsIds.size != 0 && document.visibilityState === 'visible') {
document.pendingRequestsIds.forEach(id => {
const request = {id: id, subject: "getResponse", host: window.location.host};
browser.runtime.sendMessage(request).then(response => {
sendToInpage(response, id);
});
});
}
return true;
}
document.addEventListener('visibilitychange', didChangeVisibility);

View File

@ -1,15 +1 @@
// Copyright © 2022 Tokenary. All rights reserved.
function didChangeVisibility() {
if (document.visibilityState === 'visible' && document.pendingRequestsIds.size != 0) {
document.pendingRequestsIds.forEach(id => {
const request = {id: id, subject: "getResponse", host: window.location.host};
browser.runtime.sendMessage(request).then(response => {
sendToInpage(response, id);
});
});
}
return true;
}
document.addEventListener('visibilitychange', didChangeVisibility);