From 899f5543364c3207b0328823a865cd55ccd12bcc Mon Sep 17 00:00:00 2001 From: eson Date: Wed, 25 Nov 2020 12:23:46 +0800 Subject: [PATCH] fix(closetab): 1.fix close tab. 2.waittime default = 6000 --- chromeproxy/.vscode/launch.json | 1 + chromeproxy/background/capture.js | 20 +++++++++++++++----- chromeproxy/background/worker.js | 17 ++++++++++++++++- chromeproxy/content/inject.js | 4 ++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/chromeproxy/.vscode/launch.json b/chromeproxy/.vscode/launch.json index e7e40e2..e351a57 100644 --- a/chromeproxy/.vscode/launch.json +++ b/chromeproxy/.vscode/launch.json @@ -14,6 +14,7 @@ "--ignore-certificate-errors", "--disable-dev-shm-usage", "--mute-audio", + "--single-process", "--safebrowsing-disable-auto-update", "--disable-gpu", "--no-sandbox", diff --git a/chromeproxy/background/capture.js b/chromeproxy/background/capture.js index fcd98ae..7e1b8c1 100644 --- a/chromeproxy/background/capture.js +++ b/chromeproxy/background/capture.js @@ -1,10 +1,14 @@ - var href = window.location.href; var content = document.documentElement.innerHTML; -setTimeout(function(){ - window.close(); -}, 15000) +try { + if(waittime === undefined) { + waittime = 6000 + } +} catch (error) { + waittime = 6000 +} + if (condition == undefined) { condition = function () { @@ -15,7 +19,13 @@ if (condition == undefined) { if (condition()) { Tell(BackgroundMsgType.CONTENT, content); } else { - Tell(BackgroundMsgType.NOTWANT, content); + setTimeout(function () { + if (condition()) { + Tell(BackgroundMsgType.CONTENT, content); + } else { + Tell(BackgroundMsgType.NOTWANT, content); + } + }, waittime) } function Tell(backgroundType, content) { diff --git a/chromeproxy/background/worker.js b/chromeproxy/background/worker.js index da41e2a..14b449c 100644 --- a/chromeproxy/background/worker.js +++ b/chromeproxy/background/worker.js @@ -16,7 +16,15 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { GetTask(sender); break; case BackgroundMsgType.NOTWANT: - ErrorTask(sender, request.content); + + task = task_manager[sender.tab.id]; + task.data.retry --; + if(task.data.retry >= 0) { + CaptureContent(task); + } else { + ErrorTask(sender, request.content); + } + break; default: break; @@ -27,6 +35,7 @@ function GetTask(sender) { fetch(GetTaskUrl).then(function (response) { if (response.ok) { response.json().then(function (task) { + CaptureContent(task); }) } else { @@ -41,6 +50,11 @@ function GetTask(sender) { function CaptureContent(task) { if (task.code == 200) { + + if(task.data.retry == undefined) { + task.data.retry = 1; + } + chrome.tabs.create({ url: task.data.url }, function (tab) { task_manager[tab.id] = task; if (task.data.content_condition) { @@ -60,6 +74,7 @@ function CaptureContent(task) { function FinishTask(sender, content) { var task = task_manager[sender.tab.id]; var formdata = new FormData(); + formdata.append("taskid", task.data.taskid); formdata.append("content", content); diff --git a/chromeproxy/content/inject.js b/chromeproxy/content/inject.js index 2e56971..936d20f 100644 --- a/chromeproxy/content/inject.js +++ b/chromeproxy/content/inject.js @@ -3,6 +3,10 @@ if(href.startsWith(Host)) { setInterval(function(){ GetTask(); }, 1); +} else { + setTimeout(function(){ + close(); + }, 15000) } function GetTask() {