Summary
Prototype replacing the interval-based DOM scanning in Monkey.js with MutationObserver to improve performance and responsiveness.
Current behavior
Monkey.js uses setInterval (default 100ms) to repeatedly walk the DOM and apply replacement commands. This works but is wasteful on static pages and can lag behind rapid DOM changes.
Proposed exploration
- Implement a
MutationObserver-based approach that triggers command application only when the DOM actually changes
- Benchmark against the current interval approach on:
- Heavy SPA pages (e.g., large dashboards with frequent updates)
- Static pages (should show clear improvement)
- Pages with rapid DOM churn (risk of observer flood)
- Consider a hybrid approach: MutationObserver for change detection + debounced batch application
Risks
- MutationObserver can fire very frequently on some SPAs, potentially worse than polling
- Commands that depend on timing/ordering may behave differently
- This is a core engine change — needs thorough E2E validation
Summary
Prototype replacing the interval-based DOM scanning in
Monkey.jswithMutationObserverto improve performance and responsiveness.Current behavior
Monkey.jsusessetInterval(default 100ms) to repeatedly walk the DOM and apply replacement commands. This works but is wasteful on static pages and can lag behind rapid DOM changes.Proposed exploration
MutationObserver-based approach that triggers command application only when the DOM actually changesRisks