Skip to content

Add wait, mutation waits and whenBusy to web detection - #3237

Draft
GuiltyDolphin wants to merge 4 commits into
gd-c-web-detection-generator-evaluatorfrom
gd-c-web-detection-wait
Draft

GuiltyDolphin wants to merge 4 commits into
gd-c-web-detection-generator-evaluatorfrom
gd-c-web-detection-wait

Conversation

@GuiltyDolphin

@GuiltyDolphin GuiltyDolphin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Asana Task/Github Issue: https://app.asana.com/1/137249556945/task/1220838330987911

Description

Builds on #3236.

This adds wait, the first source that suspends a run, so a detector can see what happens after an arrival in the run it started:

  • wait gives the first item to arrive after the wait starts that passes its where (with field read from it), or undefined once timeoutMs passes. timeoutMs is required (a number, or null for no timeout), as the config build writes the default
  • a body with no target waits on the recorder its type registers at init. With a target, evaluated when the wait starts, it adds a listener of its own, or for mutation a MutationObserver of its own with the body's options, which it removes when the wait ends. MutationObserver is captured with the other recorder globals, and each record gets timeStamp from when the callback ran. A target that isn't an event target, or for mutation a node, fails the wait at its target straight away. An engine without MutationObserver gives no item, so the wait resumes at timeoutMs
  • where is tested on each item as it arrives, in the task that recorded it. An arrival with no item passing leaves the run suspended. A resumed run reads the page through the frame's read cache, so a change made while it was suspended clears what it read before
  • a detector has one run at a time. While one is suspended, an arrival on an on body queues a run behind it (whenBusy: "queue", the default), abandons it and runs ("interrupt"), or is skipped ("skip"). Queued runs run in order after it ends. An abandoned run's detector names and dones stand, and the debug notification records aborted. auto and breakage report runs queue
  • detectorPerf: record takes a slice kind. A run is counted at its first slice, a later slice that moves it forward adds to its run total, and a wait miss (an arrival with no item passing) adds to every total but the run's. over<N>ms, worstMs and single-run severe use the run total. Detectors whose runs suspended get worstSliceMs, waitMisses and waitMissMs in breakage reports. Each callback and timeout that tests or resumes a run is a dispatch of its own. A slice that ends its run on a failure or an error is a failed run.

wait goes where layer 3 allows a run to suspend: a sequence, an if, expr, beside using, or an action's value, in actions.

Testing Steps

  • unit tests cover resuming with the next item, where misses, the timeout, items from before the wait, a target's own listener, mutation waits, a failed target, and one it can't listen on or observe, whenBusy queue, skip and interrupt (with done held before the wait), the slice kinds and dispatches recorded, a resumed run that ends on a failure being recorded as failed, and parse errors
  • detectorPerf unit tests follow the "page event with a wait" timeline: one run, its total across the slices that move it forward, wait misses in the accumulated totals only, an edge crossed at the slice whose run total crosses it
  • integration tests click a real page: a sync run's mutation wait sees the change the page makes in its own click handler, and resumes with nothing at its timeout when there's none

Checklist

Please tick all that apply:

  • I have tested this change locally
  • I have tested this change locally in all supported browsers
  • This change will be visible to users
  • I have added automated tests that cover this change
  • I have ensured the change is gated by config
  • This change was covered by a ship review
  • This change was covered by a tech design
  • Any dependent config has been merged

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Build Branch

Branch pr-releases/gd-c-web-detection-wait
Commit 11cc5d22c5
Updated November 30, 2026 at 12:58:18 PM UTC

Static preview entry points

QR codes (mobile preview)
Entry point QR code
Docs QR for docs preview
Static pages QR for static pages preview
Integration pages QR for integration pages preview

Integration commands

npm (Android / Extension):

npm i github:duckduckgo/content-scope-scripts#pr-releases/gd-c-web-detection-wait

Swift Package Manager (Apple):

.package(url: "https://github.com/duckduckgo/content-scope-scripts.git", branch: "pr-releases/gd-c-web-detection-wait")

git submodule (Windows):

git -C submodules/content-scope-scripts fetch origin pr-releases/gd-c-web-detection-wait
git -C submodules/content-scope-scripts checkout origin/pr-releases/gd-c-web-detection-wait
Pin to exact commit

npm (Android / Extension):

npm i github:duckduckgo/content-scope-scripts#11cc5d22c54112c53928c3e9a696df6be7c41220

Swift Package Manager (Apple):

.package(url: "https://github.com/duckduckgo/content-scope-scripts.git", revision: "11cc5d22c54112c53928c3e9a696df6be7c41220")

git submodule (Windows):

git -C submodules/content-scope-scripts fetch origin pr-releases/gd-c-web-detection-wait
git -C submodules/content-scope-scripts checkout 11cc5d22c54112c53928c3e9a696df6be7c41220

@github-actions github-actions Bot added the semver-minor New feature — triggers minor version bump label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

[Beta] Generated file diff

Time updated: Mon, 30 Nov 2026 12:59:24 GMT

Android
    - android/adsjsContentScope.js
  • android/contentScope.js

File has changed

Apple
    - apple/contentScopeIsolated.js

File has changed

Chrome-mv3
    - chrome-mv3/inject.js

File has changed

Firefox
    - firefox/inject.js

File has changed

Integration
    - integration/contentScope.js

File has changed

Windows
    - windows/contentScope.js

File has changed

GuiltyDolphin and others added 4 commits November 30, 2026 12:28
This adds the wait source, which suspends a run until the next item arrives at a recorder, a target's own listener or a mutation observer, or until timeoutMs passes. A detector has one run at a time, and an arrival while it's suspended queues a run, abandons it or is skipped, as its on body's whenBusy sets. detectorPerf times each slice of a run and counts wait misses apart from the run's total.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This lets an arrival's whenPending act on a run queued behind a suspended run, as on one waiting for its delayMs timer, so with whenBusy "queue" and whenPending "skip" or "batch" a detector has one run queued at most.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A wait whose target wasn't a node or event target waited silently until timeoutMs, which read as no change on the page. The wait now fails at its target straight away, as a root that isn't a node fails. An engine with no MutationObserver or listener methods still gives no item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A slice that ends its run on a failure is timed as failed, as one that ends on an error is, so a resumed run counts towards detectorPerf_<group>_failed the same way a run that never suspends does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GuiltyDolphin
GuiltyDolphin force-pushed the gd-c-web-detection-wait branch from d0e62f5 to 4662820 Compare November 30, 2026 12:57

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-minor New feature — triggers minor version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant