Skip to content

Commit cf36e28

Browse files
committed
Add abortTrackers support
1 parent a00b3ee commit cf36e28

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ default: `['image', 'media', 'stylesheet', 'font', 'xhr']`
123123

124124
A list of `resourceType` requests that can be aborted in order to make the process faster.
125125

126+
##### abortTrackers
127+
128+
type: `boolean`</br>
129+
default: `true`
130+
131+
It will be abort request coming for [tracking domains](https://npm.im/is-tracking-domain).
132+
126133
### .text(url, options)
127134

128135
It returns the full text content from the target `url`.
@@ -284,6 +291,20 @@ default: `[]`
284291

285292
A list of `req.resourceType()` to be blocked.
286293

294+
##### abortTrackers
295+
296+
type: `boolean`</br>
297+
default: `true`
298+
299+
It will be abort request coming for [tracking domains](https://npm.im/is-tracking-domain).
300+
301+
##### abortTrackers
302+
303+
type: `boolean`</br>
304+
default: `true`
305+
306+
It will be abort request coming for [tracking domains](https://npm.im/is-tracking-domain).
307+
287308
##### waitFor
288309

289310
type:`string|function|number`</br>

src/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ module.exports = launchOpts => {
2626

2727
const goto = async (
2828
page,
29-
{ url, abortTypes, waitFor, waitUntil, userAgent, viewport, args }
29+
{
30+
url,
31+
abortTrackers,
32+
abortTypes,
33+
waitFor,
34+
waitUntil,
35+
userAgent,
36+
viewport,
37+
args
38+
}
3039
) => {
3140
await page.setRequestInterception(true)
3241
let reqCount = { abort: 0, continue: 0 }
@@ -45,7 +54,7 @@ module.exports = launchOpts => {
4554
const resourceDomain = extractDomain(resourceUrl)
4655
const isExternal = isExternalUrl(urlDomain, resourceDomain)
4756

48-
if (isExternal && isTracker(resourceDomain)) {
57+
if (abortTrackers && isExternal && isTracker(resourceDomain)) {
4958
debug(`abort:tracker:${++reqCount.abort}`, resourceUrl)
5059
return req.abort()
5160
}
@@ -63,6 +72,7 @@ module.exports = launchOpts => {
6372

6473
const createGetContent = evaluate => async (url, opts = {}) => {
6574
const {
75+
abortTrackers = true,
6676
abortTypes = ['image', 'media', 'stylesheet', 'font', 'xhr'],
6777
waitFor = 0,
6878
waitUntil = WAIT_UNTIL,
@@ -74,6 +84,7 @@ module.exports = launchOpts => {
7484
const page = await newPage()
7585
await goto(page, {
7686
url,
87+
abortTrackers,
7788
abortTypes,
7889
waitFor,
7990
waitUntil,
@@ -127,6 +138,7 @@ module.exports = launchOpts => {
127138

128139
const pdf = async (url, opts = {}) => {
129140
const {
141+
abortTrackers = false,
130142
abortTypes = [],
131143
device: deviceName = 'macbook pro 13',
132144
format = 'A4',
@@ -162,6 +174,7 @@ module.exports = launchOpts => {
162174
userAgent: isEmpty(userAgent) ? deviceUserAgent : userAgent,
163175
viewport: Object.assign({}, deviceViewport, viewport),
164176
url,
177+
abortTrackers,
165178
abortTypes,
166179
waitFor,
167180
waitUntil,

0 commit comments

Comments
 (0)