Skip to content

Instantly share code, notes, and snippets.

@stefansundin
Created August 24, 2024 06:53
Show Gist options
  • Save stefansundin/611d415213029c025210757e4c0e1bb8 to your computer and use it in GitHub Desktop.
Save stefansundin/611d415213029c025210757e4c0e1bb8 to your computer and use it in GitHub Desktop.
Firefox browser extension that can disable the persisted queries GraphQL feature on Twitch.tv
// Note: This only works in Firefox!
//
// Load the extension in about:debugging
// If it doesn't seem to be working then click the Inspect button and see if there's any information in the Console tab
// One issue with old Firefox versions is that the host permission isn't automatically granted. Double check this in the Add-ons Manager.
//
// https://assets.twitch.tv/config/settings.0fa0027ddfc373022638f7943c4dd40d.js
function listener(details) {
console.log(details.url);
const filter = browser.webRequest.filterResponseData(details.requestId);
filter.onerror = (event) => {
console.error(`Error: ${filter.error}`);
};
filter.ondata = (event) => {
const decoder = new TextDecoder("utf-8");
const encoder = new TextEncoder();
let str = decoder.decode(event.data, { stream: true });
console.log(str);
str = str.replace(/"persisted_queries_enabled":\s*true/, '"persisted_queries_enabled":false');
if (str.includes('"persisted_queries_enabled":false')) {
console.log(`Successfully set "persisted_queries_enabled":false`);
}
filter.write(encoder.encode(str));
filter.disconnect();
};
filter.onstop = (event) => {
filter.close();
};
return {};
}
browser.webRequest.onBeforeRequest.addListener(
listener,
{
urls: ["https://assets.twitch.tv/config/settings.*.js"],
types: ["script"],
},
["blocking"]
);
{
"manifest_version": 3,
"name": "Twitch Disable Persisted GraphQL Queries",
"description": "Only works in Firefox!",
"version": "0.0.1",
"background": {
"scripts": ["background.js"]
},
"permissions": [
"webRequest",
"webRequestBlocking",
"webRequestFilterResponse"
],
"host_permissions": [
"https://www.twitch.tv/*",
"https://assets.twitch.tv/config/*"
],
"browser_specific_settings": {
"gecko": {
"strict_min_version": "127.0"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment