Fix corsFetch
This commit is contained in:
15
content.js
15
content.js
@@ -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
|
||||
}
|
||||
);
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"<all_urls>",
|
||||
"activeTab",
|
||||
"windows",
|
||||
"storage"
|
||||
"storage",
|
||||
"tabs"
|
||||
],
|
||||
"background": {
|
||||
"scripts": ["background.js"],
|
||||
|
||||
10
popup.js
10
popup.js
@@ -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){
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user