Skip to content

Commit 0eb7475

Browse files
committed
Stop blob load
1 parent f28874d commit 0eb7475

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

server.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ const BLOCKED_PATTERNS = [
4242
/wss:\/\//,
4343
/\/socket\.io\//,
4444
/\/sockjs-node\//,
45-
/\/hub\?/, // SignalR
45+
/\/hub\?/,
4646
/eventsource/i,
4747
/livereload/,
4848
];
4949

50+
// Patterns for requests that should be ignored in requestsInFlight count
51+
// (they bypass Fetch interception and hang forever)
52+
const IGNORE_INFLIGHT_PATTERNS = [
53+
/^blob:/,
54+
/^data:/,
55+
];
56+
5057
server.use({
5158
tabCreated: (req, res, next) => {
5259
const tab = req.prerender.tab;
@@ -57,7 +64,7 @@ server.use({
5764

5865
const pendingRequests = new Map();
5966

60-
// Use Fetch domain for request interception (replaces deprecated Network.setRequestInterception)
67+
// Use Fetch domain to block unwanted network requests
6168
tab.Fetch.enable({ patterns: [{ requestStage: 'Request' }] });
6269
tab.Fetch.requestPaused((params) => {
6370
const url = params.request.url;
@@ -74,10 +81,18 @@ server.use({
7481
});
7582

7683
tab.Network.requestWillBeSent((params) => {
77-
pendingRequests.set(params.requestId, {
78-
url: params.request.url,
79-
time: Date.now()
80-
});
84+
const url = params.request.url;
85+
86+
// blob: URLs bypass Fetch interception and hang forever.
87+
// Prerender already incremented numRequestsInFlight before our handler,
88+
// so we decrement it back and skip tracking.
89+
if (IGNORE_INFLIGHT_PATTERNS.some(p => p.test(url))) {
90+
tab.prerender.numRequestsInFlight--;
91+
console.log('⏭️ Ignored from inflight:', url);
92+
return;
93+
}
94+
95+
pendingRequests.set(params.requestId, { url, time: Date.now() });
8196
});
8297

8398
tab.Network.loadingFinished((params) => {
@@ -101,18 +116,19 @@ server.use({
101116
console.log('💥 JS Exception:', exception.exceptionDetails.text);
102117
});
103118

104-
// Log pending requests every 3s to identify what's hanging
105119
const interval = setInterval(() => {
106120
if (pendingRequests.size > 0) {
107121
const now = Date.now();
108-
console.log(`⏳ Pending requests (${pendingRequests.size}):`);
122+
console.log(`⏳ Pending requests (${pendingRequests.size}), inflight=${tab.prerender.numRequestsInFlight}:`);
109123
pendingRequests.forEach(({ url, time }) => {
110124
console.log(` - ${((now - time) / 1000).toFixed(1)}s ${url}`);
111125
});
112126
}
113127
}, 3000);
114128

115-
req.prerender.on('tabNavigated', () => clearInterval(interval));
129+
const cleanup = () => clearInterval(interval);
130+
req.prerender.on('tabNavigated', cleanup);
131+
req.prerender.on('beforeSend', cleanup);
116132
}
117133

118134
next();

0 commit comments

Comments
 (0)