Fix corsFetch

This commit is contained in:
FoxRefire
2024-04-28 05:58:48 +09:00
parent d272e8f2e6
commit f710d007ea
4 changed files with 23 additions and 16 deletions

View File

@@ -20,18 +20,19 @@ document.addEventListener('pssh', (e) => {
//Fetch from original origin
chrome.runtime.onMessage.addListener(
async function (request, sender, sendResponse) {
function (request, sender, sendResponse) {
if(request.type=="FETCH"){
console.log("DEBUG")
let res = await fetch(request.u, {
console.log("DEBUG:"+JSON.stringify(request))
let res = fetch(request.u, {
method: request.m,
headers: request.h,
body: request.b
}).then((r)=>r.json()).then((r)=>{
btoa(String.fromCharCode(...new Uint8Array(r)))
}).then((r)=>r.arrayBuffer()).then((r)=>{
sendResponse(
btoa(String.fromCharCode(...new Uint8Array(r)))
);
})
sendResponse({res: res});
return true
}
return true
}
);

View File

@@ -11,7 +11,8 @@
"<all_urls>",
"activeTab",
"windows",
"storage"
"storage",
"tabs"
],
"background": {
"scripts": ["background.js"],

View File

@@ -34,9 +34,13 @@ function copyResult(){
}
window.corsFetch = (u, m, h, b) => {
chrome.runtime.sendMessage({type:"FETCH", u:u, m:m, h:h, b:b}, function(response) {
console.log(response)
});
return new Promise((resolve, reject) => {
chrome.tabs.query({ url:pageURL }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {type:"FETCH", u:u, m:m, h:h, b:b}, (res) => {
resolve(res)
})
})
})
}
if(psshs.length!=0){

View File

@@ -1,14 +1,15 @@
import base64
import re
import js
req = base64.b64decode(licBody.encode()).decode()
from pyodide.ffi import to_js
req = json.loads(base64.b64decode(licBody.encode()).decode())
b64challenge = base64.b64encode(challenge).decode()
req = re.sub(r'(?<=\"message\":\").*(?=\"})', b64challenge, req)
print(req)
req['message'] = b64challenge
# res = await (await pyfetch(licUrl,
# method="POST",
# headers=licHeaders,
# body=req
# )).json()
res = js.window.corsFetch(licUrl, "POST", licHeaders, req)
res = await js.corsFetch(licUrl, "POST", to_js(licHeaders), json.dumps(req))
res = json.loads(base64.b64decode(res.encode()).decode())
print(res)
licence = base64.b64decode(res['license'].encode())