wrc-ts 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WebRobot Cloud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # wrc-ts — WebRobot Cloud SDK for TypeScript
2
+
3
+ Official TypeScript SDK for [WebRobot Cloud](https://webrobot.cloud): real
4
+ Chromium browsers in the cloud, driven over gRPC. Rent an isolated browser
5
+ session in seconds, automate it with human-like input, intercept network
6
+ traffic, solve captchas, and watch a live video stream of everything your
7
+ script does.
8
+
9
+ ## Features
10
+
11
+ - **Real browser sessions as a service** — full Chromium in the cloud with
12
+ pages, frames, cookies, storage and network state. No local binary.
13
+ - **Parallel isolated contexts** — each task gets its own session, fingerprint
14
+ and lifecycle; large queues never share browser state. Sessions are browser
15
+ contexts, not VMs or processes, so they spin up in under 50 ms and fan out to
16
+ thousands in parallel.
17
+ - **Fingerprint & proxy handling** — pinnable server-side fingerprints,
18
+ native Chrome control without CDP/Playwright/Puppeteer leaks, bring your own
19
+ proxy or let WRC allocate one.
20
+ - **Native engine-level control** — automation runs natively inside Chromium
21
+ itself, not from outside over the DevTools protocol. Nothing is injected, no
22
+ `Runtime.enable`, no DevTools handshake — page JS can't observe it. Waits run
23
+ fully async with no polling loop, and built-in steady-time checks only report
24
+ an element once it's stable in the DOM.
25
+ - **One flat frame tree** — main document, same-origin iframes and cross-origin
26
+ OOPIFs are all just a `frameId` in one tree, no flattened sessions or
27
+ per-frame execution-context juggling. `wait`/`click` act across all frames or
28
+ a single iframe, and `wait` returns the `frameId` that matched.
29
+ - **Human-like interaction** — mouse paths use WRC's own movement algorithm
30
+ instead of instant synthetic jumps.
31
+ - **WebRTC live video stream** — watch and control the rented browser live
32
+ from the WRC web interface; mouse and keyboard go back over data channels.
33
+ - **Captcha support, no third-party solvers** — passive anti-bot checks are
34
+ handled automatically; interactive challenges are solved with `solveCaptcha`
35
+ by WRC's own AI solver, which learns the known challenge types — puzzle,
36
+ OCR, slide, hold and more — on its own and keeps improving as they evolve.
37
+ No token is ever synthesized or fetched from an external API: the challenge
38
+ is completed in the valid live browser and the provider's own JavaScript
39
+ issues the token itself — which is why even new or unknown protections
40
+ pass.
41
+ - **Real hardware, real GPUs** — sessions run hardware-accelerated on real
42
+ consumer GPUs, not on VM cores with a WebGL faking layer. Canvas and WebGL
43
+ readbacks (`toDataURL`, `getImageData`) return genuinely rendered pixels —
44
+ no spoofing layer or fingerprint hash database for new bot protections to
45
+ unmask.
46
+ - **Network control at the source** — interception sits in the browser's
47
+ network stack itself, so every request from every frame (including
48
+ cross-origin OOPIFs) passes through it; no handler races, nothing slips
49
+ through. Wait for, block, mock or modify requests and responses without
50
+ leaving the SDK; mark repeated assets as static with `setStaticPaths` to
51
+ serve them from a server-side cache and cut proxy bandwidth on repeat runs.
52
+ - **Agent-friendly observation** — `getObservation` returns a compact
53
+ text/JSON view of the visible, interactive elements across every frame, each
54
+ with a node handle to act on, so a model reasons over what matters instead of
55
+ raw HTML.
56
+ - **Flow-optimized TypeScript** — fully typed promise-based API, `wait` races
57
+ multiple outcomes, JS locators target elements by page logic when CSS is
58
+ not enough. Runs in Node.js (native gRPC) and the browser (WebSocket via
59
+ `wrc-ts/browser`).
60
+
61
+ ## Install
62
+
63
+ ```bash
64
+ npm install wrc-ts
65
+ ```
66
+
67
+ Requires Node 18+. Ships as an ES module with bundled type declarations.
68
+
69
+ ## Quickstart
70
+
71
+ ```ts
72
+ import { rentBrowser, BrowserConfig, css } from "wrc-ts";
73
+
74
+ async function main() {
75
+ // Empty proxy fields tell WRC to allocate a managed proxy server-side;
76
+ // pass your own host/port/creds to bring your own.
77
+ const cfg = new BrowserConfig(
78
+ "YOUR_API_KEY", // sk_…
79
+ 300, // rent duration in seconds (5 minutes)
80
+ "", 0, "", "", // proxy host / port / user / pass
81
+ );
82
+
83
+ const browser = await rentBrowser(cfg);
84
+ try {
85
+ await browser.navigate("https://example.com");
86
+ await browser.wait(css("h1"));
87
+
88
+ const res = await browser.evaluate("document.title");
89
+ console.log("title:", res.value);
90
+ } finally {
91
+ await browser.stopBrowser(); // always release the session
92
+ }
93
+ }
94
+
95
+ main();
96
+ ```
97
+
98
+ Run it and you should see `title: Example Domain`. Get an API key from your
99
+ [dashboard](https://webrobot.cloud/dashboard/api-keys).
100
+
101
+ ## Documentation
102
+
103
+ - [Introduction](https://webrobot.cloud/docs) — what WRC is, use cases and
104
+ the mental model behind sessions, pages, frames and locators
105
+ - [Quickstart](https://webrobot.cloud/docs/quickstart) — from install to a
106
+ running script in under a minute
107
+ - [Core concepts](https://webrobot.cloud/docs/concepts)
108
+ - Guides — [locators](https://webrobot.cloud/docs/guides/locators),
109
+ [waiting](https://webrobot.cloud/docs/guides/waiting),
110
+ [network](https://webrobot.cloud/docs/guides/network),
111
+ [cookies](https://webrobot.cloud/docs/guides/cookies),
112
+ [captchas](https://webrobot.cloud/docs/guides/captchas) and more
113
+ - [TypeScript API reference](https://webrobot.cloud/docs/api-reference/ts) —
114
+ every method, type and option with runnable examples
115
+
116
+ ## Go
117
+
118
+ Prefer Go? Use the Go SDK:
119
+ [wrc_go](https://github.com/webrobot-dev/wrc_go).
120
+
121
+ ## License
122
+
123
+ [MIT](LICENSE)
@@ -0,0 +1,39 @@
1
+ import { CloudBrowser } from "./client.ts";
2
+ export { CloudBrowser } from "./client.ts";
3
+ export { WebSocketTransport } from "./ws-transport.ts";
4
+ export { BrowserConfig } from "./config.ts";
5
+ export { Locator, css, js, node, at, AllFrames } from "./locator.ts";
6
+ export { DefaultWaitTimeoutMs, DefaultVisible, DefaultSteadyMs, } from "./defaults.ts";
7
+ export { WRCError } from "./errors.ts";
8
+ export type { Rect, FrameInfo, PageInfo, Header, InterceptedRequest, InterceptedResponse, WaitResult, NavigateResult, EvaluateResult, ElementResult, DragResult, SelectOptionResult, ObservationResult, DOMResult, InspectResult, RentResponse, } from "./types.ts";
9
+ export type { Button, ClickAction, ClickOpts, FillOpts, SelectOpts, WaitOpts, WaitUntil, NavigateOpts, LoadHTMLOpts, GetDOMOpts, GetObservationOpts, } from "./options.ts";
10
+ export { type RequestPattern, type HeaderModification, type HeaderModificationAction, } from "./network.ts";
11
+ export type { CookieParam } from "./cookies.ts";
12
+ export type { StorageItem, StorageOriginEntry } from "./storage.ts";
13
+ /**
14
+ * Attaches a {@link CloudBrowser} to an existing session over a raw
15
+ * WebSocket transport.
16
+ *
17
+ * Use this from a browser context: the WebSocket transport framing is
18
+ * defined by {@link WebSocketTransport} and is served directly by the
19
+ * WRC session host. The session must already exist server-side; unlike
20
+ * {@link rentBrowser} this does not call the rent API. Closing the
21
+ * returned handle (via {@link CloudBrowser.stopBrowser}) only closes the
22
+ * transport — the rental stays alive.
23
+ *
24
+ * @param wsUrl - WebSocket URL (ws:// or wss://) of the session host
25
+ * @param sessionId - id of the existing session
26
+ * @param apiKey - API key authorizing access to the session
27
+ * @param fingerprint - browser fingerprint id; empty if unknown
28
+ *
29
+ * @returns CloudBrowser attached to the existing session
30
+ *
31
+ * @example
32
+ * const browser = createWebSocketBrowser(
33
+ * "wss://session-abc.wrc.example.com/ws",
34
+ * sessionId,
35
+ * apiKey,
36
+ * );
37
+ * await browser.navigate("https://example.com");
38
+ */
39
+ export declare function createWebSocketBrowser(wsUrl: string, sessionId: string, apiKey: string, fingerprint?: string): CloudBrowser;
@@ -0,0 +1,43 @@
1
+ import { CloudBrowser } from "./client.js";
2
+ import { WebSocketTransport } from "./ws-transport.js";
3
+ // Public API — browser entry point ────────────────────────────────────
4
+ export { CloudBrowser } from "./client.js";
5
+ export { WebSocketTransport } from "./ws-transport.js";
6
+ export { BrowserConfig } from "./config.js";
7
+ // Locator + constructors + AllFrames sentinel
8
+ export { Locator, css, js, node, at, AllFrames } from "./locator.js";
9
+ // Defaults the SDK applies before sending a request
10
+ export { DefaultWaitTimeoutMs, DefaultVisible, DefaultSteadyMs, } from "./defaults.js";
11
+ // Errors
12
+ export { WRCError } from "./errors.js";
13
+ // Browser-side factory functions ───────────────────────────────────────
14
+ /**
15
+ * Attaches a {@link CloudBrowser} to an existing session over a raw
16
+ * WebSocket transport.
17
+ *
18
+ * Use this from a browser context: the WebSocket transport framing is
19
+ * defined by {@link WebSocketTransport} and is served directly by the
20
+ * WRC session host. The session must already exist server-side; unlike
21
+ * {@link rentBrowser} this does not call the rent API. Closing the
22
+ * returned handle (via {@link CloudBrowser.stopBrowser}) only closes the
23
+ * transport — the rental stays alive.
24
+ *
25
+ * @param wsUrl - WebSocket URL (ws:// or wss://) of the session host
26
+ * @param sessionId - id of the existing session
27
+ * @param apiKey - API key authorizing access to the session
28
+ * @param fingerprint - browser fingerprint id; empty if unknown
29
+ *
30
+ * @returns CloudBrowser attached to the existing session
31
+ *
32
+ * @example
33
+ * const browser = createWebSocketBrowser(
34
+ * "wss://session-abc.wrc.example.com/ws",
35
+ * sessionId,
36
+ * apiKey,
37
+ * );
38
+ * await browser.navigate("https://example.com");
39
+ */
40
+ export function createWebSocketBrowser(wsUrl, sessionId, apiKey, fingerprint = "") {
41
+ const transport = new WebSocketTransport(wsUrl);
42
+ return new CloudBrowser(transport, sessionId, apiKey, fingerprint);
43
+ }