There are two issues here: 1. [RequestInit](https://searchfox.org/mozilla-central/rev/99f02d7a9456d4cfe2abd9c2a4a1eb8f3f41e22a/dom/webidl/Request.webidl#61) does not have a subscribe attribute. The example in comment 2 doesn't work in Chrome either. What does is the following: server.js: ```js const http = require('http'); const server = http.createServer((req, res) => { if (req.url === '/json' && req.method === 'GET' && req.headers['subscribe'] === 'true') { res.writeHead(209, 'unknown', { 'Range-Request-Allow-Methods': 'PATCH, PUT', 'Range-Request-Allow-Units': 'json', 'Patches': 'OK', 'subscribe': 'true', 'cache-control': 'no-cache, no-transform', 'Date': new Date().toUTCString(), 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=5', 'Transfer-Encoding': 'chunked' }); // Send the initial chunks res.write('11\r\n'); res.write('version: "test"\r\n'); res.write('14\r\n'); res.write('content-length: 16\r\n'); res.write('14\r\n'); res.write('{"this":"stuff"}\r\n'); res.write('2\r\n'); res.write('\r\n'); // Keep connection alive by periodically sending empty chunks const interval = setInterval(() => { if (res.writableEnded) { clearInterval(interval); return; } // Optional: send keep-alive whitespace or heartbeat chunk res.write('1\r\n \r\n'); }, 5000); // every 5 seconds // Clean up on client disconnect req.on('close', () => { clearInterval(interval); }); } else { res.writeHead(404); res.end('Not found'); } }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); }); ``` Execute the following in devtools ```js fetch('/json', { headers: { subscribe: 'true' } }) .then(response => { const reader = response.body.getReader(); const decoder = new TextDecoder(); function readChunk() { return reader.read().then(({ done, value }) => { if (done) { console.log('Stream complete'); return; } console.log('Received chunk:', decoder.decode(value, { stream: true })); return readChunk(); }); } return readChunk(); }); ``` This works on Chrome. Just hangs on Firefox, because the streamed response never actually completes.
Bug 1759996 Comment 5 Edit History
Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.
The example in comment 2 doesn't work in Chrome either. What does is the following: server.js: ```js const http = require('http'); const server = http.createServer((req, res) => { if (req.url === '/json' && req.method === 'GET' && req.headers['subscribe'] === 'true') { res.writeHead(209, 'unknown', { 'Range-Request-Allow-Methods': 'PATCH, PUT', 'Range-Request-Allow-Units': 'json', 'Patches': 'OK', 'subscribe': 'true', 'cache-control': 'no-cache, no-transform', 'Date': new Date().toUTCString(), 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=5', 'Transfer-Encoding': 'chunked' }); // Send the initial chunks res.write('11\r\n'); res.write('version: "test"\r\n'); res.write('14\r\n'); res.write('content-length: 16\r\n'); res.write('14\r\n'); res.write('{"this":"stuff"}\r\n'); res.write('2\r\n'); res.write('\r\n'); // Keep connection alive by periodically sending empty chunks const interval = setInterval(() => { if (res.writableEnded) { clearInterval(interval); return; } // Optional: send keep-alive whitespace or heartbeat chunk res.write('1\r\n \r\n'); }, 5000); // every 5 seconds // Clean up on client disconnect req.on('close', () => { clearInterval(interval); }); } else { res.writeHead(404); res.end('Not found'); } }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); }); ``` Execute the following in devtools ```js fetch('/json', { headers: { subscribe: 'true' } }) .then(response => { const reader = response.body.getReader(); const decoder = new TextDecoder(); function readChunk() { return reader.read().then(({ done, value }) => { if (done) { console.log('Stream complete'); return; } console.log('Received chunk:', decoder.decode(value, { stream: true })); return readChunk(); }); } return readChunk(); }); ``` This works on Chrome. Just hangs on Firefox, because the streamed response never actually completes.
The example in comment 2 doesn't work in Chrome either. What does is the following: server.js: ```js const http = require('http'); const server = http.createServer((req, res) => { if (req.url === '/json' && req.method === 'GET') { res.writeHead(209, 'unknown', { 'Range-Request-Allow-Methods': 'PATCH, PUT', 'Range-Request-Allow-Units': 'json', 'Patches': 'OK', 'subscribe': 'true', 'cache-control': 'no-cache, no-transform', 'Date': new Date().toUTCString(), 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=5', 'Transfer-Encoding': 'chunked' }); // Send the initial chunks res.write('11\r\n'); res.write('version: "test"\r\n'); res.write('14\r\n'); res.write('content-length: 16\r\n'); res.write('14\r\n'); res.write('{"this":"stuff"}\r\n'); res.write('2\r\n'); res.write('\r\n'); // Keep connection alive by periodically sending empty chunks const interval = setInterval(() => { if (res.writableEnded) { clearInterval(interval); return; } // Optional: send keep-alive whitespace or heartbeat chunk res.write('1\r\n \r\n'); }, 5000); // every 5 seconds // Clean up on client disconnect req.on('close', () => { clearInterval(interval); }); } else { res.writeHead(404); res.end('Not found'); } }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); }); ``` Execute the following in devtools ```js fetch('/json') .then(response => { const reader = response.body.getReader(); const decoder = new TextDecoder(); function readChunk() { return reader.read().then(({ done, value }) => { if (done) { console.log('Stream complete'); return; } console.log('Received chunk:', decoder.decode(value, { stream: true })); return readChunk(); }); } return readChunk(); }); ``` This works on Chrome. Just hangs on Firefox, because the streamed response never actually completes.