TODO: 测试Callback稳定性.
This commit is contained in:
@@ -17,6 +17,7 @@ function GetTask(sender) {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// ErrorTask(sender, "error response:" + response.text())
|
||||
console.log("error response:",response.text())
|
||||
}
|
||||
}).catch(function (reason) {
|
||||
@@ -30,7 +31,7 @@ function FinishTask(sender, content) {
|
||||
var formdata = new FormData();
|
||||
formdata.append("taskid", task.data.taskid);
|
||||
formdata.append("content", content);
|
||||
|
||||
console.log(task.data.taskid);
|
||||
fetch(FinishTaskUrl, {method: "POST", body: formdata }).then(function (response) {
|
||||
if (response.ok) {
|
||||
response.json().then(function (value) {
|
||||
@@ -42,6 +43,8 @@ function FinishTask(sender, content) {
|
||||
}
|
||||
}).catch(function(error){
|
||||
// TODO: 汇报错误
|
||||
// ErrorTask(sender, error);
|
||||
console.log(error)
|
||||
GetTask(sender);
|
||||
return;
|
||||
});
|
||||
@@ -56,16 +59,13 @@ function ErrorTask(sender, error) {
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
// console.log(request);
|
||||
sendResponse({});
|
||||
// console.log(request, sender); // 利用sender tab id 返回正确的任务id
|
||||
switch (request.type) {
|
||||
case BackgroundMsgType.CONTENT:
|
||||
// 重新获取任务
|
||||
FinishTask(sender, request.content);
|
||||
break;
|
||||
case BackgroundMsgType.ERROR:
|
||||
|
||||
// 重新获取任务
|
||||
ErrorTask(sender, request.error)
|
||||
GetTask(sender);
|
||||
@@ -97,60 +97,4 @@ chrome.webRequest.onBeforeRequest.addListener(function (details) {
|
||||
chrome.tabs.remove(details.tabId, function () { });
|
||||
return { cancel: true };
|
||||
}
|
||||
}, { 'urls': ["<all_urls>"] }, ['blocking']);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// chrome.webRequest.onCompleted.addListener(
|
||||
// function (details) {
|
||||
// console.log(details);
|
||||
// console.log(document);
|
||||
// // return { responseHeaders: details.responseHeaders};
|
||||
// },
|
||||
// {
|
||||
// urls: ["<all_urls>"],
|
||||
// types: [
|
||||
// "main_frame",
|
||||
// "sub_frame",
|
||||
// "stylesheet",
|
||||
// "script",
|
||||
// "image",
|
||||
// "object",
|
||||
// "xmlhttprequest",
|
||||
// "other"
|
||||
// ]
|
||||
// },
|
||||
// ["responseHeaders", "extraHeaders"]
|
||||
// );
|
||||
|
||||
|
||||
|
||||
// fetch('https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser').then(r => r.text()).then(result => {
|
||||
// // Result now contains the response text, do what you want...
|
||||
// console.log(result);
|
||||
// })
|
||||
|
||||
// chrome.webRequest.onBeforeRequest.addListener(function(data){
|
||||
// // data contains request_body
|
||||
// return {redirectUrl: "https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"};
|
||||
// },{'urls':["<all_urls>"]},['blocking']);
|
||||
}, { 'urls': ["<all_urls>"] }, ['blocking']);
|
||||
Reference in New Issue
Block a user