Skip to content

Content script MutationObserver watches entire document.body subtree for URL changes #100

Description

@Exotic209093

@

Summary

MutationObserver observes document.body with childList:true, subtree:true, firing the callback on every DOM mutation in the Salesforce page instead of using navigation events.

Detail

Line 170 configures urlObserver.observe(document.body, { childList: true, subtree: true }). Salesforce Lightning pages are highly dynamic SPAs that mutate the DOM constantly (component renders, data loading spinners, toast notifications, etc.). Every single mutation batch triggers the observer callback, which compares window.location.href against lastUrl. While the comparison itself is O(1), the browser must invoke the callback and serialize mutation records for every DOM change across the entire page tree. This creates persistent overhead on the content scripts main thread for the lifetime of the page. Modern Chrome extensions should use chrome.webNavigation.onHistoryStateUpdated or the Navigation API (navigation.addEventListener(navigate, ...)) for SPA URL detection, which fire only on actual navigations.

Location

src/content/index.ts:170

Reproduction

Open DevTools Performance tab on a Salesforce page with WaveLink content script injected; observe repeated MutationObserver callback invocations during normal page interaction even when the URL has not changed.

Suggested Fix

Replace the MutationObserver with chrome.webNavigation.onHistoryStateUpdated listener in the background script (which can message the content script), or use window.addEventListener(popstate, ...) combined with monkey-patching history.pushState/replaceState for same-document navigations.

Verification

REAL(high): Verified at line 170: MutationObserver observes document.body with childList:true, subtree:true. The | REAL(high): The MutationObserver on document.body with subtree:true fires on every DOM mutation in Salesforce Li | REFUTED(high): The finding is not a real performance issue due to three strong mitigations already in place: (1) Th


🤖 Found by automated codebase audit (Claude Fable 5.1)
@

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions