Skip to content

Commit

Permalink
Merge pull request #832 from shy1132/master
Browse files Browse the repository at this point in the history
fix oldtwitter on old-ish firefox versions
  • Loading branch information
dimdenGD authored Jun 8, 2024
2 parents da6174f + 48d8a5c commit 7cc5d6b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
26 changes: 25 additions & 1 deletion scripts/background_v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,31 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
},
["blocking", "requestHeaders"]
);

chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
for (let i = 0; i < details.requestHeaders.length; i++) {
if (details.requestHeaders[i].name.toLowerCase() === 'user-agent') {
if (details.requestHeaders[i].value.toLowerCase().includes('firefox')) {
let rvRegex = /rv:(\d+\.\d+)/;
let rvMatch = details.requestHeaders[i].value.match(rvRegex);
if (rvMatch) {
let rv = parseFloat(rvMatch[1]);
if (rv < 110) {
details.requestHeaders[i].value = details.requestHeaders[i].value.replace(rvRegex, 'rv:110.0'); //twitter serves client-web-legacy if rv is less than 110, which breaks request signing
}
}
}
break;
}
}
return {
requestHeaders: details.requestHeaders
};
}, {
urls: ["*://x.com/", "*://twitter.com/"]
},
["blocking", "requestHeaders"]
);
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
if(request.action === "inject") {
console.log(request, sender.tab.id);
Expand Down
13 changes: 10 additions & 3 deletions scripts/twchallenge.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
let solveId = 0;
let solveCallbacks = {};
let solveQueue = []
let solverReady = false;
let solverErrored = false;

let solverIframe = document.createElement('iframe');
Expand All @@ -26,16 +28,16 @@ function solveChallenge(path, method) {
}
let id = solveId++;
solveCallbacks[id] = { resolve, reject, time: Date.now() };
if(solverIframe && solverIframe.contentWindow) {
if(!solverIframe || !solverIframe.contentWindow || !solverReady) {
solveQueue.push({ id, path, method })
} else {
solverIframe.contentWindow.postMessage({ action: 'solve', id, path, method }, '*');
// setTimeout(() => {
// if(solveCallbacks[id]) {
// solveCallbacks[id].reject('Solver timed out');
// delete solveCallbacks[id];
// }
// }, 1750);
} else {
reject('Solver iframe not ready');
}
});
}
Expand Down Expand Up @@ -64,6 +66,11 @@ window.addEventListener('message', e => {
alert(`There was an error in initializing security header generator: ${data.error}. OldTwitter doesn't allow unsigned requests anymore for your account security. Currently it's unknown what causes this to happen, try reloading the page.`);
console.error('Error initializing solver:');
console.error(data.error);
} else if(data.action === 'ready') {
solverReady = true;
for (let task of solveQueue) {
solverIframe.contentWindow.postMessage({ action: 'solve', id: task.id, path: task.path, method: task.method }, '*')
}
}
});

Expand Down

0 comments on commit 7cc5d6b

Please sign in to comment.