Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
Update changelog, bump version, build docs
Ondra Urban1693b77329be
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a00866e78..d00e73d8b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,10 +1,17 @@-xxx-===================-- Use pipes instead of web sockets in Puppeteer.+0.14.11 / 2019-05-28+====================+- Add `Statistics` class to track crawler run statistics.+- Use pipes instead of web sockets in Puppeteer to improve performance and stability.+- Add warnings to all functions using Puppeteer's request interception to inform users about+ its performance impact caused by automatic cache disabling.+- **DEPRECATED**: `Apify.utils.puppeteer.blockResources()` because of negative impact on performance.+ Use `.blockRequests()` (see below).+- Add `Apify.utils.puppeteer.blockRequests()` to enable blocking URL patterns without request interception involved.+ This is a replacement for `.blockResources()` until performance issues with request interception resolve.0.14.10 / 2019-05-24-===================+====================- Update `Puppeteer` to 1.17.0.- Add `idempotencyKey` parameter to `Apify.addWebhook()`.diff --git a/docs/api/Dataset.md b/docs/api/Dataset.mdindex 8bd3b6127..187cfa4ac 100644--- a/docs/api/Dataset.md+++ b/docs/api/Dataset.md@@ -188,6 +188,16 @@ Returns items in the dataset based on the provided parameters.</tr><tr><td colspan="3"><p>If set to <code>true</code> then header row in CSV format is skipped.</p>+</td></tr><tr>+<td><code>[options.simplified]</code></td><td><code>Boolean</code></td><td></td>+</tr>+<tr>+<td colspan="3"><p>If set to <code>true</code> then function applies the <code>fields: ['url','pageFunctionResult','errorInfo']</code> and <code>unwind: 'pageFunctionResult'</code> options.</p>+</td></tr><tr>+<td><code>[options.skipFailedPages]</code></td><td><code>Boolean</code></td><td></td>+</tr>+<tr>+<td colspan="3"><p>If set to <code>true</code> then all the items with errorInfo property will be skipped from the output.</p></td></tr></tbody></table><a name="Dataset+getInfo"></a>diff --git a/docs/api/puppeteer.md b/docs/api/puppeteer.mdindex a7989bc77..691cf25ed 100644--- a/docs/api/puppeteer.md+++ b/docs/api/puppeteer.md@@ -30,8 +30,8 @@ await puppeteer.injectJQuery(page);* [`.injectFile(page, filePath, [options])`](#puppeteer.injectFile) ⇒ `Promise`* [`.injectJQuery(page)`](#puppeteer.injectJQuery) ⇒ `Promise`* [`.injectUnderscore(page)`](#puppeteer.injectUnderscore) ⇒ `Promise`- * [`.blockResources(page, [resourceTypes])`](#puppeteer.blockResources) ⇒ `Promise`- * [`.cacheResponses(page, cache, responseUrlRules)`](#puppeteer.cacheResponses) ⇒ `Promise`+ * [`.blockRequests(page, [options])`](#puppeteer.blockRequests) ⇒ `Promise`+ * ~~[`.cacheResponses(page, cache, responseUrlRules)`](#puppeteer.cacheResponses) ⇒ `Promise`~~* [`.compileScript(scriptString, context)`](#puppeteer.compileScript) ⇒ `function`<a name="puppeteer.addInterceptRequestHandler"></a>@@ -128,6 +128,10 @@ Removes request interception handler for given page.<a name="puppeteer.gotoExtended"></a>## `puppeteer.gotoExtended` ⇒ `Promise<Response>`+*NOTE:* In recent versions of Puppeteer using this function entirely disables browser cache which resolves in sub-optimal+performance. Until this resolves, we suggest using this function only when needed and not to replace all `page.goto()`+calls in your actors with it.+Extended version of Puppeteer's `page.goto()` allowing to perform requests with HTTP method other than GET,with custom headers and POST payload. URL, method, headers and payload are taken fromrequest parameter that must be an instance of Apify.Request class.@@ -266,27 +270,30 @@ const escapedHtml = await page.evaluate(() => {<td colspan="3"><p>Puppeteer <a href="https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page">Page</a> object.</p></td></tr></tbody></table>-<a name="puppeteer.blockResources"></a>+<a name="puppeteer.blockRequests"></a>-## `puppeteer.blockResources(page, [resourceTypes])` ⇒ `Promise`-Forces the Puppeteer browser tab to block loading certain HTTP resources.+## `puppeteer.blockRequests(page, [options])` ⇒ `Promise`+Forces the Puppeteer browser tab to block loading URLs that match a provided pattern.This is useful to speed up crawling of websites, since it reduces the amount-of data that need to be downloaded from the web.+of data that needs to be downloaded from the web, but it may break some websites+or unexpectedly prevent loading of resources.++If the `options.urlPatterns` parameter is not provided,+by default the function blocks URLs that include these patterns:-The resource types to block can be specified using the `resourceTypes` parameter,-which indicates the types of resources as they are perceived by the rendering engine.-The following resource types are currently supported:-`document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`,-`eventsource`, `websocket`, `manifest`, `other`.-For more details, see Puppeteer's-<a href="https://pptr.dev/#?product=Puppeteer&show=api-requestresourcetype" target="_blank">Request.resourceType() documentation</a>.+```json+[".css", ".jpg", ".jpeg", ".png", ".svg", ".woff", ".pdf", ".zip"]+```-If the `resourceTypes` parameter is not provided,-by default the function blocks these resource types: `stylesheet`, `font`, `image`, `media`.+The defaults will be concatenated with the patterns you provide in `options.urlPatterns`.+If you want to remove the defaults, use `options.includeDefaults: false`.-Note that the `blockResources` function internally uses Puppeteer's-[`Page.setRequestInterception()`](https://pptr.dev/#?product=Puppeteer&show=api-pagesetrequestinterceptionvalue) function,-which can only be used once per `Page` object.+This function does not use Puppeteer's request interception and therefore does not interfere+with browser cache. It's also faster than blocking requests using interception,+because the blocking happens directly in the browser without the round-trip to Node.js,+but it does not provide the extra benefits of request interception.++The function will never block main document loads and their respective redirects.**Example usage**```javascript@@ -295,37 +302,52 @@ const Apify = require('apify');const browser = await Apify.launchPuppeteer();const page = await browser.newPage();-// Block all resources except for the main HTML document-await Apify.utils.puppeteer.blockResources(page,- ['stylesheet', 'image', 'media', 'font', 'script', 'texttrack', 'xhr',- 'fetch', 'eventsource', 'websocket', 'manifest', 'other']-);+// Block all requests to URLs that include `adsbygoogle.js` and also all defaults.+await Apify.utils.puppeteer.blockRequests(page, {+ urlPatterns: ['adsbygoogle.js'],+});-await page.goto('https://www.example.com');+await page.goto('https://cnn.com');```<table><thead><tr>-<th>Param</th><th>Type</th><th>Default</th>+<th>Param</th><th>Type</th></tr></thead><tbody><tr>-<td><code>page</code></td><td><code>Page</code></td><td></td>+<td><code>page</code></td><td><code>Page</code></td></tr><tr><td colspan="3"><p>Puppeteer <a href="https://pptr.dev/#?product=Puppeteer&show=api-class-page" target="_blank"><code>Page</code></a> object.</p></td></tr><tr>-<td><code>[resourceTypes]</code></td><td><code>Array<String></code></td><td><code>['stylesheet', 'font', 'image', 'media']</code></td>+<td><code>[options]</code></td><td><code>Object</code></td>+</tr>+<tr>+<td colspan="3"></td></tr><tr>+<td><code>[options.urlPatterns]</code></td><td><code>Array<string></code></td>+</tr>+<tr>+<td colspan="3"><p>The patterns of URLs to block from being loaded by the browser.+ Only <code>*</code> can be used as a wildcard. It is also automatically added to the beginning+ and end of the pattern. This limitation is enforced by the DevTools protocol.+ <code>.png</code> is the same as <code>*.png*</code>.</p>+</td></tr><tr>+<td><code>[options.includeDefaults]</code></td><td><code>boolean</code></td></tr><tr>-<td colspan="3"><p>Array of resource types to block.</p>-</td></tr></tbody>+<td colspan="3"></td></tr></tbody></table><a name="puppeteer.cacheResponses"></a>-## `puppeteer.cacheResponses(page, cache, responseUrlRules)` ⇒ `Promise`+## ~~`puppeteer.cacheResponses(page, cache, responseUrlRules)` ⇒ `Promise`~~+***Deprecated***++*NOTE:* In recent versions of Puppeteer using this function entirely disables browser cache which resolves in sub-optimal+performance. Until this resolves, we suggest just relying on the in-browser cache unless absolutely necessary.+Enables caching of intercepted responses into a provided object. Automatically enables request interception in Puppeteer.*IMPORTANT*: Caching responses stores them to memory, so too loose rules could cause memory leaks for longer running crawlers.This issue should be resolved or atleast mitigated in future iterations of this feature.diff --git a/package.json b/package.jsonindex d299f6fdf..82c46a66e 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "apify",- "version": "0.14.10",+ "version": "0.14.11","description": "The scalable web crawling and scraping library for JavaScript. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.","engines": {"node": ">=8.14.0"