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

Implementation:AIPexStudio AIPex getAutomationMode

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

Overview

Concrete helper functions that read the user-selected automation mode from Chrome storage, returning "focus" (CDP) or "background" (DOM-only).

Description

The getAutomationMode function reads `STORAGE_KEYS.AUTOMATION_MODE` from Chrome storage via `ChromeStorageAdapter`, validates the value with `validateAutomationMode`, and returns the mode. It defaults to "focus" on error. The isFocusMode and isBackgroundMode functions are convenience wrappers. The automation mode determines whether the system uses CDP (debugger attachment, screenshots, visual effects) or pure DOM scripting (silent, no debugger).

Usage

  • Select snapshot backend: `const mode = await getAutomationMode()` then branch on "focus" vs "background".
  • Check mode: `if (await isBackgroundMode()) { /* skip screenshot */ }`
  • Used throughout snapshot-provider, screenshot tools, and automation layers.

Code Reference

Source Location

  • Repository: AIPex
  • File: packages/browser-runtime/src/runtime/automation-mode.ts
  • Lines: L22-49

Signature

export async function getAutomationMode(): Promise<AutomationMode>
export async function isFocusMode(): Promise<boolean>
export async function isBackgroundMode(): Promise<boolean>

type AutomationMode = "focus" | "background"

Import

import { getAutomationMode, isFocusMode, isBackgroundMode } from "@aipexstudio/browser-runtime";

I/O Contract

Inputs

Name Type Required Description
(none) — — Reads from Chrome storage internally

Outputs

Name Type Description
returns AutomationMode "focus" or "background"

Usage Examples

Mode-Based Branching

import { getAutomationMode } from "@aipexstudio/browser-runtime";

const mode = await getAutomationMode();

if (mode === "focus") {
  // Use CDP: attach debugger, capture AX tree
  const snapshot = await snapshotManager.createSnapshot(tabId);
} else {
  // Use DOM: inject content script, traverse DOM
  const snapshot = await requestDomSnapshot(tabId);
}

Guard Screenshot in Background

import { isBackgroundMode } from "@aipexstudio/browser-runtime";

if (await isBackgroundMode()) {
  throw new Error("Screenshots disabled in background mode");
}

Related Pages

Implements Principle

Uses Heuristics

Requires Environment

Page Connections

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