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>
<title></title>
<meta charset="utf-8">
<script src="./tools/babel_asttool.js"></script>
<script src="background.js"></script>
</head>
<body>

View File

@ -20,7 +20,6 @@ function sendCommand(method, params, source, chainfun){
chrome.debugger.onEvent.addListener(function (source, method, params){
switch(method){
case "Fetch.requestPaused":
console.log("xmFetch","Fetch.requestPaused", params.request.url)
var itheaders = params.responseHeaders;
if (itheaders.find(function(v){return v.name == "Location"})) {
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){
// 收到的是 base64 的代码base64 解一下就是原始代码,对这个代码处理一下后续再用 base64 包一层再传入 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", {
requestId: params.requestId, responseCode: params.responseStatusCode, responseHeaders: params.responseHeaders,
body: result.body, // 这里只能传 base64(指定代码)
body: result.body, // body 只能传 base64(指定代码)
}, source);
});
break;
@ -50,19 +50,21 @@ 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 tab = { tabId: tabs[0].id };
chrome.debugger.attach(tab, "1.2", function () {
currtab = { tabId: tabs[0].id };
chrome.debugger.attach(currtab, "1.2", function () {
// 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: [
{urlPattern:"*",resourceType:"Script",requestStage:"Response"},
{urlPattern:"*",resourceType:"Document",requestStage:"Response"},
] }, tab);
] }, currtab);
});
}
);