@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.
- package/README.md +107 -0
- package/dist/extraction/content-cleaner.d.ts +40 -0
- package/dist/extraction/content-cleaner.d.ts.map +1 -0
- package/dist/extraction/content-cleaner.js +393 -0
- package/dist/extraction/content-cleaner.js.map +1 -0
- package/dist/extraction/extractor.d.ts +139 -0
- package/dist/extraction/extractor.d.ts.map +1 -0
- package/dist/extraction/extractor.js +212 -0
- package/dist/extraction/extractor.js.map +1 -0
- package/dist/extraction/html-processor.d.ts +75 -0
- package/dist/extraction/html-processor.d.ts.map +1 -0
- package/dist/extraction/html-processor.js +192 -0
- package/dist/extraction/html-processor.js.map +1 -0
- package/dist/extraction/index.d.ts +14 -0
- package/dist/extraction/index.d.ts.map +1 -0
- package/dist/extraction/index.js +19 -0
- package/dist/extraction/index.js.map +1 -0
- package/dist/extraction/list-extractor.d.ts +24 -0
- package/dist/extraction/list-extractor.d.ts.map +1 -0
- package/dist/extraction/list-extractor.js +303 -0
- package/dist/extraction/list-extractor.js.map +1 -0
- package/dist/extraction/meta-extractor.d.ts +40 -0
- package/dist/extraction/meta-extractor.d.ts.map +1 -0
- package/dist/extraction/meta-extractor.js +216 -0
- package/dist/extraction/meta-extractor.js.map +1 -0
- package/dist/extraction/pagination.d.ts +29 -0
- package/dist/extraction/pagination.d.ts.map +1 -0
- package/dist/extraction/pagination.js +323 -0
- package/dist/extraction/pagination.js.map +1 -0
- package/dist/extraction/pattern-detector.d.ts +16 -0
- package/dist/extraction/pattern-detector.d.ts.map +1 -0
- package/dist/extraction/pattern-detector.js +390 -0
- package/dist/extraction/pattern-detector.js.map +1 -0
- package/dist/extraction/scrape-session.d.ts +23 -0
- package/dist/extraction/scrape-session.d.ts.map +1 -0
- package/dist/extraction/scrape-session.js +192 -0
- package/dist/extraction/scrape-session.js.map +1 -0
- package/dist/extraction/selector-engine.d.ts +23 -0
- package/dist/extraction/selector-engine.d.ts.map +1 -0
- package/dist/extraction/selector-engine.js +127 -0
- package/dist/extraction/selector-engine.js.map +1 -0
- package/dist/extraction/table-extractor.d.ts +29 -0
- package/dist/extraction/table-extractor.d.ts.map +1 -0
- package/dist/extraction/table-extractor.js +282 -0
- package/dist/extraction/table-extractor.js.map +1 -0
- package/dist/extraction/transforms.d.ts +47 -0
- package/dist/extraction/transforms.d.ts.map +1 -0
- package/dist/extraction/transforms.js +277 -0
- package/dist/extraction/transforms.js.map +1 -0
- package/dist/extraction/types.d.ts +199 -0
- package/dist/extraction/types.d.ts.map +1 -0
- package/dist/extraction/types.js +5 -0
- package/dist/extraction/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/playwright/browser-type.d.ts +101 -0
- package/dist/playwright/browser-type.d.ts.map +1 -0
- package/dist/playwright/browser-type.js +134 -0
- package/dist/playwright/browser-type.js.map +1 -0
- package/dist/playwright/browser.d.ts +98 -0
- package/dist/playwright/browser.d.ts.map +1 -0
- package/dist/playwright/browser.js +229 -0
- package/dist/playwright/browser.js.map +1 -0
- package/dist/playwright/context.d.ts +217 -0
- package/dist/playwright/context.d.ts.map +1 -0
- package/dist/playwright/context.js +518 -0
- package/dist/playwright/context.js.map +1 -0
- package/dist/playwright/extractor.d.ts +108 -0
- package/dist/playwright/extractor.d.ts.map +1 -0
- package/dist/playwright/extractor.js +404 -0
- package/dist/playwright/extractor.js.map +1 -0
- package/dist/playwright/frame.d.ts +147 -0
- package/dist/playwright/frame.d.ts.map +1 -0
- package/dist/playwright/frame.js +492 -0
- package/dist/playwright/frame.js.map +1 -0
- package/dist/playwright/index.d.ts +163 -0
- package/dist/playwright/index.d.ts.map +1 -0
- package/dist/playwright/index.js +313 -0
- package/dist/playwright/index.js.map +1 -0
- package/dist/playwright/keyboard.d.ts +74 -0
- package/dist/playwright/keyboard.d.ts.map +1 -0
- package/dist/playwright/keyboard.js +187 -0
- package/dist/playwright/keyboard.js.map +1 -0
- package/dist/playwright/locator.d.ts +237 -0
- package/dist/playwright/locator.d.ts.map +1 -0
- package/dist/playwright/locator.js +667 -0
- package/dist/playwright/locator.js.map +1 -0
- package/dist/playwright/mouse.d.ts +82 -0
- package/dist/playwright/mouse.d.ts.map +1 -0
- package/dist/playwright/mouse.js +137 -0
- package/dist/playwright/mouse.js.map +1 -0
- package/dist/playwright/page-helpers.d.ts +267 -0
- package/dist/playwright/page-helpers.d.ts.map +1 -0
- package/dist/playwright/page-helpers.js +449 -0
- package/dist/playwright/page-helpers.js.map +1 -0
- package/dist/playwright/page.d.ts +605 -0
- package/dist/playwright/page.d.ts.map +1 -0
- package/dist/playwright/page.js +1698 -0
- package/dist/playwright/page.js.map +1 -0
- package/dist/playwright/response.d.ts +100 -0
- package/dist/playwright/response.d.ts.map +1 -0
- package/dist/playwright/response.js +194 -0
- package/dist/playwright/response.js.map +1 -0
- package/dist/playwright/types.d.ts +354 -0
- package/dist/playwright/types.d.ts.map +1 -0
- package/dist/playwright/types.js +8 -0
- package/dist/playwright/types.js.map +1 -0
- package/openapi.json +327 -35
- package/package.json +10 -1
|
@@ -0,0 +1,404 @@
|
|
|
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
|
+
import { load } from 'cheerio';
|
|
16
|
+
// ==================== Public Functions ====================
|
|
17
|
+
/**
|
|
18
|
+
* Extract structured data from all elements matching containerSelector.
|
|
19
|
+
*
|
|
20
|
+
* @param html - Raw HTML string to parse
|
|
21
|
+
* @param containerSelector - CSS selector for repeating container elements
|
|
22
|
+
* @param fields - Mapping of output field names to extraction specs
|
|
23
|
+
* @returns Array of objects, one per matched container
|
|
24
|
+
*/
|
|
25
|
+
export function queryAll(html, containerSelector, fields) {
|
|
26
|
+
const $ = load(html);
|
|
27
|
+
const results = [];
|
|
28
|
+
$(containerSelector).each((_i, el) => {
|
|
29
|
+
results.push(extractItem($, $(el), fields));
|
|
30
|
+
});
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract structured data from the first element matching containerSelector.
|
|
35
|
+
*
|
|
36
|
+
* @param html - Raw HTML string to parse
|
|
37
|
+
* @param containerSelector - CSS selector for the container element
|
|
38
|
+
* @param fields - Mapping of output field names to extraction specs
|
|
39
|
+
* @returns Single record or null if no match
|
|
40
|
+
*/
|
|
41
|
+
export function queryFirst(html, containerSelector, fields) {
|
|
42
|
+
const $ = load(html);
|
|
43
|
+
const container = $(containerSelector).first();
|
|
44
|
+
if (container.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
return extractItem($, container, fields);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Extract a <table> as an array of records.
|
|
50
|
+
*
|
|
51
|
+
* Auto-detects headers from <th> or the first row. Handles colspan/rowspan.
|
|
52
|
+
*
|
|
53
|
+
* @param html - Raw HTML string
|
|
54
|
+
* @param selector - CSS selector for the table (default: 'table')
|
|
55
|
+
* @param options - Optional headers override
|
|
56
|
+
* @returns Array of records with header keys
|
|
57
|
+
*/
|
|
58
|
+
export function extractTable(html, selector = 'table', options) {
|
|
59
|
+
const $ = load(html);
|
|
60
|
+
const table = $(selector).first();
|
|
61
|
+
if (table.length === 0)
|
|
62
|
+
return [];
|
|
63
|
+
let headers = options?.headers ?? [];
|
|
64
|
+
// Auto-detect headers from <th> elements
|
|
65
|
+
if (headers.length === 0) {
|
|
66
|
+
const thElements = table.find('thead th, tr:first-child th');
|
|
67
|
+
if (thElements.length > 0) {
|
|
68
|
+
thElements.each((_i, th) => {
|
|
69
|
+
headers.push($(th).text().trim());
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// If still no headers, use first row as headers
|
|
74
|
+
const rows = table.find('tbody tr, tr');
|
|
75
|
+
let startIdx = 0;
|
|
76
|
+
if (headers.length === 0 && rows.length > 0) {
|
|
77
|
+
const firstRow = $(rows[0]);
|
|
78
|
+
firstRow.find('td, th').each((_i, cell) => {
|
|
79
|
+
headers.push($(cell).text().trim());
|
|
80
|
+
});
|
|
81
|
+
startIdx = 1;
|
|
82
|
+
}
|
|
83
|
+
// Skip header rows in tbody
|
|
84
|
+
const dataRows = [];
|
|
85
|
+
rows.each((i, row) => {
|
|
86
|
+
if (i < startIdx)
|
|
87
|
+
return;
|
|
88
|
+
// Skip rows that are purely <th> rows (header rows in tbody)
|
|
89
|
+
const tds = $(row).find('td');
|
|
90
|
+
const ths = $(row).find('th');
|
|
91
|
+
if (tds.length === 0 && ths.length > 0)
|
|
92
|
+
return;
|
|
93
|
+
dataRows.push($(row));
|
|
94
|
+
});
|
|
95
|
+
// Build a grid to handle colspan/rowspan
|
|
96
|
+
const grid = [];
|
|
97
|
+
for (let r = 0; r < dataRows.length; r++) {
|
|
98
|
+
if (!grid[r])
|
|
99
|
+
grid[r] = [];
|
|
100
|
+
const cells = dataRows[r].find('td, th');
|
|
101
|
+
let cellIdx = 0;
|
|
102
|
+
cells.each((_ci, cell) => {
|
|
103
|
+
const $cell = $(cell);
|
|
104
|
+
const colspan = parseInt($cell.attr('colspan') ?? '1', 10) || 1;
|
|
105
|
+
const rowspan = parseInt($cell.attr('rowspan') ?? '1', 10) || 1;
|
|
106
|
+
const text = $cell.text().trim();
|
|
107
|
+
// Find next empty column in current row
|
|
108
|
+
while (grid[r][cellIdx] !== undefined)
|
|
109
|
+
cellIdx++;
|
|
110
|
+
for (let dr = 0; dr < rowspan; dr++) {
|
|
111
|
+
for (let dc = 0; dc < colspan; dc++) {
|
|
112
|
+
if (!grid[r + dr])
|
|
113
|
+
grid[r + dr] = [];
|
|
114
|
+
grid[r + dr][cellIdx + dc] = text;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
cellIdx += colspan;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Convert grid to records
|
|
121
|
+
const results = [];
|
|
122
|
+
for (const row of grid) {
|
|
123
|
+
if (!row)
|
|
124
|
+
continue;
|
|
125
|
+
const record = {};
|
|
126
|
+
for (let c = 0; c < headers.length; c++) {
|
|
127
|
+
const key = headers[c] || `col_${c}`;
|
|
128
|
+
record[key] = row[c] ?? null;
|
|
129
|
+
}
|
|
130
|
+
results.push(record);
|
|
131
|
+
}
|
|
132
|
+
return results;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Extract meta tags from HTML.
|
|
136
|
+
*
|
|
137
|
+
* @param html - Raw HTML string
|
|
138
|
+
* @returns MetaData with title, description, canonical, og, twitter, and other meta tags
|
|
139
|
+
*/
|
|
140
|
+
export function extractMeta(html) {
|
|
141
|
+
const $ = load(html);
|
|
142
|
+
const result = {
|
|
143
|
+
title: null,
|
|
144
|
+
description: null,
|
|
145
|
+
canonical: null,
|
|
146
|
+
og: {},
|
|
147
|
+
twitter: {},
|
|
148
|
+
other: {},
|
|
149
|
+
};
|
|
150
|
+
// Title
|
|
151
|
+
const titleEl = $('title').first();
|
|
152
|
+
if (titleEl.length > 0) {
|
|
153
|
+
result.title = titleEl.text().trim() || null;
|
|
154
|
+
}
|
|
155
|
+
// Canonical
|
|
156
|
+
const canonicalEl = $('link[rel="canonical"]').first();
|
|
157
|
+
if (canonicalEl.length > 0) {
|
|
158
|
+
result.canonical = canonicalEl.attr('href') ?? null;
|
|
159
|
+
}
|
|
160
|
+
// Meta tags
|
|
161
|
+
$('meta').each((_i, el) => {
|
|
162
|
+
const $el = $(el);
|
|
163
|
+
const name = $el.attr('name') ?? $el.attr('property') ?? '';
|
|
164
|
+
const content = $el.attr('content') ?? '';
|
|
165
|
+
if (!name || !content)
|
|
166
|
+
return;
|
|
167
|
+
if (name === 'description') {
|
|
168
|
+
result.description = content;
|
|
169
|
+
}
|
|
170
|
+
else if (name.startsWith('og:')) {
|
|
171
|
+
result.og[name.slice(3)] = content;
|
|
172
|
+
}
|
|
173
|
+
else if (name.startsWith('twitter:')) {
|
|
174
|
+
result.twitter[name.slice(8)] = content;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
result.other[name] = content;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Extract JSON-LD structured data from HTML.
|
|
184
|
+
*
|
|
185
|
+
* @param html - Raw HTML string
|
|
186
|
+
* @returns Array of parsed JSON-LD objects
|
|
187
|
+
*/
|
|
188
|
+
export function extractStructuredData(html) {
|
|
189
|
+
const $ = load(html);
|
|
190
|
+
const results = [];
|
|
191
|
+
$('script[type="application/ld+json"]').each((_i, el) => {
|
|
192
|
+
const text = $(el).html();
|
|
193
|
+
if (!text)
|
|
194
|
+
return;
|
|
195
|
+
try {
|
|
196
|
+
const parsed = JSON.parse(text);
|
|
197
|
+
if (Array.isArray(parsed)) {
|
|
198
|
+
results.push(...parsed);
|
|
199
|
+
}
|
|
200
|
+
else if (typeof parsed === 'object' && parsed !== null) {
|
|
201
|
+
results.push(parsed);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// Skip malformed JSON-LD
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return results;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Count elements matching a CSS selector.
|
|
212
|
+
*
|
|
213
|
+
* @param html - Raw HTML string
|
|
214
|
+
* @param selector - CSS selector
|
|
215
|
+
* @returns Number of matching elements
|
|
216
|
+
*/
|
|
217
|
+
export function countElements(html, selector) {
|
|
218
|
+
const $ = load(html);
|
|
219
|
+
return $(selector).length;
|
|
220
|
+
}
|
|
221
|
+
// ==================== Internal Helpers ====================
|
|
222
|
+
/**
|
|
223
|
+
* Extract all fields from a single container element.
|
|
224
|
+
*/
|
|
225
|
+
function extractItem($, container, fields) {
|
|
226
|
+
const record = {};
|
|
227
|
+
for (const [name, spec] of Object.entries(fields)) {
|
|
228
|
+
record[name] = resolveField($, container, spec);
|
|
229
|
+
}
|
|
230
|
+
return record;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Resolve a field spec (string or object) to a value.
|
|
234
|
+
*/
|
|
235
|
+
function resolveField($, container, spec) {
|
|
236
|
+
if (typeof spec === 'string') {
|
|
237
|
+
return extractStringField($, container, spec);
|
|
238
|
+
}
|
|
239
|
+
return extractObjectField($, container, spec);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Extract a field value using a string spec (backward compatible).
|
|
243
|
+
*/
|
|
244
|
+
function extractStringField($, container, spec) {
|
|
245
|
+
const atPos = spec.lastIndexOf('@');
|
|
246
|
+
if (atPos >= 0) {
|
|
247
|
+
const sel = spec.slice(0, atPos).trim();
|
|
248
|
+
const attr = spec.slice(atPos + 1);
|
|
249
|
+
const target = sel ? container.find(sel).first() : container;
|
|
250
|
+
if (target.length === 0)
|
|
251
|
+
return null;
|
|
252
|
+
if (attr === 'outerHTML')
|
|
253
|
+
return $.html(target) ?? null;
|
|
254
|
+
if (attr === 'innerHTML')
|
|
255
|
+
return target.html() ?? null;
|
|
256
|
+
return target.attr(attr) ?? null;
|
|
257
|
+
}
|
|
258
|
+
// No '@' -> extract text content
|
|
259
|
+
const el = spec.trim() ? container.find(spec).first() : container;
|
|
260
|
+
if (el.length === 0)
|
|
261
|
+
return null;
|
|
262
|
+
return el.text().trim() || null;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Extract a field value using an object spec.
|
|
266
|
+
*/
|
|
267
|
+
function extractObjectField($, container, spec) {
|
|
268
|
+
// Handle nested extraction
|
|
269
|
+
if (spec.nested) {
|
|
270
|
+
return extractNested($, container, spec.nested);
|
|
271
|
+
}
|
|
272
|
+
const sel = spec.selector;
|
|
273
|
+
const attr = spec.attribute;
|
|
274
|
+
if (spec.all) {
|
|
275
|
+
// Multi-value: return array of all matches
|
|
276
|
+
const values = [];
|
|
277
|
+
const targets = sel ? container.find(sel) : container;
|
|
278
|
+
targets.each((_i, el) => {
|
|
279
|
+
let raw = extractRawValue($, $(el), attr, spec.type);
|
|
280
|
+
raw = applyPattern(raw, spec.pattern, spec.group);
|
|
281
|
+
raw = applyTransforms(raw, spec.transform);
|
|
282
|
+
const coerced = coerceType(raw, spec.type);
|
|
283
|
+
values.push(coerced ?? spec.default ?? null);
|
|
284
|
+
});
|
|
285
|
+
return values;
|
|
286
|
+
}
|
|
287
|
+
// Single value
|
|
288
|
+
const target = sel ? container.find(sel).first() : container;
|
|
289
|
+
if (target.length === 0) {
|
|
290
|
+
return spec.default ?? null;
|
|
291
|
+
}
|
|
292
|
+
let raw = extractRawValue($, target, attr, spec.type);
|
|
293
|
+
raw = applyPattern(raw, spec.pattern, spec.group);
|
|
294
|
+
raw = applyTransforms(raw, spec.transform);
|
|
295
|
+
const coerced = coerceType(raw, spec.type);
|
|
296
|
+
return coerced ?? spec.default ?? null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Extract the raw value from an element.
|
|
300
|
+
*/
|
|
301
|
+
function extractRawValue($, el, attr, type) {
|
|
302
|
+
if (el.length === 0)
|
|
303
|
+
return null;
|
|
304
|
+
if (type === 'html')
|
|
305
|
+
return $.html(el) ?? null;
|
|
306
|
+
if (type === 'innerHtml')
|
|
307
|
+
return el.html() ?? null;
|
|
308
|
+
if (attr) {
|
|
309
|
+
if (attr === 'outerHTML')
|
|
310
|
+
return $.html(el) ?? null;
|
|
311
|
+
if (attr === 'innerHTML')
|
|
312
|
+
return el.html() ?? null;
|
|
313
|
+
return el.attr(attr) ?? null;
|
|
314
|
+
}
|
|
315
|
+
return el.text().trim() || null;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Apply a regex pattern to extract a substring.
|
|
319
|
+
*/
|
|
320
|
+
function applyPattern(value, pattern, group) {
|
|
321
|
+
if (!pattern || value === null)
|
|
322
|
+
return value;
|
|
323
|
+
try {
|
|
324
|
+
const re = new RegExp(pattern);
|
|
325
|
+
const match = re.exec(value);
|
|
326
|
+
if (!match)
|
|
327
|
+
return null;
|
|
328
|
+
return match[group ?? 0] ?? null;
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
return value;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Apply a pipeline of transforms to a string value.
|
|
336
|
+
*/
|
|
337
|
+
function applyTransforms(value, transforms) {
|
|
338
|
+
if (!transforms || value === null)
|
|
339
|
+
return value;
|
|
340
|
+
const pipeline = Array.isArray(transforms) ? transforms : [transforms];
|
|
341
|
+
let result = value;
|
|
342
|
+
for (const t of pipeline) {
|
|
343
|
+
if (result === null)
|
|
344
|
+
break;
|
|
345
|
+
result = applyOneTransform(result, t);
|
|
346
|
+
}
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Apply a single transform to a string.
|
|
351
|
+
*/
|
|
352
|
+
function applyOneTransform(value, transform) {
|
|
353
|
+
switch (transform) {
|
|
354
|
+
case 'trim':
|
|
355
|
+
return value.trim();
|
|
356
|
+
case 'lowercase':
|
|
357
|
+
return value.toLowerCase();
|
|
358
|
+
case 'uppercase':
|
|
359
|
+
return value.toUpperCase();
|
|
360
|
+
case 'number': {
|
|
361
|
+
const cleaned = value.replace(/[^0-9.\-,]/g, '').replace(/,/g, '');
|
|
362
|
+
const n = parseFloat(cleaned);
|
|
363
|
+
return isNaN(n) ? null : String(n);
|
|
364
|
+
}
|
|
365
|
+
case 'clean':
|
|
366
|
+
return value.replace(/\s+/g, ' ').trim();
|
|
367
|
+
case 'slug':
|
|
368
|
+
return value
|
|
369
|
+
.toLowerCase()
|
|
370
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
371
|
+
.replace(/^-|-$/g, '');
|
|
372
|
+
default:
|
|
373
|
+
return value;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Coerce a value to the specified type.
|
|
378
|
+
*/
|
|
379
|
+
function coerceType(value, type) {
|
|
380
|
+
if (value === null)
|
|
381
|
+
return null;
|
|
382
|
+
if (type === 'number') {
|
|
383
|
+
const cleaned = value.replace(/[^0-9.\-,]/g, '').replace(/,/g, '');
|
|
384
|
+
const n = parseFloat(cleaned);
|
|
385
|
+
return isNaN(n) ? null : n;
|
|
386
|
+
}
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Extract nested sub-items within a container.
|
|
391
|
+
*/
|
|
392
|
+
function extractNested($, container, nested) {
|
|
393
|
+
const results = [];
|
|
394
|
+
const elements = container.find(nested.selector);
|
|
395
|
+
const limit = nested.limit ?? elements.length;
|
|
396
|
+
elements.each((i, el) => {
|
|
397
|
+
if (i >= limit)
|
|
398
|
+
return false;
|
|
399
|
+
results.push(extractItem($, $(el), nested.fields));
|
|
400
|
+
return undefined;
|
|
401
|
+
});
|
|
402
|
+
return results;
|
|
403
|
+
}
|
|
404
|
+
//# sourceMappingURL=extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../src/playwright/extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAiC,MAAM,SAAS,CAAC;AAkD9D,6DAA6D;AAE7D;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAY,EACZ,iBAAyB,EACzB,MAAiC;IAEjC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,C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C,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CACpB,CAAa,EACb,SAA2B,EAC3B,MAA+E;IAE/E,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC;IAE9C,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;QACtB,IAAI,CAAC,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACnD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playwright-compatible Frame and FrameLocator classes for Owl Browser.
|
|
3
|
+
*
|
|
4
|
+
* Provides frame isolation support via browser_switch_to_frame /
|
|
5
|
+
* browser_switch_to_main_frame tools, wrapping that mechanism into
|
|
6
|
+
* Playwright's Frame and FrameLocator API surfaces.
|
|
7
|
+
*/
|
|
8
|
+
import type { OwlBrowser } from '../client.js';
|
|
9
|
+
import type { GotoOptions, WaitForSelectorOptions, ClickOptions, FillOptions, TypeOptions, CheckOptions, SelectOptionValue, SelectOptionOptions, BoundingBox } from './types.js';
|
|
10
|
+
import type { Locator } from './locator.js';
|
|
11
|
+
/**
|
|
12
|
+
* Frame represents an iframe or the main frame of a page.
|
|
13
|
+
*
|
|
14
|
+
* Operations on a Frame are scoped to that frame's DOM.
|
|
15
|
+
* After switching to a frame, subsequent commands target that frame
|
|
16
|
+
* until switchToMain() is called.
|
|
17
|
+
*/
|
|
18
|
+
export declare class Frame {
|
|
19
|
+
private readonly _client;
|
|
20
|
+
private readonly _contextId;
|
|
21
|
+
private readonly _frameSelector;
|
|
22
|
+
private readonly _name;
|
|
23
|
+
private readonly _url;
|
|
24
|
+
private readonly _parentFrame;
|
|
25
|
+
private _detached;
|
|
26
|
+
constructor(client: OwlBrowser, contextId: string, frameSelector: string | null, name?: string, url?: string, parentFrame?: Frame | null);
|
|
27
|
+
/** Frame name attribute or generated identifier. */
|
|
28
|
+
name(): string;
|
|
29
|
+
/** Frame URL. */
|
|
30
|
+
url(): string;
|
|
31
|
+
/** Whether this is the main frame. */
|
|
32
|
+
isMainFrame(): boolean;
|
|
33
|
+
/** Whether the frame has been detached. */
|
|
34
|
+
isDetached(): boolean;
|
|
35
|
+
/** Parent frame, or null for the main frame. */
|
|
36
|
+
parentFrame(): Frame | null;
|
|
37
|
+
/** Child frames. Returns empty array (requires runtime enumeration). */
|
|
38
|
+
childFrames(): Frame[];
|
|
39
|
+
/**
|
|
40
|
+
* Switch browser focus to this frame.
|
|
41
|
+
* Subsequent DOM operations will target this frame's document.
|
|
42
|
+
*/
|
|
43
|
+
focus(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Navigate this frame to a URL.
|
|
46
|
+
*
|
|
47
|
+
* @param url - Target URL
|
|
48
|
+
* @param options - Navigation options
|
|
49
|
+
*/
|
|
50
|
+
goto(url: string, options?: GotoOptions): Promise<void>;
|
|
51
|
+
/** Click an element within this frame. */
|
|
52
|
+
click(selector: string, options?: ClickOptions): Promise<void>;
|
|
53
|
+
/** Fill an input within this frame. */
|
|
54
|
+
fill(selector: string, value: string, options?: FillOptions): Promise<void>;
|
|
55
|
+
/** Type text into an input within this frame. */
|
|
56
|
+
type(selector: string, text: string, options?: TypeOptions): Promise<void>;
|
|
57
|
+
/** Check a checkbox within this frame. */
|
|
58
|
+
check(selector: string, options?: CheckOptions): Promise<void>;
|
|
59
|
+
/** Uncheck a checkbox within this frame. */
|
|
60
|
+
uncheck(selector: string, options?: CheckOptions): Promise<void>;
|
|
61
|
+
/** Select an option from a dropdown within this frame. */
|
|
62
|
+
selectOption(selector: string, values: SelectOptionValue, options?: SelectOptionOptions): Promise<string[]>;
|
|
63
|
+
/** Wait for a selector within this frame. */
|
|
64
|
+
waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<void>;
|
|
65
|
+
/** Extract text content of an element within this frame. */
|
|
66
|
+
textContent(selector: string): Promise<string | null>;
|
|
67
|
+
/** Get inner HTML of an element within this frame. */
|
|
68
|
+
innerHTML(selector: string): Promise<string>;
|
|
69
|
+
/** Get an attribute value from an element within this frame. */
|
|
70
|
+
getAttribute(selector: string, name: string): Promise<string | null>;
|
|
71
|
+
/** Get bounding box of an element within this frame. */
|
|
72
|
+
boundingBox(selector: string): Promise<BoundingBox | null>;
|
|
73
|
+
/** Evaluate JavaScript within this frame. */
|
|
74
|
+
evaluate<R>(pageFunction: string | ((...args: unknown[]) => R), arg?: unknown): Promise<R>;
|
|
75
|
+
/** Create a Locator scoped to this frame (returns Locator from page). */
|
|
76
|
+
locator(_selector: string): never;
|
|
77
|
+
/** Mark frame as detached. */
|
|
78
|
+
_markDetached(): void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* FrameLocator provides a scoped interface for interacting with iframe content.
|
|
82
|
+
*
|
|
83
|
+
* Usage: page.frameLocator('#iframe').locator('#button').click()
|
|
84
|
+
*
|
|
85
|
+
* The FrameLocator switches to the target frame before each operation,
|
|
86
|
+
* then creates a Locator that operates within that frame context.
|
|
87
|
+
*/
|
|
88
|
+
export declare class FrameLocator {
|
|
89
|
+
private readonly _client;
|
|
90
|
+
private readonly _contextId;
|
|
91
|
+
private readonly _frameSelector;
|
|
92
|
+
private readonly _page;
|
|
93
|
+
constructor(client: OwlBrowser, contextId: string, frameSelector: string, page: {
|
|
94
|
+
locator(selector: string): Locator;
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Create a Locator for an element inside this frame.
|
|
98
|
+
*
|
|
99
|
+
* The returned Locator will switch to this frame before executing operations.
|
|
100
|
+
*
|
|
101
|
+
* @param selector - CSS selector within the frame
|
|
102
|
+
* @returns A FrameScopedLocator that auto-switches to the iframe
|
|
103
|
+
*/
|
|
104
|
+
locator(selector: string): FrameScopedLocator;
|
|
105
|
+
/** Create a nested FrameLocator for iframes inside this frame. */
|
|
106
|
+
frameLocator(selector: string): FrameLocator;
|
|
107
|
+
/** Return the first matching frame locator. */
|
|
108
|
+
first(): FrameLocator;
|
|
109
|
+
/** Return the last matching frame locator. */
|
|
110
|
+
last(): FrameLocator;
|
|
111
|
+
/** Return the nth matching frame locator. */
|
|
112
|
+
nth(_index: number): FrameLocator;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A Locator that automatically switches to a specific frame before operations.
|
|
116
|
+
*/
|
|
117
|
+
export declare class FrameScopedLocator {
|
|
118
|
+
private readonly _client;
|
|
119
|
+
private readonly _contextId;
|
|
120
|
+
private readonly _frameSelector;
|
|
121
|
+
private readonly _selector;
|
|
122
|
+
private readonly _page;
|
|
123
|
+
constructor(client: OwlBrowser, contextId: string, frameSelector: string, selector: string, page: {
|
|
124
|
+
locator(selector: string): Locator;
|
|
125
|
+
});
|
|
126
|
+
private _switchToFrame;
|
|
127
|
+
private _switchToMain;
|
|
128
|
+
/** Click the element inside the frame. */
|
|
129
|
+
click(): Promise<void>;
|
|
130
|
+
/** Fill the element inside the frame. */
|
|
131
|
+
fill(value: string): Promise<void>;
|
|
132
|
+
/** Type text into element inside the frame. */
|
|
133
|
+
type(text: string): Promise<void>;
|
|
134
|
+
/** Get text content of element inside the frame. */
|
|
135
|
+
textContent(): Promise<string | null>;
|
|
136
|
+
/** Check if element is visible inside the frame. */
|
|
137
|
+
isVisible(): Promise<boolean>;
|
|
138
|
+
/** Wait for element inside the frame. */
|
|
139
|
+
waitFor(options?: {
|
|
140
|
+
state?: string;
|
|
141
|
+
timeout?: number;
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
/** Create a child locator within the frame. */
|
|
144
|
+
locator(selector: string): FrameScopedLocator;
|
|
145
|
+
toString(): string;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=frame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../../src/playwright/frame.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EACV,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;;;GAMG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,SAAS,CAAS;gBAGxB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GAAG,IAAI,EAC5B,IAAI,CAAC,EAAE,MAAM,EACb,GAAG,CAAC,EAAE,MAAM,EACZ,WAAW,CAAC,EAAE,KAAK,GAAG,IAAI;IAU5B,oDAAoD;IACpD,IAAI,IAAI,MAAM;IAId,iB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