This commit is contained in:
cilame 2021-10-17 17:05:58 +08:00
parent 0167aecfe7
commit 83151df98e
2 changed files with 9 additions and 6 deletions

View File

@ -3,6 +3,7 @@
<head> <head>
<title></title> <title></title>
<meta charset="utf-8"> <meta charset="utf-8">
<script src="./tools/babel_asttool.js"></script>
<script src="background.js"></script> <script src="background.js"></script>
</head> </head>
<body> <body>

View File

@ -20,7 +20,6 @@ function sendCommand(method, params, source, chainfun){
chrome.debugger.onEvent.addListener(function (source, method, params){ chrome.debugger.onEvent.addListener(function (source, method, params){
switch(method){ switch(method){
case "Fetch.requestPaused": case "Fetch.requestPaused":
console.log("xmFetch","Fetch.requestPaused", params.request.url)
var itheaders = params.responseHeaders; var itheaders = params.responseHeaders;
if (itheaders.find(function(v){return v.name == "Location"})) { if (itheaders.find(function(v){return v.name == "Location"})) {
sendCommand("Fetch.continueRequest", { requestId: params.requestId, url: itheaders.value }, source); sendCommand("Fetch.continueRequest", { requestId: params.requestId, url: itheaders.value }, source);
@ -35,11 +34,12 @@ chrome.debugger.onEvent.addListener(function (source, method, params){
if (result.body !== undefined){ if (result.body !== undefined){
// 收到的是 base64 的代码base64 解一下就是原始代码,对这个代码处理一下后续再用 base64 包一层再传入 body // 收到的是 base64 的代码base64 解一下就是原始代码,对这个代码处理一下后续再用 base64 包一层再传入 body
var rescode = atob(result.body) var rescode = atob(result.body)
console.log(rescode) var resourceType = params.resourceType // 通过这里的类型对获取到的 body 信息进行处理
console.log(rescode.length, Object.keys(result), rescode.slice(0,100))
} }
sendCommand("Fetch.fulfillRequest", { sendCommand("Fetch.fulfillRequest", {
requestId: params.requestId, responseCode: params.responseStatusCode, responseHeaders: params.responseHeaders, requestId: params.requestId, responseCode: params.responseStatusCode, responseHeaders: params.responseHeaders,
body: result.body, // 这里只能传 base64(指定代码) body: result.body, // body 只能传 base64(指定代码)
}, source); }, source);
}); });
break; break;
@ -50,19 +50,21 @@ chrome.debugger.onDetach.addListener(function(){
attached = false attached = false
}) })
var attached = false var attached = false
var currtab;
function AttachDebugger() { function AttachDebugger() {
if (attached){ return } if (attached){ return }
attached = true attached = true
chrome.tabs.query( chrome.tabs.query(
{ active: true, currentWindow: true }, { active: true, currentWindow: true },
function (tabs) { function (tabs) {
var tab = { tabId: tabs[0].id }; currtab = { tabId: tabs[0].id };
chrome.debugger.attach(tab, "1.2", function () { chrome.debugger.attach(currtab, "1.2", function () {
// Document, Stylesheet, Image, Media, Font, Script, TextTrack, XHR, Fetch, EventSource, WebSocket, Manifest, SignedExchange, Ping, CSPViolationReport, Preflight, Other // Document, Stylesheet, Image, Media, Font, Script, TextTrack, XHR, Fetch, EventSource, WebSocket, Manifest, SignedExchange, Ping, CSPViolationReport, Preflight, Other
sendCommand("Network.enable", {}, currtab, function(){ sendCommand("Network.setCacheDisabled", {cacheDisabled: true}, currtab)} ) // 确保 Fetch.getResponseBody 一定能收到东西
sendCommand("Fetch.enable", { patterns: [ sendCommand("Fetch.enable", { patterns: [
{urlPattern:"*",resourceType:"Script",requestStage:"Response"}, {urlPattern:"*",resourceType:"Script",requestStage:"Response"},
{urlPattern:"*",resourceType:"Document",requestStage:"Response"}, {urlPattern:"*",resourceType:"Document",requestStage:"Response"},
] }, tab); ] }, currtab);
}); });
} }
); );