Removed x-frame-options header on iframes from Nitter instances #20

This commit is contained in:
ManeraKai 2022-03-23 13:50:51 +03:00
parent 1079e64f0d
commit 9547cc95fd
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 26 additions and 0 deletions

View File

@ -184,6 +184,20 @@ function switchInstance(url) {
return `${randomInstance}${url.pathname}${url.search}`; return `${randomInstance}${url.pathname}${url.search}`;
} }
function removeXFrameOptions(e) {
let url = new URL(e.url);
let protocolHost = `${url.protocol}//${url.host}`;
let twitterList = [
...redirects.nitter.normal,
...redirects.nitter.tor,
...nitterNormalCustomRedirects,
...nitterTorCustomRedirects,
];
if (!twitterList.includes(protocolHost) && e.type != 'sub_frame') return;
for (const i in e.responseHeaders) if (e.responseHeaders[i].name = 'x-frame-options') e.responseHeaders.splice(i, 1);
return { responseHeaders: e.responseHeaders };
}
function isNitter(url, type) { function isNitter(url, type) {
let protocolHost = `${url.protocol}//${url.host}`; let protocolHost = `${url.protocol}//${url.host}`;
@ -299,6 +313,8 @@ export default {
getBypassWatchOnTwitter, getBypassWatchOnTwitter,
setBypassWatchOnTwitter, setBypassWatchOnTwitter,
removeXFrameOptions,
getProtocol, getProtocol,
setProtocol, setProtocol,

View File

@ -131,6 +131,16 @@ browser.tabs.onRemoved.addListener(
} }
); );
// Set "blocking" and "responseHeaders".
browser.webRequest.onHeadersReceived.addListener(
e => {
return twitterHelper.removeXFrameOptions(e);
},
{ urls: ["<all_urls>"], },
["blocking", "responseHeaders"]
);
function redirectOfflineInstance(url, tabId) { function redirectOfflineInstance(url, tabId) {
let newUrl; let newUrl;