Fix: ignore the initial empty ec-app
The initial CC HTML contains an empty ec-app element, and the script
sometimes tried to initialize the intersection observer with this empty
ec-app element.
Now if the ec-app element doesn't contain the |.scrollable-content| div
(which means it's empty) the intersection observer is not initialized.
This ec-app element is always replaced later on with another ec-app
element which does contain the |.scrollable-content| div.
Bug: #21
Change-Id: I2dc54d0edf4a010a3860ffa1bdb104c8303de911
diff --git a/src/content_scripts/console_inject.js b/src/content_scripts/console_inject.js
index ab0abca..8a1d373 100644
--- a/src/content_scripts/console_inject.js
+++ b/src/content_scripts/console_inject.js
@@ -239,14 +239,17 @@
// Set up the intersectionObserver
if (typeof intersectionObserver === 'undefined' && ('tagName' in node) &&
node.tagName == 'EC-APP') {
- intersectionOptions = {
- root: node.querySelector('.scrollable-content'),
- rootMargin: '0px',
- threshold: 1.0,
- };
+ var scrollableContent = node.querySelector('.scrollable-content');
+ if (scrollableContent !== null) {
+ intersectionOptions = {
+ root: scrollableContent,
+ rootMargin: '0px',
+ threshold: 1.0,
+ };
- intersectionObserver =
- new IntersectionObserver(intersectionCallback, intersectionOptions);
+ intersectionObserver =
+ new IntersectionObserver(intersectionCallback, intersectionOptions);
+ }
}
// Start the intersectionObserver for the "load more"/"load all" buttons