Skip to content

Explore MutationObserver to replace setInterval polling #342

Description

@svrnm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions