Orphaned content script case self-destruction tweaks#2 for apply.js

This commit is contained in:
tophf 2017-03-19 05:23:58 +03:00
parent b77823c365
commit ac2a1a1c48

View File

@ -150,10 +150,7 @@ function applyStyles(styleHash) {
document.head.appendChild(document.getElementById(id)); document.head.appendChild(document.getElementById(id));
} }
} }
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
addDocumentStylesToAllIFrames();
iframeObserver.start();
});
} }
if (retiredStyleIds.length) { if (retiredStyleIds.length) {
@ -165,6 +162,11 @@ function applyStyles(styleHash) {
} }
} }
function onDOMContentLoaded() {
addDocumentStylesToAllIFrames();
iframeObserver.start();
}
function applySections(styleId, sections) { function applySections(styleId, sections) {
var styleElement = document.getElementById("stylus-" + styleId); var styleElement = document.getElementById("stylus-" + styleId);
// Already there. // Already there.
@ -317,9 +319,12 @@ function initObserver() {
// we're orphaned due to an extension update // we're orphaned due to an extension update
// we can detach the mutation observer // we can detach the mutation observer
// we can't detach chrome.runtime.onMessage because it's no longer connected internally iframeObserver.takeRecords();
iframeObserver.disconnect(); iframeObserver.disconnect();
iframeObserver = null; iframeObserver = null;
// we can detach event listeners
document.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
// we can't detach chrome.runtime.onMessage because it's no longer connected internally
// we can destroy global functions in this context to free up memory // we can destroy global functions in this context to free up memory
[ [