This repository was archived by the owner on Feb 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblockResources.js
More file actions
75 lines (70 loc) · 1.67 KB
/
blockResources.js
File metadata and controls
75 lines (70 loc) · 1.67 KB
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
67
68
69
70
71
72
73
74
75
const blockedResources = [
"google-analytics.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",
".png",
".gif",
".tiff",
".pdf",
".jpg",
".jpeg",
".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;
if (req.prerender.url !== request.url) {
blockedResources.forEach((substring) => {
if (request.url.indexOf(substring) >= 0) {
shouldBlock = true;
}
});
}
let interceptOptions = { interceptionId };
if (shouldBlock) {
interceptOptions.errorReason = "Aborted";
}
req.prerender.tab.Network.continueInterceptedRequest(
interceptOptions,
).catch((error) => {
console.log(
"[blockResources] Error continuing intercepted request",
error,
);
});
},
);
},
};