@crawlee/playwright 3.18.3-beta.1 → 3.18.3-beta.10

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.
@@ -210,6 +210,8 @@ export declare class PlaywrightCrawler extends BrowserCrawler<{
210
210
  requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
211
211
  // @ts-ignore optional peer dependency or compatibility with es2022
212
212
  requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
213
+ // @ts-ignore optional peer dependency or compatibility with es2022
214
+ requestManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
213
215
  // @ts-ignore optional peer dependency or compatibility with es2022
214
216
  requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
215
217
  // @ts-ignore optional peer dependency or compatibility with es2022
@@ -412,31 +412,25 @@ async function saveSnapshot(page, options = {}) {
412
412
  */
413
413
  async function parseWithCheerio(page, ignoreShadowRoots = false, ignoreIframes = false) {
414
414
  (0, ow_1.default)(page, ow_1.default.object.validate(browser_1.validators.browserPage));
415
- const html = ignoreShadowRoots
416
- ? null
417
- : (await page.evaluate(`(${utils_1.expandShadowRoots.toString()})(document)`));
418
- const pageContent = html || (await page.content());
415
+ const snapshot = await page.evaluateHandle(`(${utils_1.snapshotPageWithIframes.toString()})(document, ${ignoreShadowRoots ? 'null' : utils_1.expandShadowRoots.toString()})`);
416
+ const pageContent = (await (await snapshot.getProperty('html')).jsonValue());
419
417
  const $ = cheerio.load(pageContent);
420
418
  if (page.frames().length > 1 && !ignoreIframes) {
421
- const frames = await page.$$('iframe');
422
- const cheerioIframes = $('iframe').toArray();
423
- if (frames.length !== cheerioIframes.length) {
424
- log.warning(`parseWithCheerio: iframe count mismatch between live DOM (${frames.length}) and page snapshot (${cheerioIframes.length}). Some iframes may not be expanded.`);
425
- }
426
- await Promise.all(frames.map(async (frame, index) => {
419
+ const iframes = await (await snapshot.getProperty('iframes')).getProperties();
420
+ await Promise.all([...iframes].map(async ([id, handle]) => {
427
421
  try {
428
- const iframe = await frame.contentFrame();
429
- if (iframe && cheerioIframes[index]) {
422
+ const iframe = await handle.asElement()?.contentFrame();
423
+ if (iframe) {
430
424
  const getIframeHTML = async () => {
431
425
  try {
432
- return iframe.locator('body').first().innerHTML();
426
+ return await iframe.locator('body').first().innerHTML();
433
427
  }
434
428
  catch {
435
429
  return iframe.content();
436
430
  }
437
431
  };
438
432
  const contents = await getIframeHTML();
439
- $(cheerioIframes[index]).replaceWith(`<div class="crawlee-iframe-replacement">${contents}</div>`);
433
+ $(`iframe[data-crawlee-iframe-id="${id}"]`).replaceWith(`<div class="crawlee-iframe-replacement">${contents}</div>`);
440
434
  }
441
435
  }
442
436
  catch (error) {
@@ -444,6 +438,8 @@ async function parseWithCheerio(page, ignoreShadowRoots = false, ignoreIframes =
444
438
  }
445
439
  }));
446
440
  }
441
+ await snapshot.dispose();
442
+ $('[data-crawlee-iframe-id]').removeAttr('data-crawlee-iframe-id');
447
443
  return $;
448
444
  }
449
445
  let idcacPlaywright = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/playwright",
3
- "version": "3.18.3-beta.1",
3
+ "version": "3.18.3-beta.10",
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": ">=16.0.0"
@@ -56,11 +56,11 @@
56
56
  "@apify/datastructures": "^2.0.0",
57
57
  "@apify/log": "^2.4.0",
58
58
  "@apify/timeout": "^0.4.0",
59
- "@crawlee/browser": "3.18.3-beta.1",
60
- "@crawlee/browser-pool": "3.18.3-beta.1",
61
- "@crawlee/core": "3.18.3-beta.1",
62
- "@crawlee/types": "3.18.3-beta.1",
63
- "@crawlee/utils": "3.18.3-beta.1",
59
+ "@crawlee/browser": "3.18.3-beta.10",
60
+ "@crawlee/browser-pool": "3.18.3-beta.10",
61
+ "@crawlee/core": "3.18.3-beta.10",
62
+ "@crawlee/types": "3.18.3-beta.10",
63
+ "@crawlee/utils": "3.18.3-beta.10",
64
64
  "cheerio": "1.0.0-rc.12",
65
65
  "jquery": "^3.6.0",
66
66
  "lodash.isequal": "^4.5.0",
@@ -90,5 +90,5 @@
90
90
  }
91
91
  }
92
92
  },
93
- "gitHead": "ed43777009616cd7325e3e5fb3b7b39348e4a717"
93
+ "gitHead": "91711895453a45ee6733a535f70016ff681b0de7"
94
94
  }