This commit is contained in:
cilame 2022-11-27 19:38:37 +08:00
parent efb13726d1
commit 1dab3cd1c4
2 changed files with 47 additions and 1 deletions

View File

@ -26,12 +26,35 @@ chrome.contextMenus.create({
AttachDebugger();
}
});
chrome.contextMenus.create({
title: "修改发送请求",
contexts: ['all'],
onclick: function(){
init_edit_function()
edit_request = true
AttachDebugger();
}
});
function init_edit_function(){
chrome.storage.local.get(["config-request_hook"], function (res) {
try{
var code = res["config-request_hook"]
}catch(e){
console.log(e)
}
})
}
var ast_dyn_hook = false
var html_copy = false
var edit_request = false
function close_debugger(){
attached = false
ast_dyn_hook = false
html_copy = false
edit_request = false
}
function sendCommand(method, params, source, chainfun){
chrome.debugger.sendCommand(source, method, params, function(result){
@ -105,7 +128,24 @@ chrome.debugger.onEvent.addListener(function (source, method, params){
})
return
});
break; }
break;
}else{
var options = { requestId: params.requestId }
if (edit_request){
var url = params.request.url
var method = params.request.method
var postData = params.request.postData
var headers = params.request.headers
// console.log(method, url, headers, postData)
// 这里处理更新操作
// options.url = url
// options.method = method
// options.postData = postData
// options.headers = headers // 这里直接放进去似乎还会有问题
}
sendCommand("Fetch.continueRequest", options, source);
break;
}
}
})
chrome.debugger.onDetach.addListener(function(){
@ -144,6 +184,8 @@ function AttachDebugger() {
// {urlPattern:"*",resourceType:"Manifest",requestStage:"Response"},
// {urlPattern:"*",resourceType:"SignedExchange",requestStage:"Response"},
// {urlPattern:"*",resourceType:"Preflight",requestStage:"Response"},
{urlPattern:"*",requestStage:"request"},
] }, currtab);
});
}

View File

@ -138,6 +138,10 @@
<div>适用的本地文件后缀txt,html,htm,css,js,json,xml,jpg,gif,png,webp</div>
<table id="response_changer"></table>
<h2 style="margin-bottom: 0px;margin-top: 50px;">动态修改请求包</h2>
<hr>
<textarea id='fetch_hook' data-key="config-request_hook" style="width: 100%; height: 500px"></textarea>
<h2 style="margin-bottom: 0px;margin-top: 50px;">动态修改被调试页面的所有js代码</h2>
<hr>
<div>这里的功能:在目标网页上右键菜单选择 “打开 ast 动态挂钩” 即可开启,使用用插件的方式 hook 住目标页面的所有代码,像是在 node 里面一样使用 ast 将原始的代码修改成期望的样子</div>