diff --git a/README.md b/README.md index aa01804..a4b9d19 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ await scrape({ launchOptions: { headless: "new" }, /* optional */ gotoOptions: { waitUntil: "networkidle0" }, /* optional */ scrollToBottom: { timeout: 10000, viewportN: 10 }, /* optional */ - blockNavigation: true, /* optional */ }) ] }); @@ -41,7 +40,6 @@ Puppeteer plugin constructor accepts next params: * `scrollToBottom` - *(optional)* - in some cases, the page needs to be scrolled down to render its assets (lazyloading). Because some pages can be really endless, the scrolldown process can be interrupted before reaching the bottom when one or both of the bellow limitations are reached: * `timeout` - in milliseconds * `viewportN` - viewport height multiplier -* `blockNavigation` - *(optional)* - defines whether navigation away from the page is permitted or not. If it is set to true, then the page is locked to the current url and redirects with `location.replace(anotherPage)` will not pass. Defaults to `false` ## How it works It starts Chromium in headless mode which just opens page and waits until page is loaded. diff --git a/lib/index.js b/lib/index.js index 0c2573b..af7718d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,16 +7,14 @@ class PuppeteerPlugin { launchOptions = {}, gotoOptions = {}, scrollToBottom = null, - blockNavigation = false } = {}) { this.launchOptions = launchOptions; this.gotoOptions = gotoOptions; this.scrollToBottom = scrollToBottom; - this.blockNavigation = blockNavigation; this.browser = null; this.headers = {}; - logger.info('init plugin', { launchOptions, scrollToBottom, blockNavigation }); + logger.info('init plugin', { launchOptions, scrollToBottom }); } apply (registerAction) { @@ -43,10 +41,6 @@ class PuppeteerPlugin { await page.setExtraHTTPHeaders(this.headers); } - if (this.blockNavigation) { - await blockNavigation(page, url); - } - await page.goto(url, this.gotoOptions); if (this.scrollToBottom) { @@ -78,17 +72,4 @@ async function scrollToBottom (page, timeout, viewportN) { await page.evaluate(scrollToBottomBrowser, timeout, viewportN); } -async function blockNavigation (page, url) { - logger.info(`block navigation for puppeteer page from url ${url}`); - - page.on('request', req => { - if (req.isNavigationRequest() && req.frame() === page.mainFrame() && req.url() !== url) { - req.abort('aborted'); - } else { - req.continue(); - } - }); - await page.setRequestInterception(true); -} - export default PuppeteerPlugin; diff --git a/test/puppeteer-plugin.test.js b/test/puppeteer-plugin.test.js index 9cdde9e..4f8ba12 100644 --- a/test/puppeteer-plugin.test.js +++ b/test/puppeteer-plugin.test.js @@ -42,31 +42,6 @@ describe('Puppeteer plugin test', () => { expect(content).to.contain('