@olib-ai/owl-browser-sdk 2.0.5 → 2.0.6

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.
Files changed (111) hide show
  1. package/README.md +107 -0
  2. package/dist/extraction/content-cleaner.d.ts +40 -0
  3. package/dist/extraction/content-cleaner.d.ts.map +1 -0
  4. package/dist/extraction/content-cleaner.js +393 -0
  5. package/dist/extraction/content-cleaner.js.map +1 -0
  6. package/dist/extraction/extractor.d.ts +139 -0
  7. package/dist/extraction/extractor.d.ts.map +1 -0
  8. package/dist/extraction/extractor.js +212 -0
  9. package/dist/extraction/extractor.js.map +1 -0
  10. package/dist/extraction/html-processor.d.ts +75 -0
  11. package/dist/extraction/html-processor.d.ts.map +1 -0
  12. package/dist/extraction/html-processor.js +192 -0
  13. package/dist/extraction/html-processor.js.map +1 -0
  14. package/dist/extraction/index.d.ts +14 -0
  15. package/dist/extraction/index.d.ts.map +1 -0
  16. package/dist/extraction/index.js +19 -0
  17. package/dist/extraction/index.js.map +1 -0
  18. package/dist/extraction/list-extractor.d.ts +24 -0
  19. package/dist/extraction/list-extractor.d.ts.map +1 -0
  20. package/dist/extraction/list-extractor.js +303 -0
  21. package/dist/extraction/list-extractor.js.map +1 -0
  22. package/dist/extraction/meta-extractor.d.ts +40 -0
  23. package/dist/extraction/meta-extractor.d.ts.map +1 -0
  24. package/dist/extraction/meta-extractor.js +216 -0
  25. package/dist/extraction/meta-extractor.js.map +1 -0
  26. package/dist/extraction/pagination.d.ts +29 -0
  27. package/dist/extraction/pagination.d.ts.map +1 -0
  28. package/dist/extraction/pagination.js +323 -0
  29. package/dist/extraction/pagination.js.map +1 -0
  30. package/dist/extraction/pattern-detector.d.ts +16 -0
  31. package/dist/extraction/pattern-detector.d.ts.map +1 -0
  32. package/dist/extraction/pattern-detector.js +390 -0
  33. package/dist/extraction/pattern-detector.js.map +1 -0
  34. package/dist/extraction/scrape-session.d.ts +23 -0
  35. package/dist/extraction/scrape-session.d.ts.map +1 -0
  36. package/dist/extraction/scrape-session.js +192 -0
  37. package/dist/extraction/scrape-session.js.map +1 -0
  38. package/dist/extraction/selector-engine.d.ts +23 -0
  39. package/dist/extraction/selector-engine.d.ts.map +1 -0
  40. package/dist/extraction/selector-engine.js +127 -0
  41. package/dist/extraction/selector-engine.js.map +1 -0
  42. package/dist/extraction/table-extractor.d.ts +29 -0
  43. package/dist/extraction/table-extractor.d.ts.map +1 -0
  44. package/dist/extraction/table-extractor.js +282 -0
  45. package/dist/extraction/table-extractor.js.map +1 -0
  46. package/dist/extraction/transforms.d.ts +47 -0
  47. package/dist/extraction/transforms.d.ts.map +1 -0
  48. package/dist/extraction/transforms.js +277 -0
  49. package/dist/extraction/transforms.js.map +1 -0
  50. package/dist/extraction/types.d.ts +199 -0
  51. package/dist/extraction/types.d.ts.map +1 -0
  52. package/dist/extraction/types.js +5 -0
  53. package/dist/extraction/types.js.map +1 -0
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +2 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/playwright/browser-type.d.ts +101 -0
  59. package/dist/playwright/browser-type.d.ts.map +1 -0
  60. package/dist/playwright/browser-type.js +134 -0
  61. package/dist/playwright/browser-type.js.map +1 -0
  62. package/dist/playwright/browser.d.ts +98 -0
  63. package/dist/playwright/browser.d.ts.map +1 -0
  64. package/dist/playwright/browser.js +229 -0
  65. package/dist/playwright/browser.js.map +1 -0
  66. package/dist/playwright/context.d.ts +211 -0
  67. package/dist/playwright/context.d.ts.map +1 -0
  68. package/dist/playwright/context.js +466 -0
  69. package/dist/playwright/context.js.map +1 -0
  70. package/dist/playwright/extractor.d.ts +108 -0
  71. package/dist/playwright/extractor.d.ts.map +1 -0
  72. package/dist/playwright/extractor.js +404 -0
  73. package/dist/playwright/extractor.js.map +1 -0
  74. package/dist/playwright/frame.d.ts +147 -0
  75. package/dist/playwright/frame.d.ts.map +1 -0
  76. package/dist/playwright/frame.js +492 -0
  77. package/dist/playwright/frame.js.map +1 -0
  78. package/dist/playwright/index.d.ts +163 -0
  79. package/dist/playwright/index.d.ts.map +1 -0
  80. package/dist/playwright/index.js +313 -0
  81. package/dist/playwright/index.js.map +1 -0
  82. package/dist/playwright/keyboard.d.ts +74 -0
  83. package/dist/playwright/keyboard.d.ts.map +1 -0
  84. package/dist/playwright/keyboard.js +187 -0
  85. package/dist/playwright/keyboard.js.map +1 -0
  86. package/dist/playwright/locator.d.ts +237 -0
  87. package/dist/playwright/locator.d.ts.map +1 -0
  88. package/dist/playwright/locator.js +646 -0
  89. package/dist/playwright/locator.js.map +1 -0
  90. package/dist/playwright/mouse.d.ts +82 -0
  91. package/dist/playwright/mouse.d.ts.map +1 -0
  92. package/dist/playwright/mouse.js +137 -0
  93. package/dist/playwright/mouse.js.map +1 -0
  94. package/dist/playwright/page-helpers.d.ts +261 -0
  95. package/dist/playwright/page-helpers.d.ts.map +1 -0
  96. package/dist/playwright/page-helpers.js +423 -0
  97. package/dist/playwright/page-helpers.js.map +1 -0
  98. package/dist/playwright/page.d.ts +566 -0
  99. package/dist/playwright/page.d.ts.map +1 -0
  100. package/dist/playwright/page.js +1476 -0
  101. package/dist/playwright/page.js.map +1 -0
  102. package/dist/playwright/response.d.ts +100 -0
  103. package/dist/playwright/response.d.ts.map +1 -0
  104. package/dist/playwright/response.js +194 -0
  105. package/dist/playwright/response.js.map +1 -0
  106. package/dist/playwright/types.d.ts +354 -0
  107. package/dist/playwright/types.d.ts.map +1 -0
  108. package/dist/playwright/types.js +8 -0
  109. package/dist/playwright/types.js.map +1 -0
  110. package/openapi.json +327 -35
  111. package/package.json +10 -1
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Playwright-compatible BrowserType class for Owl Browser.
3
+ *
4
+ * Provides chromium.connect() and chromium.launch() entry points
5
+ * that mirror Playwright's top-level API. Owl Browser only supports
6
+ * remote connections (connect), not local browser launches.
7
+ *
8
+ * Includes connectOverCDP(), launchPersistentContext(), and launchServer()
9
+ * stubs for full Playwright API coverage.
10
+ */
11
+ import { OwlBrowser } from '../client.js';
12
+ import { Browser } from './browser.js';
13
+ /**
14
+ * BrowserType provides factory methods for creating Browser instances.
15
+ *
16
+ * In Playwright, you access this as `chromium`, `firefox`, or `webkit`.
17
+ * With Owl Browser, all three aliases point to the same implementation
18
+ * since Owl Browser uses its own Chromium-based engine.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { chromium } from '@olib-ai/owl-browser-sdk/playwright';
23
+ *
24
+ * // Connect to a running Owl Browser instance
25
+ * const browser = await chromium.connect({
26
+ * wsEndpoint: 'http://localhost:8080',
27
+ * token: 'your-token',
28
+ * });
29
+ *
30
+ * const context = await browser.newContext();
31
+ * const page = await context.newPage();
32
+ * await page.goto('https://example.com');
33
+ * ```
34
+ */
35
+ export class BrowserType {
36
+ _name;
37
+ constructor(name) {
38
+ this._name = name;
39
+ }
40
+ /** Browser engine name. */
41
+ name() {
42
+ return this._name;
43
+ }
44
+ /** Executable path (not applicable for Owl Browser). */
45
+ executablePath() {
46
+ return '';
47
+ }
48
+ /**
49
+ * Connect to a running Owl Browser server.
50
+ *
51
+ * This is the primary way to create a Browser instance.
52
+ * The server must already be running and accessible at the given URL.
53
+ *
54
+ * @param options - Connection options (endpoint URL and auth token)
55
+ * @returns A connected Browser instance
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const browser = await chromium.connect({
60
+ * wsEndpoint: 'http://localhost:8080',
61
+ * token: 'test-token',
62
+ * });
63
+ * ```
64
+ */
65
+ async connect(options) {
66
+ const client = new OwlBrowser({
67
+ url: options.wsEndpoint,
68
+ token: options.token,
69
+ timeout: options.timeout,
70
+ apiPrefix: options.apiPrefix ?? '',
71
+ });
72
+ await client.connect();
73
+ return new Browser(client);
74
+ }
75
+ /**
76
+ * Connect to a browser over CDP.
77
+ *
78
+ * Alias for connect() in Owl Browser context.
79
+ *
80
+ * @param options - Connection options
81
+ * @returns A connected Browser instance
82
+ */
83
+ async connectOverCDP(options) {
84
+ return this.connect(options);
85
+ }
86
+ /**
87
+ * Launch a new browser instance.
88
+ *
89
+ * Owl Browser does not support local browser launches.
90
+ * Use connect() to connect to a running Owl Browser server instead.
91
+ *
92
+ * @param options - Launch options (ignored)
93
+ * @throws Error always - use connect() instead
94
+ */
95
+ async launch(options) {
96
+ void options;
97
+ throw new Error(`${this._name}.launch() is not supported. ` +
98
+ `Owl Browser requires a running server. ` +
99
+ `Use ${this._name}.connect({ wsEndpoint, token }) instead.`);
100
+ }
101
+ /**
102
+ * Launch a browser with a persistent context (user data directory).
103
+ *
104
+ * Not supported by Owl Browser. Use connect() with profile_path option
105
+ * via browser_create_context for persistent profiles.
106
+ *
107
+ * @param userDataDir - User data directory path
108
+ * @param options - Launch and context options
109
+ * @throws Error always - use connect() instead
110
+ */
111
+ async launchPersistentContext(userDataDir, options) {
112
+ void userDataDir;
113
+ void options;
114
+ throw new Error(`${this._name}.launchPersistentContext() is not supported. ` +
115
+ `Use ${this._name}.connect() and create a context with ` +
116
+ `profile_path for persistent profiles.`);
117
+ }
118
+ /**
119
+ * Launch a browser server.
120
+ *
121
+ * Not supported by Owl Browser. The server must be started independently
122
+ * (via Docker or direct binary execution).
123
+ *
124
+ * @param options - Launch options
125
+ * @throws Error always - start server externally
126
+ */
127
+ async launchServer(options) {
128
+ void options;
129
+ throw new Error(`${this._name}.launchServer() is not supported. ` +
130
+ `Start the Owl Browser server externally (Docker or binary) ` +
131
+ `then use ${this._name}.connect().`);
132
+ }
133
+ }
134
+ //# sourceMappingURL=browser-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-type.js","sourceRoot":"","sources":["../../src/playwright/browser-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAOvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,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;OAQG;IACH,KAAK,CAAC,YAAY,CAAC,OAAuB;QACxC,KAAK,OAAO,CAAC;QACb,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,KAAK,oCAAoC;YACjD,6DAA6D;YAC7D,YAAY,IAAI,CAAC,KAAK,aAAa,CACpC,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Playwright-compatible Browser class for Owl Browser.
3
+ *
4
+ * Wraps the OwlBrowser client to provide the Playwright Browser API surface.
5
+ * A Browser instance represents a connection to an Owl Browser server
6
+ * and manages one or more BrowserContext instances.
7
+ *
8
+ * Supports full context creation options: viewport, proxy, locale, timezone,
9
+ * geolocation, permissions, colorScheme, storageState, recordVideo, and more.
10
+ */
11
+ import type { OwlBrowser } from '../client.js';
12
+ import { BrowserContext } from './context.js';
13
+ import type { Page } from './page.js';
14
+ import type { BrowserContextOptions } from './types.js';
15
+ /**
16
+ * Browser represents a connection to an Owl Browser instance.
17
+ *
18
+ * Use browser.newContext() to create isolated browsing sessions.
19
+ * Each context has independent cookies, storage, and optionally
20
+ * its own proxy configuration and fingerprint profile.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const browser = await chromium.connect({
25
+ * wsEndpoint: 'http://localhost:8080',
26
+ * token: 'test-token',
27
+ * });
28
+ *
29
+ * const context = await browser.newContext({
30
+ * viewport: { width: 1280, height: 720 },
31
+ * locale: 'en-US',
32
+ * proxy: { server: 'http://proxy:8080' },
33
+ * });
34
+ *
35
+ * const page = await context.newPage();
36
+ * await page.goto('https://example.com');
37
+ *
38
+ * await context.close();
39
+ * await browser.close();
40
+ * ```
41
+ */
42
+ export declare class Browser {
43
+ private readonly _client;
44
+ private readonly _contexts;
45
+ private _connected;
46
+ constructor(client: OwlBrowser);
47
+ /**
48
+ * Create a new isolated browser context.
49
+ *
50
+ * Each context gets its own cookies, local storage, and session.
51
+ * Supports full Playwright context options including proxy, viewport,
52
+ * locale, timezone, geolocation, storage state, and video recording.
53
+ *
54
+ * @param options - Context configuration options
55
+ * @returns A new BrowserContext instance
56
+ */
57
+ newContext(options?: BrowserContextOptions): Promise<BrowserContext>;
58
+ /**
59
+ * Create a new context and page in one call (convenience method).
60
+ *
61
+ * @param options - Context configuration options
62
+ * @returns A new Page instance
63
+ */
64
+ newPage(options?: BrowserContextOptions): Promise<Page>;
65
+ /**
66
+ * Get all open browser contexts.
67
+ *
68
+ * @returns Array of BrowserContext instances
69
+ */
70
+ contexts(): BrowserContext[];
71
+ /**
72
+ * Close the browser and all contexts.
73
+ *
74
+ * Closes every open context and disconnects from the server.
75
+ */
76
+ close(): Promise<void>;
77
+ /**
78
+ * Whether the browser is still connected to the server.
79
+ *
80
+ * @returns true if connected
81
+ */
82
+ isConnected(): boolean;
83
+ /**
84
+ * Browser version string.
85
+ *
86
+ * @returns Version identifier
87
+ */
88
+ version(): string;
89
+ /**
90
+ * Apply BrowserContextOptions that require post-creation API calls.
91
+ *
92
+ * Some options (viewport, proxy) are handled during browser_create_context.
93
+ * Others (cookies, extra headers, geolocation, offline) require separate
94
+ * tool executions after the context is created.
95
+ */
96
+ private _applyContextOptions;
97
+ }
98
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/playwright/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,qBAAqB,EAAwB,MAAM,YAAY,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,OAAO,CAAC,UAAU,CAAQ;gBAEd,MAAM,EAAE,UAAU;IAI9B;;;;;;;;;OASG;IACG,UAAU,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC;IA2C1E;;;;;OAKG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7D;;;;OAIG;IACH,QAAQ,IAAI,cAAc,EAAE;IAI5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;;OAIG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;OAMG;YACW,oBAAoB;CAgFnC"}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Playwright-compatible Browser class for Owl Browser.
3
+ *
4
+ * Wraps the OwlBrowser client to provide the Playwright Browser API surface.
5
+ * A Browser instance represents a connection to an Owl Browser server
6
+ * and manages one or more BrowserContext instances.
7
+ *
8
+ * Supports full context creation options: viewport, proxy, locale, timezone,
9
+ * geolocation, permissions, colorScheme, storageState, recordVideo, and more.
10
+ */
11
+ import { BrowserContext } from './context.js';
12
+ /**
13
+ * Browser represents a connection to an Owl Browser instance.
14
+ *
15
+ * Use browser.newContext() to create isolated browsing sessions.
16
+ * Each context has independent cookies, storage, and optionally
17
+ * its own proxy configuration and fingerprint profile.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const browser = await chromium.connect({
22
+ * wsEndpoint: 'http://localhost:8080',
23
+ * token: 'test-token',
24
+ * });
25
+ *
26
+ * const context = await browser.newContext({
27
+ * viewport: { width: 1280, height: 720 },
28
+ * locale: 'en-US',
29
+ * proxy: { server: 'http://proxy:8080' },
30
+ * });
31
+ *
32
+ * const page = await context.newPage();
33
+ * await page.goto('https://example.com');
34
+ *
35
+ * await context.close();
36
+ * await browser.close();
37
+ * ```
38
+ */
39
+ export class Browser {
40
+ _client;
41
+ _contexts = [];
42
+ _connected = true;
43
+ constructor(client) {
44
+ this._client = client;
45
+ }
46
+ /**
47
+ * Create a new isolated browser context.
48
+ *
49
+ * Each context gets its own cookies, local storage, and session.
50
+ * Supports full Playwright context options including proxy, viewport,
51
+ * locale, timezone, geolocation, storage state, and video recording.
52
+ *
53
+ * @param options - Context configuration options
54
+ * @returns A new BrowserContext instance
55
+ */
56
+ async newContext(options) {
57
+ const params = {};
58
+ // Proxy configuration
59
+ if (options?.proxy) {
60
+ try {
61
+ const proxyUrl = new URL(options.proxy.server);
62
+ params['proxy_type'] = proxyUrl.protocol.replace(':', '');
63
+ params['proxy_host'] = proxyUrl.hostname;
64
+ if (proxyUrl.port) {
65
+ params['proxy_port'] = proxyUrl.port;
66
+ }
67
+ }
68
+ catch {
69
+ params['proxy_host'] = options.proxy.server;
70
+ }
71
+ if (options.proxy.username)
72
+ params['proxy_username'] = options.proxy.username;
73
+ if (options.proxy.password)
74
+ params['proxy_password'] = options.proxy.password;
75
+ }
76
+ // Timezone
77
+ if (options?.timezoneId) {
78
+ params['timezone'] = options.timezoneId;
79
+ }
80
+ // Viewport / screen size
81
+ if (options?.viewport) {
82
+ params['screen_size'] = `${options.viewport.width}x${options.viewport.height}`;
83
+ }
84
+ // Create the context
85
+ const result = await this._client.execute('browser_create_context', params);
86
+ const res = result;
87
+ const contextId = String(res['context_id'] ?? '');
88
+ const context = new BrowserContext(this._client, contextId, this);
89
+ this._contexts.push(context);
90
+ // Apply post-creation options
91
+ await this._applyContextOptions(context, contextId, options);
92
+ return context;
93
+ }
94
+ /**
95
+ * Create a new context and page in one call (convenience method).
96
+ *
97
+ * @param options - Context configuration options
98
+ * @returns A new Page instance
99
+ */
100
+ async newPage(options) {
101
+ const context = await this.newContext(options);
102
+ return context.newPage();
103
+ }
104
+ /**
105
+ * Get all open browser contexts.
106
+ *
107
+ * @returns Array of BrowserContext instances
108
+ */
109
+ contexts() {
110
+ return [...this._contexts];
111
+ }
112
+ /**
113
+ * Close the browser and all contexts.
114
+ *
115
+ * Closes every open context and disconnects from the server.
116
+ */
117
+ async close() {
118
+ for (const context of this._contexts) {
119
+ try {
120
+ await context.close();
121
+ }
122
+ catch {
123
+ // Context may already be closed
124
+ }
125
+ }
126
+ this._contexts.length = 0;
127
+ try {
128
+ await this._client.close();
129
+ }
130
+ catch {
131
+ // Connection may already be closed
132
+ }
133
+ this._connected = false;
134
+ }
135
+ /**
136
+ * Whether the browser is still connected to the server.
137
+ *
138
+ * @returns true if connected
139
+ */
140
+ isConnected() {
141
+ return this._connected && this._client.connected;
142
+ }
143
+ /**
144
+ * Browser version string.
145
+ *
146
+ * @returns Version identifier
147
+ */
148
+ version() {
149
+ return 'owl-browser';
150
+ }
151
+ /**
152
+ * Apply BrowserContextOptions that require post-creation API calls.
153
+ *
154
+ * Some options (viewport, proxy) are handled during browser_create_context.
155
+ * Others (cookies, extra headers, geolocation, offline) require separate
156
+ * tool executions after the context is created.
157
+ */
158
+ async _applyContextOptions(context, contextId, options) {
159
+ if (!options)
160
+ return;
161
+ // Storage state (cookies + local storage)
162
+ if (options.storageState) {
163
+ let state;
164
+ if (typeof options.storageState === 'string') {
165
+ const { readFile } = await import('node:fs/promises');
166
+ const data = await readFile(options.storageState, 'utf-8');
167
+ state = JSON.parse(data);
168
+ }
169
+ else {
170
+ state = options.storageState;
171
+ }
172
+ if (state.cookies && state.cookies.length > 0) {
173
+ await context.addCookies(state.cookies);
174
+ }
175
+ // Restore local storage via evaluate
176
+ if (state.origins) {
177
+ for (const origin of state.origins) {
178
+ for (const item of origin.localStorage) {
179
+ await this._client.execute('browser_evaluate', {
180
+ context_id: contextId,
181
+ script: `localStorage.setItem(${JSON.stringify(item.name)}, ${JSON.stringify(item.value)})`,
182
+ return_value: false,
183
+ });
184
+ }
185
+ }
186
+ }
187
+ }
188
+ // Extra HTTP headers
189
+ if (options.extraHTTPHeaders) {
190
+ await context.setExtraHTTPHeaders(options.extraHTTPHeaders);
191
+ }
192
+ // Geolocation
193
+ if (options.geolocation) {
194
+ await context.setGeolocation(options.geolocation);
195
+ }
196
+ // Offline mode
197
+ if (options.offline) {
198
+ await context.setOffline(true);
199
+ }
200
+ // Viewport (also set during creation, but ensure Page gets it)
201
+ if (options.viewport) {
202
+ await this._client.execute('browser_set_viewport', {
203
+ context_id: contextId,
204
+ width: options.viewport.width,
205
+ height: options.viewport.height,
206
+ });
207
+ }
208
+ // Video recording
209
+ if (options.recordVideo) {
210
+ const videoParams = {
211
+ context_id: contextId,
212
+ };
213
+ await this._client.execute('browser_start_video_recording', videoParams);
214
+ }
215
+ // Download path (acceptDownloads)
216
+ if (options.acceptDownloads !== false) {
217
+ try {
218
+ await this._client.execute('browser_set_download_path', {
219
+ context_id: contextId,
220
+ path: '/tmp/downloads',
221
+ });
222
+ }
223
+ catch {
224
+ // Download path may not be configurable
225
+ }
226
+ }
227
+ }
228
+ }
229
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/playwright/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAI9C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,OAAO;IACD,OAAO,CAAa;IACpB,SAAS,GAAqB,EAAE,CAAC;IAC1C,UAAU,GAAG,IAAI,CAAC;IAE1B,YAAY,MAAkB;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU,CAAC,OAA+B;QAC9C,MAAM,MAAM,GAA4B,EAAE,CAAC;QAE3C,sBAAsB;QACtB,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC/C,MAAM,CAAC,YAAY,CAAC,GAAG,QAAQ,CA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AAO,CAAC,gBAAgB,CAAC,CAAC;QAC9D,CAAC;QAED,cAAc;QACd,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,MAAM,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpD,CAAC;QAED,eAAe;QACf,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;QAED,+DAA+D;QAC/D,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,sBAAsB,EAAE;gBACjD,UAAU,EAAE,SAAS;gBACrB,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAC7B,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;aAChC,CAAC,CAAC;QACL,CAAC;QAED,kBAAkB;QAClB,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,MAAM,WAAW,GAA4B;gBAC3C,UAAU,EAAE,SAAS;aACtB,CAAC;YACF,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,+BAA+B,EAAE,WAAW,CAAC,CAAC;QAC3E,CAAC;QAED,kCAAkC;QAClC,IAAI,OAAO,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,2BAA2B,EAAE;oBACtD,UAAU,EAAE,SAAS;oBACrB,IAAI,EAAE,gBAAgB;iBACvB,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,wCAAwC;YAC1C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Playwright-compatible BrowserContext class for Owl Browser.
3
+ *
4
+ * A BrowserContext maps to an Owl Browser context (created via browser_create_context).
5
+ * It provides isolated cookie/storage/session management, page (tab) creation,
6
+ * network interception, storage state, proxy configuration, and more.
7
+ */
8
+ import type { OwlBrowser } from '../client.js';
9
+ import { Page } from './page.js';
10
+ import { Route } from './page-helpers.js';
11
+ import type { Cookie, StorageState, Geolocation, RouteOptions } from './types.js';
12
+ import type { Browser } from './browser.js';
13
+ /**
14
+ * BrowserContext provides an isolated browser session.
15
+ *
16
+ * Each context has independent cookies, local storage, and session storage.
17
+ * Pages created within a context share these storage mechanisms.
18
+ * Supports network interception, storage state persistence, proxy configuration,
19
+ * geolocation override, and extra HTTP headers.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const context = await browser.newContext({
24
+ * viewport: { width: 1280, height: 720 },
25
+ * locale: 'en-US',
26
+ * timezoneId: 'America/New_York',
27
+ * });
28
+ * const page = await context.newPage();
29
+ * await page.goto('https://example.com');
30
+ * await context.close();
31
+ * ```
32
+ */
33
+ export declare class BrowserContext {
34
+ private readonly _client;
35
+ private readonly _contextId;
36
+ private readonly _pages;
37
+ private readonly _browser;
38
+ private readonly _routes;
39
+ private _closed;
40
+ private _firstPageCreated;
41
+ constructor(client: OwlBrowser, contextId: string, browser: Browser);
42
+ /** The parent Browser instance. */
43
+ get browser(): Browser;
44
+ /** The underlying Owl Browser context ID. */
45
+ get contextId(): string;
46
+ /**
47
+ * Create a new page (tab) in this context.
48
+ *
49
+ * The first call returns a Page wrapping the default tab that was
50
+ * created with the context. Subsequent calls create new tabs via
51
+ * browser_new_tab.
52
+ *
53
+ * @returns A new Page instance
54
+ */
55
+ newPage(): Promise<Page>;
56
+ /**
57
+ * Get all pages (tabs) in this context.
58
+ *
59
+ * @returns Array of Page instances created in this context
60
+ */
61
+ pages(): Page[];
62
+ /**
63
+ * Close the context and all its pages.
64
+ *
65
+ * Releases all resources associated with the context, including
66
+ * cookies, storage, network connections, and route handlers.
67
+ */
68
+ close(): Promise<void>;
69
+ /**
70
+ * Get cookies for the context.
71
+ *
72
+ * @param urls - Optional URL(s) to filter cookies by
73
+ * @returns Array of cookies
74
+ */
75
+ cookies(urls?: string | string[]): Promise<Cookie[]>;
76
+ /**
77
+ * Add cookies to the context.
78
+ *
79
+ * @param cookies - Array of cookie objects to add
80
+ */
81
+ addCookies(cookies: Cookie[]): Promise<void>;
82
+ /**
83
+ * Clear all cookies from the context.
84
+ */
85
+ clearCookies(): Promise<void>;
86
+ /**
87
+ * Get the storage state (cookies and local storage origins).
88
+ *
89
+ * Use this to persist session state between runs.
90
+ *
91
+ * @param options - Optional path to save the state to
92
+ * @returns StorageState object
93
+ */
94
+ storageState(options?: {
95
+ path?: string;
96
+ }): Promise<StorageState>;
97
+ /**
98
+ * Intercept network requests matching a URL pattern at the context level.
99
+ *
100
+ * @param url - URL pattern (glob) or RegExp to match
101
+ * @param handler - Handler function to process intercepted requests
102
+ * @param options - Route options (e.g., times)
103
+ */
104
+ route(url: string | RegExp, handler: (route: Route) => void | Promise<void>, options?: RouteOptions): Promise<void>;
105
+ /**
106
+ * Remove a previously registered context-level route handler.
107
+ *
108
+ * @param url - URL pattern that was registered
109
+ * @param handler - Optional specific handler to remove
110
+ */
111
+ unroute(url: string | RegExp, handler?: (route: Route) => void | Promise<void>): Promise<void>;
112
+ /**
113
+ * Remove all route handlers.
114
+ */
115
+ unrouteAll(): Promise<void>;
116
+ /**
117
+ * Set extra HTTP headers for all requests in this context.
118
+ *
119
+ * @param headers - Object with header name/value pairs
120
+ */
121
+ setExtraHTTPHeaders(headers: Record<string, string>): Promise<void>;
122
+ /**
123
+ * Set the geolocation for the context.
124
+ *
125
+ * @param geolocation - Geolocation coordinates or null to clear
126
+ */
127
+ setGeolocation(geolocation: Geolocation | null): Promise<void>;
128
+ /**
129
+ * Grant permissions to the context.
130
+ *
131
+ * Stub: Browser permissions are managed at the profile level in Owl Browser.
132
+ *
133
+ * @param permissions - Array of permission names
134
+ * @param options - Optional origin filter
135
+ */
136
+ grantPermissions(permissions: string[], options?: {
137
+ origin?: string;
138
+ }): Promise<void>;
139
+ /**
140
+ * Clear granted permissions.
141
+ */
142
+ clearPermissions(): Promise<void>;
143
+ /**
144
+ * Set the context to offline/online mode.
145
+ *
146
+ * @param offline - true to emulate offline, false for online
147
+ */
148
+ setOffline(offline: boolean): Promise<void>;
149
+ /**
150
+ * Configure proxy settings for this context.
151
+ *
152
+ * @param proxy - Proxy configuration
153
+ */
154
+ setProxy(proxy: {
155
+ server: string;
156
+ username?: string;
157
+ password?: string;
158
+ }): Promise<void>;
159
+ /**
160
+ * Add a script that runs in every page before any other script.
161
+ *
162
+ * @param script - JavaScript code or script path
163
+ * @param arg - Optional argument
164
+ */
165
+ addInitScript(script: string | {
166
+ path: string;
167
+ }, arg?: unknown): Promise<void>;
168
+ /**
169
+ * Expose a function to all pages in this context.
170
+ *
171
+ * @param name - Global function name
172
+ * @param callback - Function implementation
173
+ */
174
+ exposeFunction(name: string, callback: (...args: unknown[]) => unknown): Promise<void>;
175
+ /**
176
+ * Register a context-level event handler.
177
+ *
178
+ * @param event - Event name ('page', 'close', etc.)
179
+ * @param handler - Event handler function
180
+ */
181
+ on(event: string, handler: (...args: unknown[]) => void): this;
182
+ /**
183
+ * Register a one-time context-level event handler.
184
+ *
185
+ * @param event - Event name
186
+ * @param handler - Event handler function
187
+ */
188
+ once(event: string, handler: (...args: unknown[]) => void): this;
189
+ /**
190
+ * Wait for a context-level event.
191
+ *
192
+ * @param event - Event name (e.g., 'page')
193
+ * @param options - Wait options
194
+ * @returns Event data
195
+ */
196
+ waitForEvent(event: string, options?: {
197
+ predicate?: (data: unknown) => boolean;
198
+ timeout?: number;
199
+ }): Promise<unknown>;
200
+ /**
201
+ * Tracing interface stub.
202
+ *
203
+ * Owl Browser does not support Playwright tracing, but provides
204
+ * a compatible API surface to prevent errors in migrated code.
205
+ */
206
+ get tracing(): {
207
+ start: (options?: unknown) => Promise<void>;
208
+ stop: (options?: unknown) => Promise<void>;
209
+ };
210
+ }
211
+ //# sourceMappingURL=context.d.ts.map