Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AIPexStudio AIPex Strict Background Mode

From Leeroopedia
Knowledge Sources
Domains Automation, Browser_Extension
Last Updated 2026-10-24 12:00 GMT

Overview

Background mode uses DOM-based snapshots only and never falls back to CDP — if the content script is unavailable, it throws rather than silently switching to debugger-based automation.

Description

When `automationMode` is set to `"background"`, the snapshot provider collects accessibility tree data via content-script DOM traversal instead of Chrome DevTools Protocol. This mode is designed for silent operation where no visible "debugging this tab" banner should appear. Critically, if the DOM snapshot fails (e.g., content script not loaded, page not responding), the provider does NOT fall back to CDP — it throws an error and instructs the user to either fix the content script or switch to focus mode. This "strict silent" behavior prevents unexpected visual disruption when the user explicitly chose background mode.

Usage

Use this heuristic when debugging snapshot failures in background mode. If you see "Failed to create DOM snapshot in background mode," do not attempt to add CDP fallback logic — the strict no-fallback design is intentional. Instead, ensure the content script is properly injected on the target tab or switch to focus mode.

The Insight (Rule of Thumb)

  • Action: Never add CDP fallback in background-mode code paths.
  • Value: `throw new Error(...)` on DOM snapshot failure rather than `snapshotManager.createSnapshot(tabId)`.
  • Trade-off: Background mode may fail on tabs where the content script is not loaded (e.g., chrome:// pages, PDF viewers). This is acceptable to maintain the "silent" contract.
  • Compatibility: Background mode works without the `debugger` permission. Focus mode requires it.

Reasoning

The user explicitly selects background mode to avoid the visual disruption of the Chrome debugger banner. If the system silently fell back to CDP when the DOM snapshot failed, it would violate the user's expectation of silent operation. By throwing an error instead, the system surfaces the problem (content script not loaded) and gives the user an actionable choice: fix the content script or switch to focus mode. The CDP cache is also explicitly cleared when entering background mode to prevent stale CDP data from being served.

Code Evidence

Strict no-fallback on DOM snapshot failure from `packages/browser-runtime/src/automation/snapshot-provider.ts:183-205`:

if (mode === "background") {
  try {
    const domSnapshot = await requestDomSnapshot(tabId);
    const unified = convertDomSnapshotToUnified(domSnapshot, tabId);
    domSnapshotCache.set(tabId, unified);
    // Clear CDP cache to avoid confusion
    snapshotManager.clearSnapshot(tabId);
    return unified;
  } catch (error) {
    // Strict silent mode: DO NOT fallback to CDP
    throw new Error(
      `Failed to create DOM snapshot in background mode: ${error instanceof Error ? error.message : "Unknown error"}. ` +
        `Please ensure the content script is loaded on this tab, or switch to focus mode.`,
    );
  }
}

CDP cache clearing on mode entry from `packages/browser-runtime/src/automation/snapshot-provider.ts:207-211`:

} else {
  console.log("🔍 [SnapshotProvider] Using CDP snapshot (focus mode)");
  // Clear DOM cache when using CDP mode
  domSnapshotCache.delete(tabId);
  return snapshotManager.createSnapshot(tabId);
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment