Skip to content

Add the observe trigger, observed and trigger sources, and done to web detection - #3235

Draft
GuiltyDolphin wants to merge 2 commits into
gd-c-web-detection-dispatch-totalsfrom
gd-c-web-detection-observe
Draft

GuiltyDolphin wants to merge 2 commits into
gd-c-web-detection-dispatch-totalsfrom
gd-c-web-detection-observe

Conversation

@GuiltyDolphin

@GuiltyDolphin GuiltyDolphin commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

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

Description

Builds on #3234.

Detectors run only on an auto timer or a breakage report today. This lets them run when something arrives on the page, such as a click or a batch of long animation frames, and read what arrived:

  • recorders: one PerformanceObserver per entry type (buffered: true, with durationThreshold the lowest any body reading event entries states), and one capture, passive listener per event type and target. Only trusted events are recorded. They use PerformanceObserver, supportedEntryTypes and EventTarget.prototype's listener methods captured when the feature is constructed, and the reader captures the getters of the entry and event prototypes
  • the observe trigger, disabled by default: each on body names a type, with delayMs (default 0) or sync (event bodies only, run in the listener). An arrival schedules a run per detector whose on body gives an item from it, and detectors due at the same delay run in one task as one dispatch, reading the page through the frame's read cache
  • the observed source reads a recorder's log over the body's keep window (count, withinMs, both, or null for everything). A log is kept only while an observed body reads it, and drops from the front what no window reaches. keep is required, as the config build writes the default
  • the trigger source reads the arrival that started the run, or one item for auto and breakageReport runs, and gives no items for a body naming another type. Without field it's a condition leaf, as element is
  • the done action makes the detector done at the end of the run when its value is true or a list with an item. A done that held stays in effect if the run fails later. Once done, its observed bodies leave their logs, it stops observing, and a recorder nothing uses any more disconnects
  • an event's target is pinned at dispatch, so a run reads it after dispatch even when it's in a shadow tree

Recorders register at init, not load, since load runs on sites where the feature is off. A target is evaluated once at registration, and one that isn't an object registers nothing. A trigger body reads the recorder an on body registered and registers none of its own.

C-S-S takes any entry type, event type, field and target. What config may use is restricted by the privacy-configuration validator.

Testing Steps

  • unit tests cover log windows and dropping, parse errors, delayMs and sync runs, where on on bodies, observed windows, the pinned target, trigger for other types and for auto and breakage report runs, done (holding, held before a failure, not holding), shared listeners, explicit targets, and entry recorders (threshold, batches, the 104 ms default, unsupported types, disconnecting when done)
  • integration tests click a real page: a detector runs on each trusted click until it's done, and ignores a click a page script dispatches

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-observe
Commit dc4dc9ec46
Updated November 30, 2026 at 12:58:06 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-observe

Swift Package Manager (Apple):

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

git submodule (Windows):

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

npm (Android / Extension):

npm i github:duckduckgo/content-scope-scripts#dc4dc9ec46b7caa7ddbe88fbc52d43254408a5ea

Swift Package Manager (Apple):

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

git submodule (Windows):

git -C submodules/content-scope-scripts fetch origin pr-releases/gd-c-web-detection-observe
git -C submodules/content-scope-scripts checkout dc4dc9ec46b7caa7ddbe88fbc52d43254408a5ea

@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:32 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 2 commits November 30, 2026 12:28
…b detection

This adds recorders for performance entry types and trusted events, registered at init with captured globals. The observe trigger runs a detector when an item it names arrives, after delayMs or in the listener with sync, and the trigger and observed sources read the arrival and the log over each body's keep window. The done action ends a detector with no match, which releases its recorders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This sets what an arrival does while a run of the detector is pending: schedule its own run (the default), skip, batch its items into the pending run, or replace it with its own. A batched run's trigger reads each arrival under its own recorder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GuiltyDolphin
GuiltyDolphin force-pushed the gd-c-web-detection-observe branch from d3f3ddd to d639d40 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