Chrome Extension Debugging Lessons — Domain Whitelist, Duplicate Listeners, Closure Pitfalls
When maintaining a Chrome extension, “this should definitely work, why doesn’t it?” comes up more often than expected. I made four consecutive mistakes in a short period, each with a different root cause. Writing them down. 1. A return in the dispatch block silently kills generic detection Content scripts typically end with a pattern like this: if (isSomeSpecificPage()) { doSomethingSpecific(); return; // ← exits here } // Generic DOM detection (MutationObserver, etc.) const observer = new MutationObserver(() => { ... }); observer.observe(document.body, { childList: true, subtree: true }); After adding a feature for a specific domain with an early return, the generic DOM detection never ran in a popup window on that domain. ...
