forked from tvanro/prerender-alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockResource.js
66 lines (59 loc) · 1.65 KB
/
blockResource.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const blockedResources = [
"google-analytics.com",
"cloudflareinsights.com",
"googletagmanager.com",
"api.mixpanel.com",
"fonts.googleapis.com",
"stats.g.doubleclick.net",
"mc.yandex.ru",
"use.typekit.net",
"beacon.tapfiliate.com",
"js-agent.newrelic.com",
"api.segment.io",
"woopra.com",
"static.olark.com",
"static.getclicky.com",
"fast.fonts.com",
"youtube.com/embed",
"cdn.heapanalytics.com",
"googleads.g.doubleclick.net",
"pagead2.googlesyndication.com",
"fullstory.com/rec",
"navilytics.com/nls_ajax.php",
"log.optimizely.com/event",
"hn.inspectlet.com",
"tpc.googlesyndication.com",
"partner.googleadservices.com",
".ttf",
".eot",
".otf",
".woff",
".gif",
".tiff",
".pdf",
".ico",
".svg"
];
module.exports = {
tabCreated: (req, res, next) => {
req.prerender.tab.Network.setRequestInterception({
patterns: [{urlPattern: '*'}]
}).then(() => {
next();
});
req.prerender.tab.Network.requestIntercepted(({interceptionId, request}) => {
let shouldBlock = false;
blockedResources.forEach((substring) => {
if (request.url.indexOf(substring) >= 0) {
console.log(`Blocking ${request.url}`);
shouldBlock = true;
}
});
let interceptOptions = {interceptionId};
if (shouldBlock) {
interceptOptions.errorReason = 'Aborted';
}
req.prerender.tab.Network.continueInterceptedRequest(interceptOptions);
});
}
};