diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ace6bec..fd82224b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Support `waitFor` for [crawler.queue()](https://github.com/yujiosaka/headless-chrome-crawler#crawlerqueueoptions)'s options. +- Support `slowMo` for [HCCrawler.connect()](#hccrawlerconnectoptions)'s options. ### Fixed diff --git a/README.md b/README.md index c9384c0b..7320ae28 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ HCCrawler.launch({ This method connects to an existing Chromium instance. The following options are passed to [puppeteer.connect()](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions). ``` -browserWSEndpoint, ignoreHTTPSErrors +browserWSEndpoint, ignoreHTTPSErrors, slowMo ``` Also, the following options can be set as default values when [crawler.queue()](#crawlerqueueoptions) are executed. diff --git a/lib/hccrawler.js b/lib/hccrawler.js index 2731ccf2..4e26c2a6 100644 --- a/lib/hccrawler.js +++ b/lib/hccrawler.js @@ -28,6 +28,7 @@ const SessionCache = require('../cache/session'); const CONNECT_OPTIONS = [ 'browserWSEndpoint', 'ignoreHTTPSErrors', + 'slowMo', ]; const LAUNCH_OPTIONS = [ 'ignoreHTTPSErrors', diff --git a/test/hccrawler.test.js b/test/hccrawler.test.js index 9157df4f..16d8e3c0 100644 --- a/test/hccrawler.test.js +++ b/test/hccrawler.test.js @@ -34,6 +34,33 @@ describe('HCCrawler', () => { }); }); + describe('HCCrawler.connect', () => { + let crawler; + + beforeEach(() => ( + HCCrawler.launch(DEFAULT_OPTIONS) + .then(_crawler => { + crawler = _crawler; + }) + )); + + afterEach(() => crawler.close()); + + it('connects multiple times to the same crawler', () => ( + HCCrawler.connect({ browserWSEndpoint: crawler.wsEndpoint() }) + .then(secondCrawler => secondCrawler.close()) + )); + + it('reconnects to an already disconnected crawler', () => { + const browserWSEndpoint = crawler.wsEndpoint(); + return crawler.disconnect() + .then(() => HCCrawler.connect({ browserWSEndpoint })) + .then(_crawler => { + crawler = _crawler; + }); + }); + }); + describe('HCCrawler.launch', () => { let crawler; let onSuccess; @@ -46,6 +73,13 @@ describe('HCCrawler', () => { afterEach(() => crawler.close()); + it('launches a crawler', () => ( + HCCrawler.launch(DEFAULT_OPTIONS) + .then(_crawler => { + crawler = _crawler; + }) + )); + context('when the server is running', () => { let server;