Goal: user explicitly enables a dedicated background Teams collector tab which traverses discovered chat rows, captures messages and bounded history, repeats without taking over the user's normal Teams tab. Opening chats can change read state; disclose this beside enable/start UI. No sending messages, token extraction or private endpoint replay.
config.automation = {enabled:false, intervalSeconds:120, dwellSeconds:4, maxChats:50, listScrollPasses:8, historyScrollPasses:2, chatItemSelector:'', chatListSelector:'', messageListSelector:''}.
Validate integers: interval30..3600, dwell2..30, maxChats1..200, listScrollPasses0..30, historyScrollPasses0..20; selectors max2000 chars. Existing saved configs without automation use defaults. publicConfig includes settings but always forces assigned:false; background GET_CONFIG overrides assigned=true only for its extension-created collector tab. Main config.enabled must also be true.
Background owns one dedicated tab and persists its id/accountId in chrome.storage.session, surviving service worker suspension. Create at an allowed existing Teams tab's origin (fallback https://teams.cloud.microsoft/), active:false. Never reuse a user's tab as the collector, never call tabs.update(active:true) or window focus. SAVE_CONFIG with automation.enabled=true creates/reuses this dedicated tab; false, main disabled, account change, non-Teams navigation or tab closure cancels assignment and stops crawler. User's normal tabs continue passive capture. START_AUTOMATION/STOP_AUTOMATION trusted extension page actions may set the enabled flag; GET_STATE returns automation state and config. On browser/extension startup, explicitly saved enabled mode can create a fresh collector. Opening popup must not create duplicates. Closing collector disables automatic mode instead of immediately recreating it.
automation.collectorTab defaults false in public config; GET_CONFIG sets it only for the saved owner tab, including after STOP when assigned=false. Content latches this classification for its lifetime and never falls back to passive collection in the dedicated tab. Account changes discard the old owner and its pending queue; the old content instance stays passive-suppressed until replaced.
GET_CONFIG includes {...publicConfig(settings),automation:{...settings.automation,assigned:<verified sender tab>}}. REPORT_AUTOMATION from a Teams content script is accepted only from the assigned collector tab with matching config account; normalized status stored as status.automation for popup/options. Payload {accountId,status}. Status has no message content; fields {running,phase,visited,discovered,pass,nextRunAt,error,coverage} with bounded integers/strings and timestamps. Stop/error pause must not trigger infinite reconnect loop.
Export createChatCrawler({window,document,capture,report,wait?,now?}). All DOM/navigation stays here; no Chrome API calls. capture() returns Promise<{ok:boolean,pending:number,records:number}> using normal content queue and authenticated backend. report(status) receives above status fields.
Return methods:
configure(options) updates automation config including assigned and main enabled passed as options.enabled; cancels active pass if identity/options differ; must not repeatedly cancel unchanged settings.tick() starts a due pass if enabled+assigned, returns quickly when already running/not due; resolves when pass finishes. First pass starts immediately.stop(reason?) cancels waits/navigation immediately; no automatic retry of fatal/interaction pause until reconfigured/reconnected by user.status() current status.isNavigating() true during transitions/scroll settling when passive scans must be suspended.dispose() stops and removes listeners.preview() read-only discovery summary {count,labels,errors} for diagnosing chat row selectors.Implemented additions: preview(overrideOptions?) accepts unsaved selector drafts; messageSelector is forwarded from the existing parser's saved message selector. captureContext() returns {id,title,root} only while the same verified message pane is valid. The DOM root stays inside the content runtime and is never sent in diagnostics or persisted. The parser uses it to limit automatic capture to that pane's messages, excluding other panes and calendar/activity cards.
Discovery uses narrow Teams chat-list row candidates, excludes menu/action buttons/navigation app bar/composer; supports custom row/list/message-list CSS selectors. Enumerate virtualized sidebar by bounded scrolling, store stable row identity, re-find DOM row before clicking (never retain detached references). Work only on one dedicated tab. Default max50 chats per pass and2 history scrolls; max limits explicitly in coverage. Repeated pass starts after interval from completion; scan all found up to cap, not full archive guarantee.
Before opening another chat, flush pending captured queue; on failure or nonempty pending after bounded draining, stop and show error. After click, require evidence selection/pane changed plus stable message/pane rendering for dwell interval; never capture stale old-message DOM under new title. Empty/unrecognized chat can be skipped with explicit coverage/error rather than asserted complete. Suppress passive content scan during transitions via isNavigating. Scroll only identified message list; no whole-page history scrolling. Capture at each settled history step, drain queue before next chat. Stop on trusted user pointer/keyboard input in collector tab; own synthetic clicks do not trigger this.
Content runtime owns crawler instance, reports via REPORT_AUTOMATION with current account. On config update calls configure({...config.automation,enabled:config.enabled&&config.automation.enabled}). Existing observer/20s heartbeat invokes crawler.tick when assigned; all passive scans are suppressed for dedicated collector instances, including after pause/disable. Crawler callback calls scan({fromCrawler:true}), which returns delivery result; manual scans in ordinary tabs keep existing behavior. If captureContext is null during pre-navigation queue draining, flush only already queued records without parsing DOM. Verified capture is required after settling; each pass goes to the latest message viewport before bounded upward history scrolling. Interrupted transition message identities remain excluded across pause/resume until a new view is verified. Dispose cancels crawler. PROBE can expose automation state; PREVIEW_CHATS triggers crawler.preview read-only, for trusted background messages.
CONFIG_CHANGED may carry resumeAutomation:true only for an explicit trusted start/save/reconnect action. Startup, service worker wakes, and tab-load refreshes must not resume an interaction/error pause. Crawler also exposes resume() for that explicit action and captureContext() for the verified local conversation identity, which stays out of diagnostic reports.
Root owns content-runtime.js integration, server/UI/docs, and overall tests. Crawler worker owns chat-crawler.js + tests/chat-crawler.test.js. Background/UI worker owns background-runtime.js, config.js, manifest.json, options., popup., extension/style.css and its own automation tests. No cross-owner edits.