@crawlee/playwright 4.0.0-beta.306 → 4.0.0-beta.308
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/internals/utils/playwright-utils.js +11 -17
- package/package.json +10 -10
|
@@ -22,7 +22,7 @@ import { createRequire } from 'node:module';
|
|
|
22
22
|
import vm from 'node:vm';
|
|
23
23
|
import { Configuration, KeyValueStore, serviceLocator, SessionError, validators } from '@crawlee/browser';
|
|
24
24
|
import { sleep } from '@crawlee/utils';
|
|
25
|
-
import { expandShadowRoots, parseArgument, schemas } from '@crawlee/utils/internal';
|
|
25
|
+
import { expandShadowRoots, parseArgument, schemas, snapshotPageWithIframes } from '@crawlee/utils/internal';
|
|
26
26
|
import { z } from 'zod';
|
|
27
27
|
import { LruCache } from '@apify/datastructures';
|
|
28
28
|
import { enqueueLinksByClickingElements } from '../enqueue-links/click-elements.js';
|
|
@@ -400,35 +400,27 @@ export async function saveSnapshot(page, options = {}) {
|
|
|
400
400
|
*/
|
|
401
401
|
export async function parseWithCheerio(page, ignoreShadowRoots = false, ignoreIframes = false) {
|
|
402
402
|
parseArgument(page, validators.browserPage);
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
: (await page.evaluate(`(${expandShadowRoots.toString()})(document)`));
|
|
406
|
-
const pageContent = html || (await page.content());
|
|
403
|
+
const snapshot = await page.evaluateHandle(`(${snapshotPageWithIframes.toString()})(document, ${ignoreShadowRoots ? 'null' : expandShadowRoots.toString()})`);
|
|
404
|
+
const pageContent = (await (await snapshot.getProperty('html')).jsonValue());
|
|
407
405
|
// Full cheerio (parse5) import for browser compliant parser
|
|
408
406
|
const { load } = await import('cheerio');
|
|
409
407
|
const $ = load(pageContent);
|
|
410
408
|
if (page.frames().length > 1 && !ignoreIframes) {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
if (frames.length !== cheerioIframes.length) {
|
|
414
|
-
serviceLocator
|
|
415
|
-
.getLogger()
|
|
416
|
-
.warning(`parseWithCheerio: iframe count mismatch between live DOM (${frames.length}) and page snapshot (${cheerioIframes.length}). Some iframes may not be expanded.`);
|
|
417
|
-
}
|
|
418
|
-
await Promise.all(frames.map(async (frame, index) => {
|
|
409
|
+
const iframes = await (await snapshot.getProperty('iframes')).getProperties();
|
|
410
|
+
await Promise.all([...iframes].map(async ([id, handle]) => {
|
|
419
411
|
try {
|
|
420
|
-
const iframe = await
|
|
421
|
-
if (iframe
|
|
412
|
+
const iframe = await handle.asElement()?.contentFrame();
|
|
413
|
+
if (iframe) {
|
|
422
414
|
const getIframeHTML = async () => {
|
|
423
415
|
try {
|
|
424
|
-
return iframe.locator('body').first().innerHTML();
|
|
416
|
+
return await iframe.locator('body').first().innerHTML();
|
|
425
417
|
}
|
|
426
418
|
catch {
|
|
427
419
|
return iframe.content();
|
|
428
420
|
}
|
|
429
421
|
};
|
|
430
422
|
const contents = await getIframeHTML();
|
|
431
|
-
$(
|
|
423
|
+
$(`iframe[data-crawlee-iframe-id="${id}"]`).replaceWith(`<div class="crawlee-iframe-replacement">${contents}</div>`);
|
|
432
424
|
}
|
|
433
425
|
}
|
|
434
426
|
catch (error) {
|
|
@@ -436,6 +428,8 @@ export async function parseWithCheerio(page, ignoreShadowRoots = false, ignoreIf
|
|
|
436
428
|
}
|
|
437
429
|
}));
|
|
438
430
|
}
|
|
431
|
+
await snapshot.dispose();
|
|
432
|
+
$('[data-crawlee-iframe-id]').removeAttr('data-crawlee-iframe-id');
|
|
439
433
|
return $;
|
|
440
434
|
}
|
|
441
435
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/playwright",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.308",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.13.0"
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/datastructures": "^3.0.1",
|
|
51
51
|
"@apify/timeout": "^1.0.1",
|
|
52
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
53
|
-
"@crawlee/browser": "4.0.0-beta.
|
|
54
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
55
|
-
"@crawlee/cheerio": "4.0.0-beta.
|
|
56
|
-
"@crawlee/core": "4.0.0-beta.
|
|
57
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
58
|
-
"@crawlee/types": "4.0.0-beta.
|
|
59
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.308",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.308",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.308",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.308",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.308",
|
|
57
|
+
"@crawlee/http-client": "4.0.0-beta.308",
|
|
58
|
+
"@crawlee/types": "4.0.0-beta.308",
|
|
59
|
+
"@crawlee/utils": "4.0.0-beta.308",
|
|
60
60
|
"cheerio": "^1.2.0",
|
|
61
61
|
"domhandler": "^6.0.1",
|
|
62
62
|
"jquery": "^3.8.0",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "a2b078ad2b609112651ca93672b4c6b3aee80127"
|
|
85
85
|
}
|