Skip to content

Commit 7956e88

Browse files
authored
Drop support of "blockNavigation" option (#150)
1 parent 147abab commit 7956e88

File tree

3 files changed

+1
-47
lines changed

3 files changed

+1
-47
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ await scrape({
3030
launchOptions: { headless: "new" }, /* optional */
3131
gotoOptions: { waitUntil: "networkidle0" }, /* optional */
3232
scrollToBottom: { timeout: 10000, viewportN: 10 }, /* optional */
33-
blockNavigation: true, /* optional */
3433
})
3534
]
3635
});
@@ -41,7 +40,6 @@ Puppeteer plugin constructor accepts next params:
4140
* `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:
4241
* `timeout` - in milliseconds
4342
* `viewportN` - viewport height multiplier
44-
* `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`
4543

4644
## How it works
4745
It starts Chromium in headless mode which just opens page and waits until page is loaded.

lib/index.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ class PuppeteerPlugin {
77
launchOptions = {},
88
gotoOptions = {},
99
scrollToBottom = null,
10-
blockNavigation = false
1110
} = {}) {
1211
this.launchOptions = launchOptions;
1312
this.gotoOptions = gotoOptions;
1413
this.scrollToBottom = scrollToBottom;
15-
this.blockNavigation = blockNavigation;
1614
this.browser = null;
1715
this.headers = {};
1816

19-
logger.info('init plugin', { launchOptions, scrollToBottom, blockNavigation });
17+
logger.info('init plugin', { launchOptions, scrollToBottom });
2018
}
2119

2220
apply (registerAction) {
@@ -43,10 +41,6 @@ class PuppeteerPlugin {
4341
await page.setExtraHTTPHeaders(this.headers);
4442
}
4543

46-
if (this.blockNavigation) {
47-
await blockNavigation(page, url);
48-
}
49-
5044
await page.goto(url, this.gotoOptions);
5145

5246
if (this.scrollToBottom) {
@@ -78,17 +72,4 @@ async function scrollToBottom (page, timeout, viewportN) {
7872
await page.evaluate(scrollToBottomBrowser, timeout, viewportN);
7973
}
8074

81-
async function blockNavigation (page, url) {
82-
logger.info(`block navigation for puppeteer page from url ${url}`);
83-
84-
page.on('request', req => {
85-
if (req.isNavigationRequest() && req.frame() === page.mainFrame() && req.url() !== url) {
86-
req.abort('aborted');
87-
} else {
88-
req.continue();
89-
}
90-
});
91-
await page.setRequestInterception(true);
92-
}
93-
9475
export default PuppeteerPlugin;

test/puppeteer-plugin.test.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,6 @@ describe('Puppeteer plugin test', () => {
4242
expect(content).to.contain('<div id="special-characters-test">7년 동안 한국에서 살았어요. Слава Україні!</div>');
4343
});
4444
});
45-
46-
describe('Block navigation', () => {
47-
before('scrape website', async () => {
48-
result = await scrape({
49-
urls: [`http://localhost:${SERVE_WEBSITE_PORT}/navigation.html`],
50-
directory: directory,
51-
plugins: [
52-
new PuppeteerPlugin({
53-
launchOptions: { headless: "new" },
54-
blockNavigation: true
55-
})
56-
]
57-
});
58-
});
59-
before('get content from file', () => {
60-
content = fs.readFileSync(`${directory}/${result[0].filename}`).toString();
61-
});
62-
after('delete dir', () => fs.removeSync(directory));
63-
64-
it('should render content (and not be redirected)', async () => {
65-
expect(content).to.contain('<div id="root">Navigation blocked!</div>');
66-
});
67-
});
68-
69-
7045
});
7146

7247
function startWebserver(port = 3000) {

0 commit comments

Comments
 (0)