diff --git a/background.html b/background.html index 1088cf8..8f28630 100644 --- a/background.html +++ b/background.html @@ -6,6 +6,7 @@ + diff --git a/background.js b/background.js index 399ca52..affd0f9 100644 --- a/background.js +++ b/background.js @@ -40,12 +40,10 @@ chrome.debugger.onEvent.addListener(function (source, method, params){ var replacer = eval((res["config-fetch_hook"]||'')+';fetch_hook') if (params.resourceType == 'Script'){ var replbody = btoa(replacer(respboby, params.request.url)) } if (params.resourceType == 'Document'){ var replbody = btoa(html_script_replacer(respboby, replacer, params.request.url)) } - fillfunc(replbody) - } + fillfunc(replbody) } catch(e){ - // hook 修改失败,将错误信息传入前端,直接在前端反馈错误信息 - fillfunc(result.body) - } + send_error_info_to_front(e.stack, currtab.tabId) + fillfunc(result.body) } }) return } fillfunc(result.body) // body 只能传 base64(指定代码) @@ -55,13 +53,14 @@ chrome.debugger.onEvent.addListener(function (source, method, params){ }) chrome.debugger.onDetach.addListener(function(){ attached = false }) var attached = false +var currtab; function AttachDebugger() { if (attached){ return } attached = true chrome.tabs.query( { active: true, currentWindow: true }, function (tabs) { - var currtab = { tabId: tabs[0].id }; + currtab = { tabId: tabs[0].id }; chrome.debugger.attach(currtab, "1.2", function () { sendCommand("Network.enable", {}, currtab, function(){ sendCommand("Network.setCacheDisabled", {cacheDisabled: true}, currtab)} ) // 确保 Fetch.getResponseBody 一定能收到东西 sendCommand("Fetch.enable", { patterns: [ diff --git a/inject.js b/inject.js index ea2035f..e6b2a29 100644 --- a/inject.js +++ b/inject.js @@ -439,3 +439,8 @@ chrome.storage.local.get(hookers, function (result) { inject_script(`(${replacer_injectfunc})(${JSON.stringify(result)},window)`); }) +chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) { + if (msg.action.type == 'error'){ + inject_script(`console.error(${JSON.stringify(msg.action.info)})`) + } +}); \ No newline at end of file diff --git a/tools/error_front.js b/tools/error_front.js new file mode 100644 index 0000000..4bb6a13 --- /dev/null +++ b/tools/error_front.js @@ -0,0 +1,5 @@ +function send_error_info_to_front(e, tid){ + chrome.tabs.query({active: true, currentWindow: true}, function(tabs){ + chrome.tabs.sendMessage(tid, {action: {type:'error', info: e}}, function(response) {}); + }); +} \ No newline at end of file