-
Notifications
You must be signed in to change notification settings - Fork 0
Fence browser observations by generation #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rgarcia
wants to merge
1
commit into
main
Choose a base branch
from
hypeship/browser-observation-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+388
−154
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /** Minimal CDP accessibility node used by browser observations. */ | ||
| export interface AXNode { | ||
| nodeId: string; | ||
| ignored?: boolean; | ||
| role?: { value?: string }; | ||
| name?: { value?: string }; | ||
| value?: { value?: unknown }; | ||
| properties?: Array<{ name: string; value?: { value?: unknown } }>; | ||
| backendDOMNodeId?: number; | ||
| parentId?: string; | ||
| childIds?: string[]; | ||
| } | ||
|
|
||
| /** Role/name cohort positions used when minting and healing refs. */ | ||
| export interface NthIndex { | ||
| index: Map<string, number>; | ||
| cohorts: Map<string, number>; | ||
| } | ||
|
|
||
| /** Frame and generation metadata required to render an observed node. */ | ||
| export interface RenderContext { | ||
| targetId: string; | ||
| frameKey: string; | ||
| sessionId: string; | ||
| generation: number; | ||
| interactiveOnly: boolean; | ||
| nthIndex: NthIndex; | ||
| cursorIds?: ReadonlySet<number>; | ||
| } | ||
|
|
||
| /** One normalized accessibility line before its ref is minted. */ | ||
| export interface ObservationLine { | ||
| text: string; | ||
| refNode?: AXNode; | ||
| ctx: RenderContext; | ||
| } | ||
|
|
||
| /** Accessibility tree collected for one stitched child frame. */ | ||
| export interface FrameStitch { | ||
| byId: Map<string, AXNode>; | ||
| roots: string[]; | ||
| ctx: RenderContext; | ||
| } | ||
|
|
||
| /** Accessibility node paired with its frame context. */ | ||
| export interface ObservedNode { | ||
| node: AXNode; | ||
| ctx: RenderContext; | ||
| } | ||
|
|
||
| /** Stable structured browser state collected before presentation filtering. */ | ||
| export interface BrowserObservation { | ||
| targetId: string; | ||
| tree: FrameStitch; | ||
| stitches: Map<number, FrameStitch>; | ||
| nodes: ObservedNode[]; | ||
| url: string; | ||
| title: string; | ||
| generations: Map<string, number>; | ||
| } | ||
|
|
||
| /** Render-ready projection of one structured browser observation. */ | ||
| export interface BrowserPresentation { | ||
| observation: BrowserObservation; | ||
| cacheKey: string; | ||
| lines: ObservationLine[]; | ||
| shape: string; | ||
| } | ||
|
|
||
| /** Signals that browser state changed while an observation was collected. */ | ||
| export class ObservationChangedError extends Error { | ||
| constructor(message = "Browser observation changed during collection") { | ||
| super(message); | ||
| this.name = "ObservationChangedError"; | ||
| } | ||
| } | ||
|
|
||
| /** Index each ref-eligible node by its position among nodes with the same role and name, in tree order. */ | ||
| export function buildNthIndex(nodes: AXNode[]): NthIndex { | ||
| const cohorts = new Map<string, number>(); | ||
| const index = new Map<string, number>(); | ||
| for (const node of nodes) { | ||
| if (node.ignored || node.backendDOMNodeId === undefined) continue; | ||
| const key = cohortKey(node.role?.value ?? "", node.name?.value ?? ""); | ||
| const nth = cohorts.get(key) ?? 0; | ||
| cohorts.set(key, nth + 1); | ||
| index.set(node.nodeId, nth); | ||
| } | ||
| return { index, cohorts }; | ||
| } | ||
|
|
||
| /** Build the stable key for a role/name ref-healing cohort. */ | ||
| export function cohortKey(role: string, name: string): string { | ||
| return `${role}\u0000${name}`; | ||
| } | ||
|
|
||
| /** Merge a run of two or more consecutive StaticText siblings (text split by inline markup) into one node. */ | ||
| export function staticTextRun(tree: Map<string, AXNode>, childIds: string[], start: number): { node: AXNode; end: number } | undefined { | ||
| let end = start; | ||
| const parts: string[] = []; | ||
| while (end < childIds.length) { | ||
| const node = tree.get(childIds[end]!); | ||
| if (!node || node.ignored || node.role?.value !== "StaticText") break; | ||
| const text = node.name?.value ?? ""; | ||
| if (text) parts.push(text); | ||
| end += 1; | ||
| } | ||
| if (end - start < 2) return undefined; | ||
| const first = tree.get(childIds[start]!)!; | ||
| return { node: { ...first, name: { value: parts.join(" ") }, childIds: [] }, end: end - 1 }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.