更换获取方式方法

This commit is contained in:
aixianling
2023-08-15 17:09:00 +08:00
parent 2b142153d5
commit 2d12360655
7 changed files with 48 additions and 41 deletions

View File

@@ -1,21 +1,20 @@
/**
利用chrome的fetch来避免跨域
**/
import {genAnti} from "@/entry/genAnti";
import {getAntiContent} from "@/api/chromeApi";
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type == 'api') {
new Promise((resolve, reject) => {
new Promise((resolve) => {
let headers = {};
if (request.needMallId) {
headers.Mallid = request.mallId;
}
if (request.anti) {
headers["Anti-Content"] = getAntiContent()
}
headers['Content-Type'] = 'application/json';
headers.cookie = getCookie();
// Promise.resolve(genAnti()).then(r => {
// headers["Anti-Content"] = r
// })
Promise.resolve().then(() => fetch(request.url, {
'headers': headers,
'method': 'POST',
@@ -26,11 +25,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
})).then((res) => {
resolve(res.json());
});
}).then((res) => {
sendResponse(res);
});
} else if (request.type == 'init') {
fetch(request.url,{headers:{cookie: getCookie()}}).then(res => sendResponse(res.text()));
}).then(sendResponse);
} else if (request.type == 'notify') {
chrome.notifications.create(
"" + Math.random(), {