@orkestrel/browser 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,15 +2,6 @@ import { EmitterErrorHandler } from '@orkestrel/emitter';
2
2
  import { EmitterHooks } from '@orkestrel/emitter';
3
3
  import { EmitterInterface } from '@orkestrel/emitter';
4
4
 
5
- /**
6
- * Return the nearest-first ancestor chain for a captured browser node.
7
- *
8
- * @param snapshot - Captured browser snapshot
9
- * @param node - Descendant node
10
- * @returns Nearest-first ancestor list
11
- */
12
- export declare function ancestorsOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): readonly BrowserNode[];
13
-
14
5
  /**
15
6
  * Read one captured node attribute.
16
7
  *
@@ -58,7 +49,7 @@ export declare const BROWSER_FRAME_WORLD_NAME = "__orkestrelBrowserFrame";
58
49
  /** Tool identity embedded in HAR 1.2 documents. */
59
50
  export declare const BROWSER_HAR_CREATOR: Readonly<{
60
51
  name: "@orkestrel/browser";
61
- version: "0.0.5";
52
+ version: "0.0.8";
62
53
  }>;
63
54
 
64
55
  /** CDP Input modifier bit values keyed by canonical key name. */
@@ -741,6 +732,7 @@ export declare class BrowserFrame implements BrowserFrameInterface {
741
732
  get touch(): BrowserTouchInterface;
742
733
  title(): Promise<string>;
743
734
  content(): Promise<BrowserContentResult>;
735
+ article(): Promise<string>;
744
736
  click(selector: string, options?: BrowserActionOptions): Promise<void>;
745
737
  fill(selector: string, value: string, options?: BrowserActionOptions): Promise<void>;
746
738
  select(selector: string, values: readonly string[], options?: BrowserActionOptions): Promise<void>;
@@ -783,6 +775,7 @@ export declare interface BrowserFrameInfo {
783
775
  * - `url` — current frame URL
784
776
  * - `title` — resolve the document title
785
777
  * - `content` — extract page URL, title, HTML, and visible text
778
+ * - `article` — the page's reader-facing prose, boilerplate and hidden regions pruned (not `content()`'s whole-body text)
786
779
  * - `click` — click an element matching the selector
787
780
  * - `fill` — type text into an input element
788
781
  * - `select` — choose option(s) in a `<select>` element
@@ -801,6 +794,7 @@ export declare interface BrowserFrameInterface {
801
794
  readonly touch: BrowserTouchInterface;
802
795
  title(): Promise<string>;
803
796
  content(): Promise<BrowserContentResult>;
797
+ article(): Promise<string>;
804
798
  click(selector: string, options?: BrowserActionOptions): Promise<void>;
805
799
  fill(selector: string, value: string, options?: BrowserActionOptions): Promise<void>;
806
800
  select(selector: string, values: readonly string[], options?: BrowserActionOptions): Promise<void>;
@@ -1305,7 +1299,7 @@ export declare interface BrowserNode {
1305
1299
  readonly layout: BrowserLayout | undefined;
1306
1300
  }
1307
1301
 
1308
- /** Predicate used by browser snapshot traversal helpers. */
1302
+ /** Predicate form accepted by {@link BrowserSnapshotInterface} find, filter, and closest methods. */
1309
1303
  export declare type BrowserNodePredicate = (node: BrowserNode) => boolean;
1310
1304
 
1311
1305
  /**
@@ -1350,7 +1344,7 @@ export declare class BrowserPage extends BrowserFrame implements BrowserPageInte
1350
1344
  save(path: string, bytes: Uint8Array): Promise<void>;
1351
1345
  frame(name: string): Promise<BrowserFrameInterface | undefined>;
1352
1346
  frames(): Promise<readonly BrowserFrameInterface[]>;
1353
- snapshot(options?: BrowserSnapshotOptions): Promise<BrowserSnapshot>;
1347
+ snapshot(options?: BrowserSnapshotOptions): Promise<BrowserSnapshotInterface>;
1354
1348
  codegen(options?: BrowserCodegenOptions): Promise<BrowserCodegenInterface>;
1355
1349
  destroy(): Promise<void>;
1356
1350
  close(): Promise<void>;
@@ -1420,7 +1414,7 @@ export declare interface BrowserPageInterface extends BrowserFrameInterface {
1420
1414
  pdf(options?: BrowserPDFOptions): Promise<BrowserPDFResult>;
1421
1415
  frame(name: string): Promise<BrowserFrameInterface | undefined>;
1422
1416
  frames(): Promise<readonly BrowserFrameInterface[]>;
1423
- snapshot(options?: BrowserSnapshotOptions): Promise<BrowserSnapshot>;
1417
+ snapshot(options?: BrowserSnapshotOptions): Promise<BrowserSnapshotInterface>;
1424
1418
  codegen(options?: BrowserCodegenOptions): Promise<BrowserCodegenInterface>;
1425
1419
  destroy(): Promise<void>;
1426
1420
  close(): Promise<void>;
@@ -1812,14 +1806,56 @@ export declare interface BrowserSelectorManagerInterface {
1812
1806
  /** Resolve the current CDP session for a frame id. */
1813
1807
  export declare type BrowserSessionFunction = (frame: string) => Promise<string>;
1814
1808
 
1815
- /** A flattened, serializable snapshot of every document attached to a page. */
1816
- export declare interface BrowserSnapshot {
1809
+ /** Structural sibling relationship relative to a browser node. */
1810
+ export declare type BrowserSiblingRelation = 'preceding' | 'following';
1811
+
1812
+ /** A navigable, serializable browser DOM snapshot. */
1813
+ export declare class BrowserSnapshot implements BrowserSnapshotInterface {
1814
+ #private;
1815
+ readonly documents: readonly BrowserDocument[];
1816
+ readonly styles: readonly string[];
1817
+ constructor(input: BrowserSnapshotInput);
1818
+ walk(options?: BrowserWalkOptions): Generator<BrowserNode, void, unknown>;
1819
+ descendants(node: BrowserNode): Generator<BrowserNode, void, unknown>;
1820
+ document(node: BrowserNode): BrowserDocument | undefined;
1821
+ children(node: BrowserNode): readonly BrowserNode[];
1822
+ parent(node: BrowserNode): BrowserNode | undefined;
1823
+ siblings(node: BrowserNode, relation?: BrowserSiblingRelation): readonly BrowserNode[];
1824
+ ancestors(node: BrowserNode): readonly BrowserNode[];
1825
+ common(first: BrowserNode, second: BrowserNode): BrowserNode | undefined;
1826
+ distance(first: BrowserNode, second: BrowserNode): number | undefined;
1827
+ find(query: BrowserNodeQuery | BrowserNodePredicate): BrowserNode | undefined;
1828
+ filter(query: BrowserNodeQuery | BrowserNodePredicate, limit?: number): readonly BrowserNode[];
1829
+ closest(node: BrowserNode, query: BrowserNodeQuery | BrowserNodePredicate): BrowserNode | undefined;
1830
+ path(node: BrowserNode): string;
1831
+ }
1832
+
1833
+ /** Serializable input for a navigable browser snapshot. */
1834
+ export declare interface BrowserSnapshotInput {
1817
1835
  readonly documents: readonly BrowserDocument[];
1818
1836
  readonly styles: readonly string[];
1819
1837
  }
1820
1838
 
1839
+ /** A navigable, serializable snapshot of every document attached to a page. */
1840
+ export declare interface BrowserSnapshotInterface extends BrowserSnapshotInput {
1841
+ walk(options?: BrowserWalkOptions): Generator<BrowserNode, void, unknown>;
1842
+ descendants(node: BrowserNode): Generator<BrowserNode, void, unknown>;
1843
+ document(node: BrowserNode): BrowserDocument | undefined;
1844
+ children(node: BrowserNode): readonly BrowserNode[];
1845
+ parent(node: BrowserNode): BrowserNode | undefined;
1846
+ siblings(node: BrowserNode, relation?: BrowserSiblingRelation): readonly BrowserNode[];
1847
+ ancestors(node: BrowserNode): readonly BrowserNode[];
1848
+ common(first: BrowserNode, second: BrowserNode): BrowserNode | undefined;
1849
+ distance(first: BrowserNode, second: BrowserNode): number | undefined;
1850
+ find(query: BrowserNodeQuery | BrowserNodePredicate): BrowserNode | undefined;
1851
+ filter(query: BrowserNodeQuery | BrowserNodePredicate, limit?: number): readonly BrowserNode[];
1852
+ closest(node: BrowserNode, query: BrowserNodeQuery | BrowserNodePredicate): BrowserNode | undefined;
1853
+ path(node: BrowserNode): string;
1854
+ }
1855
+
1821
1856
  /**
1822
- * Options for capturing a browser DOM snapshot.
1857
+ * Options configuring capture through {@link BrowserPageInterface} `snapshot()`.
1858
+ * The snapshot entity's creation input is {@link BrowserSnapshotInput}.
1823
1859
  *
1824
1860
  * @remarks
1825
1861
  * - `styles` — computed CSS property names to capture
@@ -2011,6 +2047,21 @@ export declare type BrowserWaitState = 'attached' | 'detached' | 'visible' | 'hi
2011
2047
  /** Page load condition for navigation — the CDP load event awaited by `navigate()`. */
2012
2048
  export declare type BrowserWaitUntil = 'commit' | 'load' | 'domcontentloaded';
2013
2049
 
2050
+ /**
2051
+ * Options for walking a browser snapshot.
2052
+ *
2053
+ * @remarks
2054
+ * - `root` — optional subtree root, included in the walk
2055
+ * - `order` — structural traversal order, defaulting to depth-first
2056
+ */
2057
+ export declare interface BrowserWalkOptions {
2058
+ readonly root?: BrowserNode;
2059
+ readonly order?: BrowserWalkOrder;
2060
+ }
2061
+
2062
+ /** Structural ordering for a browser snapshot walk. */
2063
+ export declare type BrowserWalkOrder = 'depth' | 'breadth';
2064
+
2014
2065
  /**
2015
2066
  * Observable WebSocket connection reconstructed from Network-domain events.
2016
2067
  */
@@ -2239,39 +2290,6 @@ export declare interface CDPTransportInterface {
2239
2290
  close(): Promise<void>;
2240
2291
  }
2241
2292
 
2242
- /**
2243
- * Return direct children of a captured browser node.
2244
- *
2245
- * @remarks
2246
- * Includes the root nodes of an iframe's linked content document. Shadow DOM
2247
- * and template content already carry flattened parent indexes from CDP.
2248
- *
2249
- * @param snapshot - Captured browser snapshot
2250
- * @param node - Parent node
2251
- * @returns Direct children in snapshot order
2252
- */
2253
- export declare function childrenOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): readonly BrowserNode[];
2254
-
2255
- /**
2256
- * Find the nearest matching node from the candidate through its ancestors.
2257
- *
2258
- * @param snapshot - Captured browser snapshot
2259
- * @param node - Starting node, included in the search
2260
- * @param predicate - Node predicate
2261
- * @returns Closest matching node, or undefined
2262
- */
2263
- export declare function closestBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode, predicate: BrowserNodePredicate): BrowserNode | undefined;
2264
-
2265
- /**
2266
- * Resolve the nearest common ancestor of two captured browser nodes.
2267
- *
2268
- * @param snapshot - Captured browser snapshot
2269
- * @param first - First node
2270
- * @param second - Second node
2271
- * @returns Common ancestor, or undefined
2272
- */
2273
- export declare function commonAncestorOfBrowserNodes(snapshot: BrowserSnapshot, first: BrowserNode, second: BrowserNode): BrowserNode | undefined;
2274
-
2275
2293
  /**
2276
2294
  * Compile the element-side actionability pass used before trusted input.
2277
2295
  *
@@ -2491,16 +2509,6 @@ export declare function computeBrowserButtons(buttons: readonly BrowserMouseButt
2491
2509
  */
2492
2510
  export declare function computeBrowserModifiers(modifiers: readonly string[]): number;
2493
2511
 
2494
- /**
2495
- * Compute the edge count between two captured browser nodes.
2496
- *
2497
- * @param snapshot - Captured browser snapshot
2498
- * @param first - First node
2499
- * @param second - Second node
2500
- * @returns Tree distance, or undefined when no common ancestor exists
2501
- */
2502
- export declare function computeBrowserNodeDistance(snapshot: BrowserSnapshot, first: BrowserNode, second: BrowserNode): number | undefined;
2503
-
2504
2512
  /**
2505
2513
  * Concatenate byte chunks without Node-specific buffers.
2506
2514
  *
@@ -2528,6 +2536,22 @@ export declare function cookieToProtocol(cookie: BrowserCookieInput): Readonly<R
2528
2536
  */
2529
2537
  export declare function createBrowserHAREntry(pending: BrowserHARPending, duration: number, body?: Uint8Array, error?: string): BrowserHAREntry;
2530
2538
 
2539
+ /**
2540
+ * Create a navigable browser snapshot from decoded serializable data.
2541
+ *
2542
+ * @param input - Captured documents and computed-style names
2543
+ * @returns A {@link BrowserSnapshotInterface}
2544
+ *
2545
+ * @example
2546
+ * ```ts
2547
+ * import { createBrowserSnapshot, decodeBrowserSnapshot } from '@src/core'
2548
+ *
2549
+ * const snapshot = createBrowserSnapshot(decodeBrowserSnapshot(captured, ['display']))
2550
+ * snapshot.find({ name: 'main' })
2551
+ * ```
2552
+ */
2553
+ export declare function createBrowserSnapshot(input: BrowserSnapshotInput): BrowserSnapshotInterface;
2554
+
2531
2555
  /**
2532
2556
  * Create a CDP client bound to the given transport.
2533
2557
  *
@@ -2579,7 +2603,7 @@ export declare function decodeBrowserAttributes(value: unknown, strings: readonl
2579
2603
  * @param limit - Maximum accepted node count
2580
2604
  * @returns A typed serializable browser snapshot
2581
2605
  */
2582
- export declare function decodeBrowserSnapshot(value: unknown, styles?: readonly string[], limit?: number): BrowserSnapshot;
2606
+ export declare function decodeBrowserSnapshot(value: unknown, styles?: readonly string[], limit?: number): BrowserSnapshotInput;
2583
2607
 
2584
2608
  /**
2585
2609
  * Decode CDP snapshot sparse boolean data.
@@ -2606,24 +2630,6 @@ export declare function decodeRareIntegerData(value: unknown): ReadonlyMap<numbe
2606
2630
  */
2607
2631
  export declare function decodeRareStringData(value: unknown, strings: readonly string[]): ReadonlyMap<number, string>;
2608
2632
 
2609
- /**
2610
- * Lazily walk descendants of one captured node, excluding the node itself.
2611
- *
2612
- * @param snapshot - Captured browser snapshot
2613
- * @param root - Root whose descendants are required
2614
- * @returns A lazy descendant generator
2615
- */
2616
- export declare function descendantsOfBrowserNode(snapshot: BrowserSnapshot, root: BrowserNode): Generator<BrowserNode, void, unknown>;
2617
-
2618
- /**
2619
- * Resolve the document containing a browser node.
2620
- *
2621
- * @param snapshot - Captured browser snapshot
2622
- * @param node - Node whose document is required
2623
- * @returns The containing document, or undefined
2624
- */
2625
- export declare function documentOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): BrowserDocument | undefined;
2626
-
2627
2633
  /**
2628
2634
  * Encode raw bytes as base64 without relying on Node or DOM globals.
2629
2635
  *
@@ -2632,44 +2638,6 @@ export declare function documentOfBrowserNode(snapshot: BrowserSnapshot, node: B
2632
2638
  */
2633
2639
  export declare function encodeBase64(bytes: Uint8Array): string;
2634
2640
 
2635
- /**
2636
- * Find the first matching descendant beneath one captured node.
2637
- *
2638
- * @param snapshot - Captured browser snapshot
2639
- * @param root - Root whose descendants are searched
2640
- * @param predicate - Node predicate
2641
- * @returns First matching descendant, or undefined
2642
- */
2643
- export declare function findBrowserDescendant(snapshot: BrowserSnapshot, root: BrowserNode, predicate: BrowserNodePredicate): BrowserNode | undefined;
2644
-
2645
- /**
2646
- * Find the first captured node satisfying a predicate.
2647
- *
2648
- * @param snapshot - Captured browser snapshot
2649
- * @param predicate - Node predicate
2650
- * @returns First matching node, or undefined
2651
- */
2652
- export declare function findBrowserNode(snapshot: BrowserSnapshot, predicate: BrowserNodePredicate): BrowserNode | undefined;
2653
-
2654
- /**
2655
- * Find captured nodes satisfying a predicate.
2656
- *
2657
- * @param snapshot - Captured browser snapshot
2658
- * @param predicate - Node predicate
2659
- * @param limit - Optional maximum result count
2660
- * @returns Matching nodes in snapshot order
2661
- */
2662
- export declare function findBrowserNodes(snapshot: BrowserSnapshot, predicate: BrowserNodePredicate, limit?: number): readonly BrowserNode[];
2663
-
2664
- /**
2665
- * Return structural siblings after the supplied browser node.
2666
- *
2667
- * @param snapshot - Captured browser snapshot
2668
- * @param node - Reference node
2669
- * @returns Later siblings in structural order
2670
- */
2671
- export declare function followingSiblingsOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): readonly BrowserNode[];
2672
-
2673
2641
  /**
2674
2642
  * Wrap a `Runtime.evaluate` expression so the IN-PAGE code stringifies its
2675
2643
  * own result and throws a recognizable error before an oversized result
@@ -2703,14 +2671,20 @@ export declare function guardEvaluateExpression(expression: string, limit: numbe
2703
2671
  export declare function isBrowserError(value: unknown): value is BrowserError;
2704
2672
 
2705
2673
  /**
2706
- * Test whether one captured node is below another across frame boundaries.
2674
+ * Test whether a browser-node matcher is a declarative query.
2675
+ *
2676
+ * @param value - Browser-node query or predicate
2677
+ * @returns Whether the matcher is a declarative query
2707
2678
  *
2708
- * @param snapshot - Captured browser snapshot
2709
- * @param node - Candidate descendant
2710
- * @param ancestor - Candidate ancestor
2711
- * @returns Whether the relationship exists
2679
+ * @example
2680
+ * ```ts
2681
+ * import { isBrowserNodeQuery } from '@src/core'
2682
+ *
2683
+ * isBrowserNodeQuery({ name: 'main' }) // true
2684
+ * isBrowserNodeQuery(() => true) // false
2685
+ * ```
2712
2686
  */
2713
- export declare function isBrowserNodeDescendant(snapshot: BrowserSnapshot, node: BrowserNode, ancestor: BrowserNode): boolean;
2687
+ export declare function isBrowserNodeQuery(value: BrowserNodeQuery | BrowserNodePredicate): value is BrowserNodeQuery;
2714
2688
 
2715
2689
  /**
2716
2690
  * Test whether a captured node has a non-empty rendered layout box.
@@ -2812,15 +2786,6 @@ export declare function matchesBrowserURL(url: string, pattern: string): boolean
2812
2786
  */
2813
2787
  export declare function mediaToFeatures(media: BrowserMedia): readonly Readonly<Record<string, string>>[];
2814
2788
 
2815
- /**
2816
- * Build a deterministic, serializable path for a captured browser node.
2817
- *
2818
- * @param snapshot - Captured browser snapshot
2819
- * @param node - Captured browser node
2820
- * @returns Frame-qualified structural path
2821
- */
2822
- export declare function nodeToPath(snapshot: BrowserSnapshot, node: BrowserNode): string;
2823
-
2824
2789
  /**
2825
2790
  * Normalize a raw list of recorded codegen actions.
2826
2791
  *
@@ -2835,18 +2800,6 @@ export declare function nodeToPath(snapshot: BrowserSnapshot, node: BrowserNode)
2835
2800
  */
2836
2801
  export declare function normalizeCodegenActions(actions: readonly BrowserCodegenAction[]): readonly BrowserCodegenAction[];
2837
2802
 
2838
- /**
2839
- * Resolve the structural parent of a captured browser node.
2840
- *
2841
- * @remarks
2842
- * An iframe content-document root resolves to its owning iframe node.
2843
- *
2844
- * @param snapshot - Captured browser snapshot
2845
- * @param node - Child node
2846
- * @returns Parent node, or undefined for a top-level document root
2847
- */
2848
- export declare function parentOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): BrowserNode | undefined;
2849
-
2850
2803
  /**
2851
2804
  * Parse a keyboard chord such as `Control+Shift+P`.
2852
2805
  *
@@ -2868,15 +2821,6 @@ export declare function parseBrowserChord(value: string): BrowserChord;
2868
2821
  */
2869
2822
  export declare function parseCodegenActionPayload(payload: unknown): BrowserCodegenAction | undefined;
2870
2823
 
2871
- /**
2872
- * Return structural siblings before the supplied browser node.
2873
- *
2874
- * @param snapshot - Captured browser snapshot
2875
- * @param node - Reference node
2876
- * @returns Earlier siblings in structural order
2877
- */
2878
- export declare function precedingSiblingsOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): readonly BrowserNode[];
2879
-
2880
2824
  /**
2881
2825
  * Decode Accessibility-domain nodes into a flat serializable tree.
2882
2826
  *
@@ -3228,15 +3172,6 @@ export declare interface ScreenshotWriterInterface {
3228
3172
  write(path: string, data: Uint8Array): Promise<void>;
3229
3173
  }
3230
3174
 
3231
- /**
3232
- * Return every structural sibling except the supplied browser node.
3233
- *
3234
- * @param snapshot - Captured browser snapshot
3235
- * @param node - Node whose siblings are required
3236
- * @returns Siblings in structural order
3237
- */
3238
- export declare function siblingsOfBrowserNode(snapshot: BrowserSnapshot, node: BrowserNode): readonly BrowserNode[];
3239
-
3240
3175
  /** Encode UTF-8 text as bytes. */
3241
3176
  export declare function textToBytes(value: string): Uint8Array;
3242
3177
 
@@ -3307,42 +3242,4 @@ export declare function validateBrowserTimeout(timeout: number): void;
3307
3242
  */
3308
3243
  export declare function validateBrowserViewport(viewport: BrowserViewport): void;
3309
3244
 
3310
- /**
3311
- * Lazily walk one captured browser-node subtree in depth-first order.
3312
- *
3313
- * @param snapshot - Captured browser snapshot
3314
- * @param root - Root node, included as the first result
3315
- * @returns A lazy subtree generator
3316
- */
3317
- export declare function walkBrowserNode(snapshot: BrowserSnapshot, root: BrowserNode): Generator<BrowserNode, void, unknown>;
3318
-
3319
- /**
3320
- * Lazily walk one captured browser-node subtree in breadth-first order.
3321
- *
3322
- * @param snapshot - Captured browser snapshot
3323
- * @param root - Root node, included as the first result
3324
- * @returns A lazy breadth-first subtree generator
3325
- */
3326
- export declare function walkBrowserNodeBreadthFirst(snapshot: BrowserSnapshot, root: BrowserNode): Generator<BrowserNode, void, unknown>;
3327
-
3328
- /**
3329
- * Lazily walk every captured browser node in structural depth-first order.
3330
- *
3331
- * @remarks
3332
- * Iframe content documents are entered at their owner element. Orphaned or
3333
- * cyclic protocol nodes are still yielded once through an identity guard.
3334
- *
3335
- * @param snapshot - Captured browser snapshot
3336
- * @returns A lazy node generator
3337
- */
3338
- export declare function walkBrowserSnapshot(snapshot: BrowserSnapshot): Generator<BrowserNode, void, unknown>;
3339
-
3340
- /**
3341
- * Lazily walk every captured node in structural breadth-first order.
3342
- *
3343
- * @param snapshot - Captured browser snapshot
3344
- * @returns A lazy breadth-first generator
3345
- */
3346
- export declare function walkBrowserSnapshotBreadthFirst(snapshot: BrowserSnapshot): Generator<BrowserNode, void, unknown>;
3347
-
3348
3245
  export { }