@crawlee/playwright 4.0.0-beta.311 → 4.0.0-beta.313

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.
@@ -1,4 +1,5 @@
1
- import { BrowserCrawler, RequestState, Router, serviceLocator } from '@crawlee/browser';
1
+ import { setTimeout as delay } from 'node:timers/promises';
2
+ import { BrowserCrawler, DownloadStartedError, RequestState, Router, serviceLocator } from '@crawlee/browser';
2
3
  import { assertBrowserPoolNotConfigured, parseArgument, schemas } from '@crawlee/utils/internal';
3
4
  import { z } from 'zod';
4
5
  import { playwrightBrowserPool } from './playwright-browser-pool.js';
@@ -107,7 +108,25 @@ export class PlaywrightCrawler extends BrowserCrawler {
107
108
  return this.buildContextPipeline().compose(this.#enhanceContext.bind(this));
108
109
  }
109
110
  async navigationHandler(crawlingContext, gotoOptions) {
110
- return gotoExtended(crawlingContext.page, crawlingContext.request, gotoOptions);
111
+ const { page } = crawlingContext;
112
+ const { promise: downloadStarted, resolve } = Promise.withResolvers();
113
+ const onDownload = () => resolve();
114
+ page.once('download', onDownload);
115
+ try {
116
+ return await gotoExtended(page, crawlingContext.request, gotoOptions);
117
+ }
118
+ catch (error) {
119
+ // `goto` can reject before the `download` event arrives, and `listDownloads()` would miss it.
120
+ // ponytail: fixed 5 s bound, tie it to the navigation window if downloads start slower than that
121
+ if (error.message?.includes('Download is starting')) {
122
+ await Promise.race([downloadStarted, delay(5_000, undefined, { ref: false })]);
123
+ throw new DownloadStartedError(error.message, { cause: error });
124
+ }
125
+ throw error;
126
+ }
127
+ finally {
128
+ page.off('download', onDownload);
129
+ }
111
130
  }
112
131
  async #enhanceContext(context) {
113
132
  const waitForSelector = async (selector, timeoutMs = 5_000) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/playwright",
3
- "version": "4.0.0-beta.311",
3
+ "version": "4.0.0-beta.313",
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"
@@ -48,15 +48,15 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@apify/datastructures": "^3.0.1",
51
- "@apify/timeout": "^1.0.2",
52
- "@crawlee/basic": "4.0.0-beta.311",
53
- "@crawlee/browser": "4.0.0-beta.311",
54
- "@crawlee/browser-pool": "4.0.0-beta.311",
55
- "@crawlee/cheerio": "4.0.0-beta.311",
56
- "@crawlee/core": "4.0.0-beta.311",
57
- "@crawlee/http-client": "4.0.0-beta.311",
58
- "@crawlee/types": "4.0.0-beta.311",
59
- "@crawlee/utils": "4.0.0-beta.311",
51
+ "@apify/timeout": "^1.1.0",
52
+ "@crawlee/basic": "4.0.0-beta.313",
53
+ "@crawlee/browser": "4.0.0-beta.313",
54
+ "@crawlee/browser-pool": "4.0.0-beta.313",
55
+ "@crawlee/cheerio": "4.0.0-beta.313",
56
+ "@crawlee/core": "4.0.0-beta.313",
57
+ "@crawlee/http-client": "4.0.0-beta.313",
58
+ "@crawlee/types": "4.0.0-beta.313",
59
+ "@crawlee/utils": "4.0.0-beta.313",
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": "001b41ad1451519c9b14711c347db8989eef7e4a"
84
+ "gitHead": "9f6a677a05a3fa9ff77c73ffd7c7722b798fcff7"
85
85
  }