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
Commented out launchChrome() function as well as lighthouse and chrome-remote-interface dependencies, updated README.md
Jan Curn978926c47598
diff --git a/README.md b/README.mdindex 7d2c49c66..f0d3cacf3 100644--- a/README.md+++ b/README.md@@ -12,6 +12,9 @@ It is still a work in progress, stay tuned.npm install apifier --save```+This package requires Node.js 6 or higher.+It might work with lower versions too, but they are neither tested nor supported.+## Usage inside actsImport the package to your act.@@ -170,15 +173,62 @@ Apifier.setOutput(output).then(() => {Note that this is especially useful if output of your act should not be a JSON,because return value from `Apifier.main()` is always converted to JSON.+### Browser++Apifier runtime optionally depends on+the [selenium-webdriver](https://www.npmjs.com/package/selenium-webdriver) package that enables+automation of a web browser.+The simplest way to launch a new web browser process is to call:++```javascript+const options = { browser: 'chrome' };+const browser = await Apifier.browse('https://www.example.com/', options);+```++The first parameter is the URL of the initial page, by default it is `about:blank`.+The second parameter is an optional object that defines options for the web browser.+It has the following properties:++```javascript+{+ // Indicates whether the browser should be opened in headless mode (i.e. without window).+ // By default, this value is generated based on the APIFY_HEADLESS environment variable.+ headless: Boolean,++ // Type of the web browser, currently only 'chrome' is supported.+ browser: 'chrome',++ // URL of the proxy server, e.g. 'socks://username:[email protected]:55555'+ proxyUrl: null,+}+```++The `Apifier.browse()` function returns a promise resolving to a new instance of the `Browser` class,+which represents a web browser process. Currently it only contains the `webDriver` property,+which is an instance of Selenium's+[WebDriver](http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebDriver.html)+class:++```javascript+const ulr = await browser.webDriver.getCurrentUrl();+```++Additionally, the `Browser` class defines the `close()` method which closes the web browser process.+It returns a promise that resolves when the browser was closed:++```javascript+await browser.close();+```+### Promises-By default, the `getContext`, `getInput` and `setOutput` functions returns a promise.+By default, the `getContext`, `getInput`, `setOutput` and `browse` functions return a promise.However, they also accept a Node.js-style callback parameter.If the callback is provided, the return value of the functions is not definedand the functions only invoke the callback upon completion or error.-To set a promise dependency from an external library, use code such as:+To set a promise dependency from an external library, use a code such as:```javascriptconst Promise = require('bluebird');diff --git a/package.json b/package.jsonindex c461fa258..5925ac86d 100644--- a/package.json+++ b/package.json@@ -66,8 +66,6 @@"underscore": "^1.8.3"},"optionalDependencies": {- "chrome-remote-interface": "^0.23.0",- "lighthouse": "^2.0.0","selenium-webdriver": "^3.4.0"}}diff --git a/src/browser.js b/src/browser.jsindex d71e35005..505a6174e 100644--- a/src/browser.js+++ b/src/browser.js@@ -1,5 +1,5 @@import urlModule from 'url';-import { ChromeLauncher } from 'lighthouse/lighthouse-cli/chrome-launcher';+// import { ChromeLauncher } from 'lighthouse/lighthouse-cli/chrome-launcher';import { APIFY_ENV_VARS } from './constants';import { newPromise, nodeifyPromise } from './utils';@@ -122,38 +122,38 @@ export const browse = (url, options = null, callback = null) => {};-/**- * Launches a debugging instance of Chrome on port 9222, without Selenium.- * This code is kept here for legacy reasons, it's not used.- * @param {boolean=} headless True (default) to launch Chrome in headless mode.- * Set to false to launch Chrome normally.- * @return {Promise<ChromeLauncher>}- */-export const launchChrome = (headless = !!process.env.APIFY_HEADLESS) => {- // code inspired by https://developers.google.com/web/updates/2017/04/headless-chrome- // TODO: enable other options e.g. userAgent, windowHeight, windowWidth, proxy-- const launcher = new ChromeLauncher({- port: 9222,- autoSelectChrome: true, // False to manually select which Chrome install.- additionalFlags: [- '--window-size=412,732',- '--disable-gpu',- headless ? '--headless' : '',- ],- });-- return newPromise()- .then(() => {- return launcher.run();- })- .then(() => {- return launcher;- })- .catch((err) => {- // Kill Chrome if there's an error.- return launcher.kill().then(() => {- throw err;- }, console.error);- });-};+// /**+// * Launches a debugging instance of Chrome on port 9222, without Selenium.+// * This code is kept here for legacy reasons, it's not used.+// * @param {boolean=} headless True (default) to launch Chrome in headless mode.+// * Set to false to launch Chrome normally.+// * @return {Promise<ChromeLauncher>}+// */+// export const launchChrome = (headless = !!process.env.APIFY_HEADLESS) => {+// // code inspired by https://developers.google.com/web/updates/2017/04/headless-chrome+// // TODO: enable other options e.g. userAgent, windowHeight, windowWidth, proxy+//+// const launcher = new ChromeLauncher({+// port: 9222,+// autoSelectChrome: true, // False to manually select which Chrome install.+// additionalFlags: [+// '--window-size=412,732',+// '--disable-gpu',+// headless ? '--headless' : '',+// ],+// });+//+// return newPromise()+// .then(() => {+// return launcher.run();+// })+// .then(() => {+// return launcher;+// })+// .catch((err) => {+// // Kill Chrome if there's an error.+// return launcher.kill().then(() => {+// throw err;+// }, console.error);+// });+// };