browserscale-ts 1.3.0 → 1.5.0

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.
package/dist/client.js CHANGED
@@ -2,10 +2,10 @@ import { createClient } from "@connectrpc/connect";
2
2
  import { create } from "@bufbuild/protobuf";
3
3
  import { Browser,
4
4
  // request / response schemas
5
- SetProxyRequestSchema, GetPagesRequestSchema, NavigateRequestSchema, LoadHTMLRequestSchema, EvaluateRequestSchema, WaitForAnyParamsSchema, WaitConditionSchema, ClickRequestSchema, FillRequestSchema, MoveToRequestSchema, ScrollToRequestSchema, DragRequestSchema, SelectOptionRequestSchema, GetDOMRequestSchema, GetDOMHashRequestSchema, GetObservationRequestSchema, ScreenshotRequestSchema, ReadCanvasRequestSchema, SetBlockListRequestSchema, SetStaticPathsRequestSchema, WaitForAnyRequestRequestSchema, WaitForAnyResponseRequestSchema, ModifyRequestRequestSchema, GetCookiesRequestSchema, SetCookiesRequestSchema, ClearCookiesRequestSchema, GetStorageRequestSchema, SetStorageRequestSchema, ClearStorageRequestSchema, InspectAtPositionRequestSchema, HighlightNodeRequestSchema, InsertTextRequestSchema, TypeRequestSchema, PressKeyRequestSchema, ReleaseKeyRequestSchema, GetSelectionRequestSchema, SolveCaptchaRequestSchema, GetStreamConfigRequestSchema, StartStreamRequestSchema, StopStreamRequestSchema, AddReactionRequestSchema, RemoveReactionRequestSchema, ListReactionsRequestSchema, } from "./gen/wrc_pb.js";
5
+ SetProxyRequestSchema, GetPagesRequestSchema, NavigateRequestSchema, LoadHTMLRequestSchema, EvaluateRequestSchema, WaitForAnyParamsSchema, WaitConditionSchema, ClickRequestSchema, FillRequestSchema, MoveToRequestSchema, ScrollToRequestSchema, DragRequestSchema, SelectOptionRequestSchema, GetDOMRequestSchema, GetDOMHashRequestSchema, GetObservationRequestSchema, ScreenshotRequestSchema, ReadCanvasRequestSchema, SetBlockListRequestSchema, SetStaticPathsRequestSchema, WaitForAnyRequestRequestSchema, WaitForAnyResponseRequestSchema, ModifyRequestRequestSchema, GetCookiesRequestSchema, SetCookiesRequestSchema, ClearCookiesRequestSchema, GetStorageRequestSchema, SetStorageRequestSchema, ClearStorageRequestSchema, GetAuthSessionRequestSchema, SetAuthSessionRequestSchema, InspectAtPositionRequestSchema, HighlightNodeRequestSchema, InsertTextRequestSchema, TypeRequestSchema, PressKeyRequestSchema, ReleaseKeyRequestSchema, GetSelectionRequestSchema, SolveCaptchaRequestSchema, GetStreamConfigRequestSchema, StartStreamRequestSchema, StopStreamRequestSchema, AddReactionRequestSchema, RemoveReactionRequestSchema, ListReactionsRequestSchema, } from "./gen/wrc_pb.js";
6
6
  import { DefaultWaitTimeoutMs } from "./defaults.js";
7
7
  import { BrowserScaleError } from "./errors.js";
8
- import { cookieParamFromProto, cookieParamsToProto, elementFields, headerModsToProto, headersToProto, interceptedRequestFromProto, interceptedResponseFromProto, pageInfoFromProto, rectFromProto, splitRequestPatterns, storageEntriesToProto, storageEntryFromProto, unwrapClick, unwrapDrag, unwrapFill, unwrapMove, unwrapScroll, unwrapSelect, unwrapWait, } from "./internal/convert.js";
8
+ import { authSessionFromProto, authSessionToProto, cookieParamFromProto, cookieParamsToProto, elementFields, headerModsToProto, headersToProto, interceptedRequestFromProto, interceptedResponseFromProto, pageInfoFromProto, rectFromProto, splitRequestPatterns, storageEntriesToProto, storageEntryFromProto, unwrapClick, unwrapDrag, unwrapFill, unwrapMove, unwrapScroll, unwrapSelect, unwrapWait, } from "./internal/convert.js";
9
9
  /**
10
10
  * CloudBrowser is the SDK-side handle for an active browserscale browser session.
11
11
  *
@@ -705,38 +705,70 @@ export class CloudBrowser {
705
705
  return resp.hash;
706
706
  }
707
707
  /**
708
- * Returns a compact, agent-friendly description of every interactable
709
- * element currently visible on the page, together with a truncated view
710
- * of the surrounding text.
708
+ * Returns a compact, frame-aware view of the visible page — the first thing
709
+ * to reach for on an unfamiliar page, and the cheapest way to re-read the
710
+ * current state afterwards.
711
711
  *
712
- * Intended as input for LLM/agent loops where a full DOM dump would be
713
- * too large; the server filters down to elements that are actually
714
- * visible and interactable.
712
+ * Each frame opens with header lines carrying the URL, the title and the
713
+ * scroll position, then one line per visible element:
715
714
  *
716
- * @param opts - optional caps: `maxElementsPerFrame`, `maxTextLength`;
717
- * omit either to use the server default
715
+ * ```
716
+ * input#email[47] type="email" name="loginId" value="a@b.com" required click "E-Mail"
717
+ * ```
718
718
  *
719
- * @returns ObservationResult with both a human-readable `text` rendering
720
- * and a `json` payload of the structured observation
719
+ * It spans every frame, pierces open and closed shadow roots, enumerates
720
+ * `<select>` options, and reports live form state: `value=` is what is typed
721
+ * in right now (passwords as a length), `checked=` for boxes. The trailing
722
+ * quoted string is always the label or text, never the value, so an empty and
723
+ * a prefilled field stay distinguishable. Because the headers already carry
724
+ * URL, title and scroll offset, this replaces the usual handful of
725
+ * {@link evaluate} probes after each step.
726
+ *
727
+ * On what to do with the result: backendNodeId (the `47` above) is a handle
728
+ * for this session and can be passed straight to click/fill via
729
+ * {@link node}. It does not survive a new document, so for anything you write
730
+ * into a script, target with {@link css} or {@link js} instead — those calls
731
+ * return the backendNodeId they resolved to, which lets you confirm the
732
+ * durable anchor hits the element you saw.
733
+ *
734
+ * @param opts - optional format and budget overrides; see {@link GetObservationOpts}
735
+ *
736
+ * @returns the observation in the requested format, ready to hand to a model
721
737
  *
722
738
  * @throws UNKNOWN_ERROR - the observation could not be produced
723
739
  *
724
740
  * @example
725
- * const obs = await browser.getObservation({ maxElementsPerFrame: 200 });
726
- * console.log(obs.text);
741
+ * const obs = await browser.getObservation();
742
+ * console.log(obs);
727
743
  */
728
744
  async getObservation(opts) {
729
745
  const req = create(GetObservationRequestSchema, {
730
746
  sessionId: this.sessionId,
731
747
  apiKey: this.apiKey,
732
748
  });
749
+ if (opts?.format !== undefined)
750
+ req.format = opts.format;
733
751
  if (opts?.maxElementsPerFrame !== undefined) {
734
752
  req.maxElementsPerFrame = opts.maxElementsPerFrame;
735
753
  }
736
754
  if (opts?.maxTextLength !== undefined)
737
755
  req.maxTextLength = opts.maxTextLength;
756
+ if (opts?.maxTotalTokens !== undefined)
757
+ req.maxTotalTokens = opts.maxTotalTokens;
758
+ if (opts?.includeBounds !== undefined)
759
+ req.includeBounds = opts.includeBounds;
760
+ if (opts?.viewportOnly !== undefined)
761
+ req.viewportOnly = opts.viewportOnly;
762
+ if (opts?.backendNodeId !== undefined)
763
+ req.backendNodeId = opts.backendNodeId;
764
+ if (opts?.selector !== undefined)
765
+ req.selector = opts.selector;
766
+ if (opts?.jsExpression !== undefined)
767
+ req.jsExpression = opts.jsExpression;
768
+ if (opts?.frameId !== undefined)
769
+ req.frameId = opts.frameId;
738
770
  const resp = await this.client.getObservation(req);
739
- return { text: resp.observationText, json: resp.observationJson };
771
+ return resp.observation;
740
772
  }
741
773
  /**
742
774
  * Captures a single image of the page's current frame and returns it as
@@ -1161,6 +1193,54 @@ export class CloudBrowser {
1161
1193
  await this.client.clearStorage(req);
1162
1194
  }
1163
1195
  // ──────────────────────────────────────────────────────────────────
1196
+ // Auth / DBSC (portable signed-in persona)
1197
+ // ──────────────────────────────────────────────────────────────────
1198
+ /**
1199
+ * Exports the signed-in primary account and DBSC sessions of this
1200
+ * browser context.
1201
+ *
1202
+ * State is read in the browser process, so no page needs to be open.
1203
+ * Returns undefined when the context has neither a signed-in account
1204
+ * nor DBSC sessions.
1205
+ *
1206
+ * @returns AuthSession, or undefined when there is nothing to export
1207
+ *
1208
+ * @throws UNKNOWN_ERROR - the auth session could not be read
1209
+ *
1210
+ * @example
1211
+ * const auth = await browser.getAuthSession();
1212
+ * if (auth) await fs.writeFile("auth.json", JSON.stringify(auth));
1213
+ */
1214
+ async getAuthSession() {
1215
+ const resp = await this.client.getAuthSession(create(GetAuthSessionRequestSchema, {
1216
+ sessionId: this.sessionId,
1217
+ apiKey: this.apiKey,
1218
+ }));
1219
+ return resp.session ? authSessionFromProto(resp.session) : undefined;
1220
+ }
1221
+ /**
1222
+ * Imports an auth session so the context comes up signed in (and syncing
1223
+ * if syncConsent) with its DBSC sessions restored.
1224
+ *
1225
+ * Call it before navigating. Pair with setCookies() / setStorage() to
1226
+ * restore a full persona.
1227
+ *
1228
+ * @param session - session as returned by getAuthSession()
1229
+ *
1230
+ * @throws UNKNOWN_ERROR - the auth session could not be written
1231
+ *
1232
+ * @example
1233
+ * await browser.setAuthSession(saved);
1234
+ * await browser.navigate("https://mail.google.com");
1235
+ */
1236
+ async setAuthSession(session) {
1237
+ await this.client.setAuthSession(create(SetAuthSessionRequestSchema, {
1238
+ sessionId: this.sessionId,
1239
+ apiKey: this.apiKey,
1240
+ session: authSessionToProto(session),
1241
+ }));
1242
+ }
1243
+ // ──────────────────────────────────────────────────────────────────
1164
1244
  // Devtools / live-UI helpers
1165
1245
  // ──────────────────────────────────────────────────────────────────
1166
1246
  /**
@@ -548,6 +548,15 @@ export type OccluderInfo = Message<"browserscale.v1.OccluderInfo"> & {
548
548
  * @generated from field: optional bool hittable_while_invisible = 12;
549
549
  */
550
550
  hittableWhileInvisible?: boolean;
551
+ /**
552
+ * Computed position keyword. Reports "fixed"/"sticky" when the element is
553
+ * pinned by itself or by an ancestor — pinned blockers stay put no matter
554
+ * where the pointer goes and can only be cleared by scrolling the target out
555
+ * from under them; ordinary overlays often collapse once the pointer leaves.
556
+ *
557
+ * @generated from field: optional string position = 13;
558
+ */
559
+ position?: string;
551
560
  };
552
561
  /**
553
562
  * Describes the message browserscale.v1.OccluderInfo.
@@ -2332,6 +2341,146 @@ export type ClearStorageRequest = Message<"browserscale.v1.ClearStorageRequest">
2332
2341
  * Use `create(ClearStorageRequestSchema)` to create a new message.
2333
2342
  */
2334
2343
  export declare const ClearStorageRequestSchema: GenMessage<ClearStorageRequest>;
2344
+ /**
2345
+ * One Device Bound Session Credentials entry (WRC.DbscSession).
2346
+ *
2347
+ * @generated from message browserscale.v1.DbscSession
2348
+ */
2349
+ export type DbscSession = Message<"browserscale.v1.DbscSession"> & {
2350
+ /**
2351
+ * Serialized net::SchemefulSite (eTLD+1 site key), e.g. "https://google.com".
2352
+ *
2353
+ * @generated from field: string site = 1;
2354
+ */
2355
+ site: string;
2356
+ /**
2357
+ * Base64 of the serialized net.device_bound_sessions.proto.Session
2358
+ * (includes the wrapped binding key; portable under WRC's software
2359
+ * UnexportableKeyProvider).
2360
+ *
2361
+ * @generated from field: string session = 2;
2362
+ */
2363
+ session: string;
2364
+ };
2365
+ /**
2366
+ * Describes the message browserscale.v1.DbscSession.
2367
+ * Use `create(DbscSessionSchema)` to create a new message.
2368
+ */
2369
+ export declare const DbscSessionSchema: GenMessage<DbscSession>;
2370
+ /**
2371
+ * Portable snapshot of a context's signed-in Google account and/or DBSC
2372
+ * sessions (WRC.AuthSession). All fields optional so partial state round-trips.
2373
+ *
2374
+ * @generated from message browserscale.v1.AuthSession
2375
+ */
2376
+ export type AuthSession = Message<"browserscale.v1.AuthSession"> & {
2377
+ /**
2378
+ * Gaia obfuscated account id.
2379
+ *
2380
+ * @generated from field: optional string gaia_id = 1;
2381
+ */
2382
+ gaiaId?: string;
2383
+ /**
2384
+ * Account email.
2385
+ *
2386
+ * @generated from field: optional string email = 2;
2387
+ */
2388
+ email?: string;
2389
+ /**
2390
+ * OAuth refresh token (persistent).
2391
+ *
2392
+ * @generated from field: optional string refresh_token = 3;
2393
+ */
2394
+ refreshToken?: string;
2395
+ /**
2396
+ * Base64 of the wrapped device-binding key for the refresh token.
2397
+ * Empty/absent = unbound token.
2398
+ *
2399
+ * @generated from field: optional string wrapped_binding_key = 4;
2400
+ */
2401
+ wrappedBindingKey?: string;
2402
+ /**
2403
+ * Signin-scoped device id; must travel with the token.
2404
+ *
2405
+ * @generated from field: optional string signin_scoped_device_id = 5;
2406
+ */
2407
+ signinScopedDeviceId?: string;
2408
+ /**
2409
+ * True if the account should be restored at Sync consent.
2410
+ *
2411
+ * @generated from field: optional bool sync_consent = 6;
2412
+ */
2413
+ syncConsent?: boolean;
2414
+ /**
2415
+ * Device Bound Session Credentials for this context (all bound sites).
2416
+ *
2417
+ * @generated from field: repeated browserscale.v1.DbscSession dbsc_sessions = 7;
2418
+ */
2419
+ dbscSessions: DbscSession[];
2420
+ };
2421
+ /**
2422
+ * Describes the message browserscale.v1.AuthSession.
2423
+ * Use `create(AuthSessionSchema)` to create a new message.
2424
+ */
2425
+ export declare const AuthSessionSchema: GenMessage<AuthSession>;
2426
+ /**
2427
+ * @generated from message browserscale.v1.GetAuthSessionRequest
2428
+ */
2429
+ export type GetAuthSessionRequest = Message<"browserscale.v1.GetAuthSessionRequest"> & {
2430
+ /**
2431
+ * @generated from field: string session_id = 1;
2432
+ */
2433
+ sessionId: string;
2434
+ /**
2435
+ * @generated from field: string api_key = 2;
2436
+ */
2437
+ apiKey: string;
2438
+ };
2439
+ /**
2440
+ * Describes the message browserscale.v1.GetAuthSessionRequest.
2441
+ * Use `create(GetAuthSessionRequestSchema)` to create a new message.
2442
+ */
2443
+ export declare const GetAuthSessionRequestSchema: GenMessage<GetAuthSessionRequest>;
2444
+ /**
2445
+ * @generated from message browserscale.v1.GetAuthSessionResponse
2446
+ */
2447
+ export type GetAuthSessionResponse = Message<"browserscale.v1.GetAuthSessionResponse"> & {
2448
+ /**
2449
+ * Present only if the context has exportable auth/DBSC state.
2450
+ *
2451
+ * @generated from field: optional browserscale.v1.AuthSession session = 1;
2452
+ */
2453
+ session?: AuthSession;
2454
+ };
2455
+ /**
2456
+ * Describes the message browserscale.v1.GetAuthSessionResponse.
2457
+ * Use `create(GetAuthSessionResponseSchema)` to create a new message.
2458
+ */
2459
+ export declare const GetAuthSessionResponseSchema: GenMessage<GetAuthSessionResponse>;
2460
+ /**
2461
+ * @generated from message browserscale.v1.SetAuthSessionRequest
2462
+ */
2463
+ export type SetAuthSessionRequest = Message<"browserscale.v1.SetAuthSessionRequest"> & {
2464
+ /**
2465
+ * @generated from field: string session_id = 1;
2466
+ */
2467
+ sessionId: string;
2468
+ /**
2469
+ * @generated from field: string api_key = 2;
2470
+ */
2471
+ apiKey: string;
2472
+ /**
2473
+ * Session to import (as returned by GetAuthSession).
2474
+ *
2475
+ * @generated from field: browserscale.v1.AuthSession session = 3;
2476
+ */
2477
+ session?: AuthSession;
2478
+ };
2479
+ /**
2480
+ * Describes the message browserscale.v1.SetAuthSessionRequest.
2481
+ * Use `create(SetAuthSessionRequestSchema)` to create a new message.
2482
+ */
2483
+ export declare const SetAuthSessionRequestSchema: GenMessage<SetAuthSessionRequest>;
2335
2484
  /**
2336
2485
  * @generated from message browserscale.v1.GetDOMRequest
2337
2486
  */
@@ -2397,17 +2546,74 @@ export type GetObservationRequest = Message<"browserscale.v1.GetObservationReque
2397
2546
  */
2398
2547
  pageId: string;
2399
2548
  /**
2400
- * Default 500.
2549
+ * Safety net against runaway documents; max_total_tokens is the limit that
2550
+ * normally binds. Default 800.
2401
2551
  *
2402
2552
  * @generated from field: optional int32 max_elements_per_frame = 4;
2403
2553
  */
2404
2554
  maxElementsPerFrame?: number;
2405
2555
  /**
2406
- * Default 240.
2556
+ * Max length of human-readable strings (labels, text, values). Default 300.
2557
+ * Identifier-like attributes have their own shorter cap.
2407
2558
  *
2408
2559
  * @generated from field: optional int32 max_text_length = 5;
2409
2560
  */
2410
2561
  maxTextLength?: number;
2562
+ /**
2563
+ * "text" (default) for the compact line format, "json" for the structured
2564
+ * form. Only the requested representation is built.
2565
+ *
2566
+ * @generated from field: optional string format = 6;
2567
+ */
2568
+ format?: string;
2569
+ /**
2570
+ * Budget across ALL frames, in estimated tokens rather than characters.
2571
+ * Default 8000.
2572
+ *
2573
+ * @generated from field: optional int32 max_total_tokens = 7;
2574
+ */
2575
+ maxTotalTokens?: number;
2576
+ /**
2577
+ * Include element bounds as bounds="x,y,w,h".
2578
+ *
2579
+ * @generated from field: optional bool include_bounds = 8;
2580
+ */
2581
+ includeBounds?: boolean;
2582
+ /**
2583
+ * Only emit elements intersecting the frame's current viewport.
2584
+ *
2585
+ * @generated from field: optional bool viewport_only = 9;
2586
+ */
2587
+ viewportOnly?: boolean;
2588
+ /**
2589
+ * Scope root by backend node ID from a previous wait/getObservation.
2590
+ * Requires frame_id. At most one of backend_node_id, selector, js_expression.
2591
+ * Omit all three for the whole page.
2592
+ *
2593
+ * @generated from field: optional int32 backend_node_id = 10;
2594
+ */
2595
+ backendNodeId?: number;
2596
+ /**
2597
+ * Scope root by CSS selector.
2598
+ *
2599
+ * @generated from field: optional string selector = 11;
2600
+ */
2601
+ selector?: string;
2602
+ /**
2603
+ * Scope root by JS expression that evaluates to a DOM Element
2604
+ * (including __wrc.shadow(...) for closed shadow roots).
2605
+ *
2606
+ * @generated from field: optional string js_expression = 12;
2607
+ */
2608
+ jsExpression?: string;
2609
+ /**
2610
+ * Where to look up the scope root: a specific frameId, empty/omitted for
2611
+ * the main frame, or "ALL_FRAMES" to search every frame until found.
2612
+ * Ignored when observing the whole page.
2613
+ *
2614
+ * @generated from field: optional string frame_id = 13;
2615
+ */
2616
+ frameId?: string;
2411
2617
  };
2412
2618
  /**
2413
2619
  * Describes the message browserscale.v1.GetObservationRequest.
@@ -2419,17 +2625,11 @@ export declare const GetObservationRequestSchema: GenMessage<GetObservationReque
2419
2625
  */
2420
2626
  export type GetObservationResponse = Message<"browserscale.v1.GetObservationResponse"> & {
2421
2627
  /**
2422
- * Compact plain-text observation intended for LLM context.
2423
- *
2424
- * @generated from field: string observation_text = 1;
2425
- */
2426
- observationText: string;
2427
- /**
2428
- * Structured JSON with frames, elements, counts, and limits.
2628
+ * The observation in the requested format.
2429
2629
  *
2430
- * @generated from field: string observation_json = 2;
2630
+ * @generated from field: string observation = 1;
2431
2631
  */
2432
- observationJson: string;
2632
+ observation: string;
2433
2633
  };
2434
2634
  /**
2435
2635
  * Describes the message browserscale.v1.GetObservationResponse.
@@ -3389,6 +3589,24 @@ export declare const Browser: GenService<{
3389
3589
  input: typeof ClearStorageRequestSchema;
3390
3590
  output: typeof EmptySchema;
3391
3591
  };
3592
+ /**
3593
+ * Auth / DBSC (portable signed-in persona)
3594
+ *
3595
+ * @generated from rpc browserscale.v1.Browser.GetAuthSession
3596
+ */
3597
+ getAuthSession: {
3598
+ methodKind: "unary";
3599
+ input: typeof GetAuthSessionRequestSchema;
3600
+ output: typeof GetAuthSessionResponseSchema;
3601
+ };
3602
+ /**
3603
+ * @generated from rpc browserscale.v1.Browser.SetAuthSession
3604
+ */
3605
+ setAuthSession: {
3606
+ methodKind: "unary";
3607
+ input: typeof SetAuthSessionRequestSchema;
3608
+ output: typeof EmptySchema;
3609
+ };
3392
3610
  /**
3393
3611
  * DOM / observation
3394
3612
  *