diff --git a/privacy-protections/request-blocking/main.js b/privacy-protections/request-blocking/main.js index 9a8278a..196bde0 100644 --- a/privacy-protections/request-blocking/main.js +++ b/privacy-protections/request-blocking/main.js @@ -300,6 +300,33 @@ const tests = [ ajax.send(); } }, + { + category: 'js', + id: 'sendBeacon', + description: 'Try sending data using sendBeacon.', + checkAsync: (callback) => { + const observer = new PerformanceObserver(observed); + + const checkResource = resource => { + if (resource.name.includes(`beacon?${random}`)) { + if (resource.serverTiming.length === 0) { + callback('failed'); + } else { + callback('loaded'); + } + observer.disconnect(); + } + }; + + function observed (list) { + list.getEntries().forEach(checkResource); + } + + observer.observe({ entryTypes: ['resource'] }); + + navigator.sendBeacon(`https://${TRACKER_DOMAIN}/block-me/beacon?${random}`, 'fake=data'); + } + }, { category: 'other', id: 'favicon', diff --git a/server.js b/server.js index c3f1a1f..eb39b7b 100644 --- a/server.js +++ b/server.js @@ -100,6 +100,13 @@ app.post('/block-me/csp', (req, res) => { return res.sendStatus(200); }); +// dummy sednBeacon endopoint +app.post('/block-me/beacon', (req, res) => { + res.set('Timing-Allow-Origin', '*'); + res.set('Server-Timing', 'loaded'); + return res.sendStatus(204); +}); + // reflects request headers and request url back app.get('/reflect-headers', (req, res) => { res.set('Access-Control-Allow-Origin', req.headers.origin || '*');