|
| 1 | +let acmsPageObserver = null; |
| 2 | + |
1 | 3 | // Abstraction of scripts related to Appellate PACER to make them modular and |
2 | 4 | // testable. |
3 | 5 | let AppellateDelegate = function (tabId, court, url, path, links) { |
@@ -74,21 +76,24 @@ AppellateDelegate.prototype.ACMSPageHandler = function () { |
74 | 76 |
|
75 | 77 | // If ACMS has already rendered the main content container (indexContent), |
76 | 78 | // we can immediately initialize the docket handler without waiting for |
77 | | - // HTMX updates. This prevents unnecessary observer creation and avoids |
78 | | - // double-handling when navigating back/forward. |
| 79 | + // HTMX updates. This handles cases where the page loads fully before |
| 80 | + // the extension runs or when navigating back/forward. |
79 | 81 | if ( |
80 | 82 | document.getElementById('indexContent') || |
81 | 83 | document.getElementById('fullDocketContent') |
82 | 84 | ) { |
83 | 85 | this.handleAcmsDocket(); |
84 | | - } else { |
85 | | - // Otherwise, the page is still loading partial content via HTMX. |
86 | | - // Set up a MutationObserver on <body> to detect when ACMS injects |
87 | | - // the relevant sections. |
88 | | - const body = document.querySelector('body'); |
89 | | - const observer = new MutationObserver(pageObserver); |
90 | | - observer.observe(body, { subtree: true, childList: true }); |
91 | 86 | } |
| 87 | + |
| 88 | + if (acmsPageObserver) return; |
| 89 | + |
| 90 | + // Always set up the observer to watch for HTMX updates, even if content |
| 91 | + // is already present. HTMX can trigger partial page updates at any time, |
| 92 | + // and we need to respond to those changes in both Chrome (node-by-node |
| 93 | + // loading) and Firefox (full page already loaded). |
| 94 | + const body = document.querySelector('body'); |
| 95 | + acmsPageObserver = new MutationObserver(pageObserver.bind(this)); |
| 96 | + acmsPageObserver.observe(body, { subtree: true, childList: true }); |
92 | 97 | }; |
93 | 98 |
|
94 | 99 | // Identify and handle pages from Appellate courts. |
|
0 commit comments