Skip to content

Instantly share code, notes, and snippets.

@dwsmart
Created September 7, 2022 11:41
Show Gist options
  • Save dwsmart/1f136ba9698ede0067237a0745dbd2a7 to your computer and use it in GitHub Desktop.
Save dwsmart/1f136ba9698ede0067237a0745dbd2a7 to your computer and use it in GitHub Desktop.
/*
* a cloudflare worker to remove the script tag they inject into the head if you have a cloudflare app installed.
* WARNING: some apps may not work if you remove this script tag!!! But things like logflare that add no js of
* their own should be fine.
*/
addEventListener('fetch', event => {
const request = event.request
event.respondWith(handleRequest(request))
});
async function handleRequest(request) {
const url = new URL(request.url);
let oldResponse = await fetch(url.toString(), request)
let newResponse = new HTMLRewriter()
.on("script[src*='/cdn-cgi/apps/head/']", new removeScript())
.transform(oldResponse)
return newResponse
}
class removeScript {
element(element) {
element.remove();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment