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.addEventListener("DOMContentLoaded", function() {
addDocumentStylesToAllIFrames();
iframeObserver.start();
});
document.addEventListener("DOMContentLoaded", onDOMContentLoaded);
}
if (retiredStyleIds.length) {
@ -165,6 +162,11 @@ function applyStyles(styleHash) {
}
}
function onDOMContentLoaded() {
addDocumentStylesToAllIFrames();
iframeObserver.start();
}
function applySections(styleId, sections) {
var styleElement = document.getElementById("stylus-" + styleId);
// Already there.
@ -317,9 +319,12 @@ function initObserver() {
// we're orphaned due to an extension update
// 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 = 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
[