Improve performance and reliability of mutationObservers
Some mutationObservers were attaching to the |.scrollable-content|
element which might not exist when the script runs, so now they attach
to the body element instead.
Also, now the //content_scripts/console_inject.js's mutationObserver no
longer requests attribute changes, because they weren't being used,
which introduced a slight performance penalty.
Bug: #21
Change-Id: I7abca0bcd4eb80a98e3184933977d8116a9db0ec
diff --git a/src/content_scripts/console_inject.js b/src/content_scripts/console_inject.js
index ee3bffb..b5e86f8 100644
--- a/src/content_scripts/console_inject.js
+++ b/src/content_scripts/console_inject.js
@@ -109,7 +109,6 @@
var observerOptions = {
childList: true,
- attributes: true,
subtree: true,
}
@@ -127,8 +126,7 @@
authuser = startup[2][1] || '0';
mutationObserver = new MutationObserver(mutationCallback);
- mutationObserver.observe(
- document.querySelector('.scrollable-content'), observerOptions);
+ mutationObserver.observe(document.body, observerOptions);
intersectionObserver =
new IntersectionObserver(intersectionCallback, intersectionOptions);
diff --git a/src/injections/profileindicator_inject.js b/src/injections/profileindicator_inject.js
index ddf1cfe..1a0125f 100644
--- a/src/injections/profileindicator_inject.js
+++ b/src/injections/profileindicator_inject.js
@@ -352,8 +352,7 @@
}
mutationObserver = new MutationObserver(mutationCallback);
- mutationObserver.observe(
- document.querySelector('.scrollable-content'), observerOptions);
+ mutationObserver.observe(document.body, observerOptions);
} else {
// We are in TW
authuser = (new URL(location.href)).searchParams.get('authuser') || '0';