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

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 +217 -0
  67. package/dist/playwright/context.d.ts.map +1 -0
  68. package/dist/playwright/context.js +518 -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 +667 -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 +267 -0
  95. package/dist/playwright/page-helpers.d.ts.map +1 -0
  96. package/dist/playwright/page-helpers.js +449 -0
  97. package/dist/playwright/page-helpers.js.map +1 -0
  98. package/dist/playwright/page.d.ts +605 -0
  99. package/dist/playwright/page.d.ts.map +1 -0
  100. package/dist/playwright/page.js +1698 -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 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/playwright/context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WA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MAAM,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EACjC,GAAG,CAAC,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,CAAC;IAahB;;;;;OAKG;IACG,cAAc,CAClB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,GACxC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;;;OAKG;IACH,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;IAQ9D;;;;;OAKG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;IAMhE;;;;;;OAMG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GACrE,OAAO,CAAC,OAAO,CAAC;IAmDnB;;;;;OAKG;IACH,IAAI,OAAO,IAAI;QAAE,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAAC,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAKzG;CACF"}
@@ -0,0 +1,518 @@
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 { Page } from './page.js';
9
+ import { Route } from './page-helpers.js';
10
+ /**
11
+ * BrowserContext provides an isolated browser session.
12
+ *
13
+ * Each context has independent cookies, local storage, and session storage.
14
+ * Pages created within a context share these storage mechanisms.
15
+ * Supports network interception, storage state persistence, proxy configuration,
16
+ * geolocation override, and extra HTTP headers.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const context = await browser.newContext({
21
+ * viewport: { width: 1280, height: 720 },
22
+ * locale: 'en-US',
23
+ * timezoneId: 'America/New_York',
24
+ * });
25
+ * const page = await context.newPage();
26
+ * await page.goto('https://example.com');
27
+ * await context.close();
28
+ * ```
29
+ */
30
+ export class BrowserContext {
31
+ _client;
32
+ _contextId;
33
+ _pages = [];
34
+ _browser;
35
+ _routes = [];
36
+ _closed = false;
37
+ _firstPageCreated = false;
38
+ constructor(client, contextId, browser) {
39
+ this._client = client;
40
+ this._contextId = contextId;
41
+ this._browser = browser;
42
+ }
43
+ /** The parent Browser instance. */
44
+ get browser() {
45
+ return this._browser;
46
+ }
47
+ /** The underlying Owl Browser context ID. */
48
+ get contextId() {
49
+ return this._contextId;
50
+ }
51
+ /**
52
+ * Create a new page (tab) in this context.
53
+ *
54
+ * The first call returns a Page wrapping the default tab that was
55
+ * created with the context. Subsequent calls create new tabs via
56
+ * browser_new_tab.
57
+ *
58
+ * @returns A new Page instance
59
+ */
60
+ async newPage() {
61
+ if (!this._firstPageCreated) {
62
+ this._firstPageCreated = true;
63
+ const page = new Page(this._client, this._contextId);
64
+ this._pages.push(page);
65
+ return page;
66
+ }
67
+ // Create a new tab
68
+ const result = await this._client.execute('browser_new_tab', {
69
+ context_id: this._contextId,
70
+ });
71
+ const res = result;
72
+ const tabId = String(res['tab_id'] ?? res['id'] ?? '');
73
+ const page = new Page(this._client, this._contextId, tabId);
74
+ this._pages.push(page);
75
+ return page;
76
+ }
77
+ /**
78
+ * Get all pages (tabs) in this context.
79
+ *
80
+ * @returns Array of Page instances created in this context
81
+ */
82
+ pages() {
83
+ return [...this._pages];
84
+ }
85
+ /**
86
+ * Close the context and all its pages.
87
+ *
88
+ * Releases all resources associated with the context, including
89
+ * cookies, storage, network connections, and route handlers.
90
+ */
91
+ async close() {
92
+ if (this._closed)
93
+ return;
94
+ this._closed = true;
95
+ // Clean up routes
96
+ for (const entry of this._routes) {
97
+ try {
98
+ await this._client.execute('browser_remove_network_rule', {
99
+ context_id: this._contextId,
100
+ rule_id: entry.ruleId,
101
+ });
102
+ }
103
+ catch {
104
+ // Ignore cleanup errors
105
+ }
106
+ }
107
+ this._routes.length = 0;
108
+ await this._client.execute('browser_close_context', {
109
+ context_id: this._contextId,
110
+ });
111
+ }
112
+ // ==================== Cookies ====================
113
+ /**
114
+ * Get cookies for the context.
115
+ *
116
+ * @param urls - Optional URL(s) to filter cookies by
117
+ * @returns Array of cookies
118
+ */
119
+ async cookies(urls) {
120
+ const params = {
121
+ context_id: this._contextId,
122
+ };
123
+ if (typeof urls === 'string') {
124
+ params['url'] = urls;
125
+ }
126
+ else if (Array.isArray(urls) && urls.length > 0) {
127
+ params['url'] = urls[0];
128
+ }
129
+ const result = await this._client.execute('browser_get_cookies', params);
130
+ // Result is a flat array of cookie objects (not wrapped in { cookies: [...] })
131
+ if (Array.isArray(result)) {
132
+ return result;
133
+ }
134
+ // Fallback: check if wrapped in an object
135
+ const res = result;
136
+ const cookies = res['cookies'];
137
+ if (Array.isArray(cookies)) {
138
+ return cookies;
139
+ }
140
+ return [];
141
+ }
142
+ /**
143
+ * Add cookies to the context.
144
+ *
145
+ * @param cookies - Array of cookie objects to add
146
+ */
147
+ async addCookies(cookies) {
148
+ for (const cookie of cookies) {
149
+ // Strip leading dot from domain for URL construction
150
+ const domain = (cookie.domain ?? 'localhost').replace(/^\./, '');
151
+ // Use https by default, http if secure is explicitly false
152
+ const proto = cookie.secure === false ? 'http' : 'https';
153
+ const params = {
154
+ context_id: this._contextId,
155
+ url: `${proto}://${domain}${cookie.path ?? '/'}`,
156
+ name: cookie.name,
157
+ value: cookie.value,
158
+ };
159
+ if (cookie.domain !== undefined)
160
+ params['domain'] = cookie.domain;
161
+ if (cookie.path !== undefined)
162
+ params['path'] = cookie.path;
163
+ if (cookie.expires !== undefined)
164
+ params['expires'] = String(cookie.expires);
165
+ if (cookie.httpOnly !== undefined)
166
+ params['httpOnly'] = cookie.httpOnly;
167
+ if (cookie.secure !== undefined)
168
+ params['secure'] = cookie.secure;
169
+ if (cookie.sameSite !== undefined)
170
+ params['sameSite'] = cookie.sameSite.toLowerCase();
171
+ await this._client.execute('browser_set_cookie', params);
172
+ }
173
+ }
174
+ /**
175
+ * Clear all cookies from the context.
176
+ */
177
+ async clearCookies() {
178
+ await this._client.execute('browser_delete_cookies', {
179
+ context_id: this._contextId,
180
+ });
181
+ }
182
+ // ==================== Storage State ====================
183
+ /**
184
+ * Get the storage state (cookies and local storage origins).
185
+ *
186
+ * Use this to persist session state between runs.
187
+ *
188
+ * @param options - Optional path to save the state to
189
+ * @returns StorageState object
190
+ */
191
+ async storageState(options) {
192
+ const cookies = await this.cookies();
193
+ // Try to get full profile state including fingerprint settings
194
+ let owlProfile;
195
+ try {
196
+ const profileResult = await this._client.execute('browser_get_profile', {
197
+ context_id: this._contextId,
198
+ });
199
+ if (profileResult && typeof profileResult === 'object') {
200
+ owlProfile = profileResult;
201
+ }
202
+ }
203
+ catch {
204
+ // Profile retrieval not supported; continue with cookies only
205
+ }
206
+ const state = {
207
+ cookies,
208
+ origins: [],
209
+ };
210
+ // Store profile data under extension key for restore
211
+ if (owlProfile) {
212
+ state['_owlProfile'] = owlProfile;
213
+ }
214
+ if (options?.path) {
215
+ const { writeFile: fsWriteFile } = await import('node:fs/promises');
216
+ await fsWriteFile(options.path, JSON.stringify(state, null, 2));
217
+ }
218
+ return state;
219
+ }
220
+ // ==================== Network Interception ====================
221
+ /**
222
+ * Intercept network requests matching a URL pattern at the context level.
223
+ *
224
+ * @param url - URL pattern (glob) or RegExp to match
225
+ * @param handler - Handler function to process intercepted requests
226
+ * @param options - Route options (e.g., times)
227
+ */
228
+ async route(url, handler, options) {
229
+ const urlPattern = url instanceof RegExp ? url.source : url;
230
+ await this._client.execute('browser_enable_network_interception', {
231
+ context_id: this._contextId,
232
+ enable: true,
233
+ });
234
+ const result = await this._client.execute('browser_add_network_rule', {
235
+ context_id: this._contextId,
236
+ url_pattern: urlPattern,
237
+ action: 'block',
238
+ is_regex: url instanceof RegExp,
239
+ });
240
+ const res = result;
241
+ const ruleId = String(res['rule_id'] ?? '');
242
+ this._routes.push({
243
+ urlPattern,
244
+ ruleId,
245
+ handler,
246
+ remaining: options?.times ?? null,
247
+ });
248
+ const route = new Route(this._client, this._contextId, ruleId, urlPattern);
249
+ await handler(route);
250
+ }
251
+ /**
252
+ * Remove a previously registered context-level route handler.
253
+ *
254
+ * @param url - URL pattern that was registered
255
+ * @param handler - Optional specific handler to remove
256
+ */
257
+ async unroute(url, handler) {
258
+ const urlPattern = url instanceof RegExp ? url.source : url;
259
+ for (let i = this._routes.length - 1; i >= 0; i--) {
260
+ const entry = this._routes[i];
261
+ if (entry && entry.urlPattern === urlPattern) {
262
+ if (handler === undefined || entry.handler === handler) {
263
+ try {
264
+ await this._client.execute('browser_remove_network_rule', {
265
+ context_id: this._contextId,
266
+ rule_id: entry.ruleId,
267
+ });
268
+ }
269
+ catch {
270
+ // Ignore
271
+ }
272
+ this._routes.splice(i, 1);
273
+ }
274
+ }
275
+ }
276
+ }
277
+ /**
278
+ * Remove all route handlers.
279
+ */
280
+ async unrouteAll() {
281
+ for (const entry of this._routes) {
282
+ try {
283
+ await this._client.execute('browser_remove_network_rule', {
284
+ context_id: this._contextId,
285
+ rule_id: entry.ruleId,
286
+ });
287
+ }
288
+ catch {
289
+ // Ignore
290
+ }
291
+ }
292
+ this._routes.length = 0;
293
+ }
294
+ // ==================== Extra HTTP Headers ====================
295
+ /**
296
+ * Set extra HTTP headers for all requests in this context.
297
+ *
298
+ * No-op: Owl Browser does not support runtime header injection.
299
+ * Custom headers should be configured at context creation via VM profiles.
300
+ *
301
+ * @param headers - Object with header name/value pairs
302
+ */
303
+ async setExtraHTTPHeaders(headers) {
304
+ void headers;
305
+ // Not supported — requires VM profile configuration at context creation
306
+ }
307
+ // ==================== Geolocation ====================
308
+ /**
309
+ * Set the geolocation for the context.
310
+ *
311
+ * No-op: Geolocation is configured at context creation via VM profiles
312
+ * in Owl Browser. Runtime geolocation changes are not supported.
313
+ *
314
+ * @param geolocation - Geolocation coordinates or null to clear
315
+ */
316
+ async setGeolocation(geolocation) {
317
+ void geolocation;
318
+ // Not supported — requires VM profile configuration at context creation
319
+ }
320
+ // ==================== Permissions ====================
321
+ /**
322
+ * Grant permissions to the context.
323
+ *
324
+ * Stub: Browser permissions are managed at the profile level in Owl Browser.
325
+ *
326
+ * @param permissions - Array of permission names
327
+ * @param options - Optional origin filter
328
+ */
329
+ async grantPermissions(permissions, options) {
330
+ void permissions;
331
+ void options;
332
+ }
333
+ /**
334
+ * Clear granted permissions.
335
+ */
336
+ async clearPermissions() {
337
+ // Not directly supported in Owl Browser
338
+ }
339
+ // ==================== Offline ====================
340
+ /**
341
+ * Set the context to offline/online mode.
342
+ *
343
+ * @param offline - true to emulate offline, false for online
344
+ */
345
+ async setOffline(offline) {
346
+ if (offline) {
347
+ // Block all network traffic by adding a catch-all block rule
348
+ await this._client.execute('browser_enable_network_interception', {
349
+ context_id: this._contextId,
350
+ enable: true,
351
+ });
352
+ await this._client.execute('browser_add_network_rule', {
353
+ context_id: this._contextId,
354
+ url_pattern: '*',
355
+ action: 'block',
356
+ });
357
+ }
358
+ else {
359
+ // Remove the catch-all block rule
360
+ await this._client.execute('browser_enable_network_interception', {
361
+ context_id: this._contextId,
362
+ enable: false,
363
+ });
364
+ }
365
+ }
366
+ // ==================== Proxy ====================
367
+ /**
368
+ * Configure proxy settings for this context.
369
+ *
370
+ * @param proxy - Proxy configuration
371
+ */
372
+ async setProxy(proxy) {
373
+ try {
374
+ const proxyUrl = new URL(proxy.server);
375
+ const params = {
376
+ context_id: this._contextId,
377
+ type: proxyUrl.protocol.replace(':', ''),
378
+ host: proxyUrl.hostname,
379
+ port: proxyUrl.port,
380
+ };
381
+ if (proxy.username)
382
+ params['username'] = proxy.username;
383
+ if (proxy.password)
384
+ params['password'] = proxy.password;
385
+ await this._client.execute('browser_set_proxy', params);
386
+ }
387
+ catch {
388
+ // Invalid URL, pass host directly
389
+ await this._client.execute('browser_set_proxy', {
390
+ context_id: this._contextId,
391
+ host: proxy.server,
392
+ });
393
+ }
394
+ }
395
+ // ==================== Init Scripts ====================
396
+ /**
397
+ * Add a script that runs in every page before any other script.
398
+ *
399
+ * @param script - JavaScript code or script path
400
+ * @param arg - Optional argument
401
+ */
402
+ async addInitScript(script, arg) {
403
+ void arg;
404
+ const code = typeof script === 'string' ? script : '';
405
+ if (code) {
406
+ // Execute in the current page; subsequent pages will need re-injection
407
+ await this._client.execute('browser_evaluate', {
408
+ context_id: this._contextId,
409
+ script: code,
410
+ return_value: false,
411
+ });
412
+ }
413
+ }
414
+ /**
415
+ * Expose a function to all pages in this context.
416
+ *
417
+ * @param name - Global function name
418
+ * @param callback - Function implementation
419
+ */
420
+ async exposeFunction(name, callback) {
421
+ void callback;
422
+ await this._client.execute('browser_evaluate', {
423
+ context_id: this._contextId,
424
+ script: `window['${name}'] = function() { console.log('${name} called', ...arguments); }`,
425
+ return_value: false,
426
+ });
427
+ }
428
+ // ==================== Events ====================
429
+ /**
430
+ * Register a context-level event handler.
431
+ *
432
+ * @param event - Event name ('page', 'close', etc.)
433
+ * @param handler - Event handler function
434
+ */
435
+ on(event, handler) {
436
+ void event;
437
+ void handler;
438
+ // Context-level events require WebSocket push notifications
439
+ // which Owl Browser handles via polling
440
+ return this;
441
+ }
442
+ /**
443
+ * Register a one-time context-level event handler.
444
+ *
445
+ * @param event - Event name
446
+ * @param handler - Event handler function
447
+ */
448
+ once(event, handler) {
449
+ void event;
450
+ void handler;
451
+ return this;
452
+ }
453
+ /**
454
+ * Wait for a context-level event.
455
+ *
456
+ * @param event - Event name (e.g., 'page')
457
+ * @param options - Wait options
458
+ * @returns Event data
459
+ */
460
+ async waitForEvent(event, options) {
461
+ const timeout = options?.timeout ?? 30000;
462
+ if (event === 'page') {
463
+ // Set popup policy to new_tab so popups create tabs
464
+ try {
465
+ await this._client.execute('browser_set_popup_policy', {
466
+ context_id: this._contextId,
467
+ policy: 'new_tab',
468
+ });
469
+ }
470
+ catch {
471
+ // May not be supported; continue
472
+ }
473
+ // Snapshot current tabs
474
+ const beforeResult = await this._client.execute('browser_get_tabs', {
475
+ context_id: this._contextId,
476
+ });
477
+ const beforeRes = beforeResult;
478
+ const beforeTabs = (beforeRes['tabs'] ?? []);
479
+ const beforeIds = new Set(beforeTabs.map((t) => String(t['tab_id'] ?? t['id'] ?? '')));
480
+ // Poll for new tab
481
+ const start = Date.now();
482
+ while (Date.now() - start < timeout) {
483
+ await new Promise((r) => setTimeout(r, 200));
484
+ const afterResult = await this._client.execute('browser_get_tabs', {
485
+ context_id: this._contextId,
486
+ });
487
+ const afterRes = afterResult;
488
+ const afterTabs = (afterRes['tabs'] ?? []);
489
+ for (const tab of afterTabs) {
490
+ const tabId = String(tab['tab_id'] ?? tab['id'] ?? '');
491
+ if (tabId && !beforeIds.has(tabId)) {
492
+ const page = new Page(this._client, this._contextId, tabId);
493
+ this._pages.push(page);
494
+ return page;
495
+ }
496
+ }
497
+ }
498
+ throw new Error(`Timeout waiting for new page (${timeout}ms)`);
499
+ }
500
+ // Generic wait fallback
501
+ await new Promise((r) => setTimeout(r, Math.min(timeout, 1000)));
502
+ return null;
503
+ }
504
+ // ==================== Tracing ====================
505
+ /**
506
+ * Tracing interface stub.
507
+ *
508
+ * Owl Browser does not support Playwright tracing, but provides
509
+ * a compatible API surface to prevent errors in migrated code.
510
+ */
511
+ get tracing() {
512
+ return {
513
+ start: async (_options) => { },
514
+ stop: async (_options) => { },
515
+ };
516
+ }
517
+ }
518
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/playwright/context.ts"],"names":[],"mappings":"AAAA;;;;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B,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;oBACvD,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;wBACnC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;wBAC5D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;wBACvB,OAAO,IAAI,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,KAAK,CAAC,CAAC;QACjE,CAAC;QAED,wBAAwB;QACxB,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,oDAAoD;IAEpD;;;;;OAKG;IACH,IAAI,OAAO;QACT,OAAO;YACL,KAAK,EAAE,KAAK,EAAE,QAAkB,EAAE,EAAE,GAAe,CAAC;YACpD,IAAI,EAAE,KAAK,EAAE,QAAkB,EAAE,EAAE,GAAe,CAAC;SACpD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Schema-driven HTML data extraction using cheerio.
3
+ *
4
+ * Pure functions for extracting structured data from HTML strings using
5
+ * a declarative field schema. No side effects, no browser interaction.
6
+ *
7
+ * String field syntax (backward compatible):
8
+ * "selector" -> textContent of the matched element
9
+ * "selector@attr" -> attribute value of the matched element
10
+ * "@attr" -> attribute value of the container itself
11
+ *
12
+ * Object field specs add: type coercion, regex, transforms, nested
13
+ * extraction, multi-value collection, and defaults.
14
+ */
15
+ /** Built-in transform names. */
16
+ export type Transform = 'trim' | 'lowercase' | 'uppercase' | 'number' | 'clean' | 'slug';
17
+ /** Object-based field spec for advanced extraction. */
18
+ export interface ObjectFieldSpec {
19
+ /** CSS selector (default: container itself). */
20
+ selector?: string;
21
+ /** Attribute to extract (default: textContent). */
22
+ attribute?: string;
23
+ /** Return string[] of ALL matches, not just first. */
24
+ all?: boolean;
25
+ /** Type coercion: 'text' (default), 'number', 'html', 'innerHtml'. */
26
+ type?: 'text' | 'number' | 'html' | 'innerHtml';
27
+ /** Regex pattern to apply on extracted text. */
28
+ pattern?: string;
29
+ /** Capture group index (default: 0 = full match). */
30
+ group?: number;
31
+ /** Transform pipeline applied after extraction. */
32
+ transform?: Transform | Transform[];
33
+ /** Fallback value when extraction returns null. */
34
+ default?: string | number | null;
35
+ /** Nested extraction: extract sub-items within each container. */
36
+ nested?: {
37
+ selector: string;
38
+ fields: Record<string, FieldSpec>;
39
+ limit?: number;
40
+ };
41
+ }
42
+ /** A field spec is either a string shorthand or an object spec. */
43
+ export type FieldSpec = string | ObjectFieldSpec;
44
+ /** Extracted record — values can be string, number, null, string[], or nested records. */
45
+ export type ExtractedRecord = Record<string, unknown>;
46
+ /** Meta tag extraction result. */
47
+ export interface MetaData {
48
+ title: string | null;
49
+ description: string | null;
50
+ canonical: string | null;
51
+ og: Record<string, string>;
52
+ twitter: Record<string, string>;
53
+ other: Record<string, string>;
54
+ }
55
+ /**
56
+ * Extract structured data from all elements matching containerSelector.
57
+ *
58
+ * @param html - Raw HTML string to parse
59
+ * @param containerSelector - CSS selector for repeating container elements
60
+ * @param fields - Mapping of output field names to extraction specs
61
+ * @returns Array of objects, one per matched container
62
+ */
63
+ export declare function queryAll(html: string, containerSelector: string, fields: Record<string, FieldSpec>): ExtractedRecord[];
64
+ /**
65
+ * Extract structured data from the first element matching containerSelector.
66
+ *
67
+ * @param html - Raw HTML string to parse
68
+ * @param containerSelector - CSS selector for the container element
69
+ * @param fields - Mapping of output field names to extraction specs
70
+ * @returns Single record or null if no match
71
+ */
72
+ export declare function queryFirst(html: string, containerSelector: string, fields: Record<string, FieldSpec>): ExtractedRecord | null;
73
+ /**
74
+ * Extract a <table> as an array of records.
75
+ *
76
+ * Auto-detects headers from <th> or the first row. Handles colspan/rowspan.
77
+ *
78
+ * @param html - Raw HTML string
79
+ * @param selector - CSS selector for the table (default: 'table')
80
+ * @param options - Optional headers override
81
+ * @returns Array of records with header keys
82
+ */
83
+ export declare function extractTable(html: string, selector?: string, options?: {
84
+ headers?: string[];
85
+ }): ExtractedRecord[];
86
+ /**
87
+ * Extract meta tags from HTML.
88
+ *
89
+ * @param html - Raw HTML string
90
+ * @returns MetaData with title, description, canonical, og, twitter, and other meta tags
91
+ */
92
+ export declare function extractMeta(html: string): MetaData;
93
+ /**
94
+ * Extract JSON-LD structured data from HTML.
95
+ *
96
+ * @param html - Raw HTML string
97
+ * @returns Array of parsed JSON-LD objects
98
+ */
99
+ export declare function extractStructuredData(html: string): object[];
100
+ /**
101
+ * Count elements matching a CSS selector.
102
+ *
103
+ * @param html - Raw HTML string
104
+ * @param selector - CSS selector
105
+ * @returns Number of matching elements
106
+ */
107
+ export declare function countElements(html: string, selector: string): number;
108
+ //# sourceMappingURL=extractor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../src/playwright/extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH,gCAAgC;AAChC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEzF,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,sEAAsE;IACtE,IAAI,CAAC,EAAE,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