diff options
author | V <vendicated@riseup.net> | 2023-04-17 04:05:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-17 04:05:01 +0200 |
commit | 5305447f442b57443c4616ccd8d530c2c5e539b4 (patch) | |
tree | ae7eb4e71b1b2dffe15a5173d8282913a0c98e9d /browser | |
parent | 76e74b3e40c82ef1fd992596298fbf967bcef4c0 (diff) | |
download | Vencord-5305447f442b57443c4616ccd8d530c2c5e539b4.tar.gz Vencord-5305447f442b57443c4616ccd8d530c2c5e539b4.tar.bz2 Vencord-5305447f442b57443c4616ccd8d530c2c5e539b4.zip |
firefox: Fix csp (QuickCss, themes, some plugins) (#554)
Diffstat (limited to 'browser')
-rw-r--r-- | browser/background.js | 32 | ||||
-rw-r--r-- | browser/manifestv2.json | 41 |
2 files changed, 73 insertions, 0 deletions
diff --git a/browser/background.js b/browser/background.js new file mode 100644 index 0000000..7fc4a82 --- /dev/null +++ b/browser/background.js @@ -0,0 +1,32 @@ +/** + * @template T + * @param {T[]} arr + * @param {(v: T) => boolean} predicate + */ +function removeFirst(arr, predicate) { + const idx = arr.findIndex(predicate); + if (idx !== -1) arr.splice(idx, 1); +} + +chrome.webRequest.onHeadersReceived.addListener( + ({ responseHeaders, type, url }) => { + if (!responseHeaders) return; + + if (type === "main_frame") { + // In main frame requests, the CSP needs to be removed to enable fetching of custom css + // as desired by the user + removeFirst(responseHeaders, h => h.name.toLowerCase() === "content-security-policy"); + } else if (type === "stylesheet" && url.startsWith("https://raw.githubusercontent.com")) { + // Most users will load css from GitHub, but GitHub doesn't set the correct content type, + // so we fix it here + removeFirst(responseHeaders, h => h.name.toLowerCase() === "content-type"); + responseHeaders.push({ + name: "Content-Type", + value: "text/css" + }); + } + return { responseHeaders }; + }, + { urls: ["https://raw.githubusercontent.com/*", "*://*.discord.com/*"], types: ["main_frame", "stylesheet"] }, + ["blocking", "responseHeaders"] +); diff --git a/browser/manifestv2.json b/browser/manifestv2.json new file mode 100644 index 0000000..3cac945 --- /dev/null +++ b/browser/manifestv2.json @@ -0,0 +1,41 @@ +{ + "manifest_version": 2, + "minimum_chrome_version": "91", + + "name": "Vencord Web", + "description": "The cutest Discord mod now in your browser", + "author": "Vendicated", + "homepage_url": "https://github.com/Vendicated/Vencord", + "icons": { + "128": "icon.png" + }, + + "permissions": [ + "webRequest", + "webRequestBlocking", + "*://*.discord.com/*", + "https://raw.githubusercontent.com/*" + ], + + "content_scripts": [ + { + "run_at": "document_start", + "matches": ["*://*.discord.com/*"], + "js": ["content.js"], + "all_frames": true + } + ], + + "background": { + "scripts": ["background.js"] + }, + + "web_accessible_resources": ["dist/Vencord.js", "dist/Vencord.css"], + + "browser_specific_settings": { + "gecko": { + "id": "vencord-firefox@vendicated.dev", + "strict_min_version": "91.0" + } + } +} |