From ac2a1a1c4883248f8b0d586d6a069142c6641d50 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 19 Mar 2017 05:23:58 +0300 Subject: [PATCH] Orphaned content script case self-destruction tweaks#2 for apply.js --- apply.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apply.js b/apply.js index 6ae471b7..e882ed9f 100644 --- a/apply.js +++ b/apply.js @@ -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 [