ProxymanApp / ProxymanApp/Proxyman
onResponse changing values in selected attributes - doesn’t work
@NghiaTranUIT is already working on this.
Since Dec 12, 2024.
- Dominant language
- No language data
- Stars
- 7k
- Forks
- 237
- PR merge metrics
- No merged PRs in 30d
Description
I am a tester with no programming skills. I use Maplocal or breakpoints on a daily basis. I noticed the scripts tab and wondered what it could be useful to me.
I am thinking about the case when I want to modify one value in the response without having to manually set up a breakpoint (situation when I need to have fresh /unique data in the response, but I need to change something specific)
As I do not know much about programming I asked the gpt chat to create such a script, unfortunately, despite many attempts/changes/analysis of errors, the data is not changed in the final response.
So, there is a simple response body (Json) with 3 attributes {"messages":10,"id":115,"card":0} , the goal is to change the response body for only messages value.
This is what i get from chatgpt:
function onResponse(context) {
if (context.response && context.response.body) {
let body = context.response.body;
try {
let json = JSON.parse(body);
json.messages = 1;
body = JSON.stringify(json);
context.response.body = body;
console.log("Modified response body:", body);
} catch (e) {
console.error("Error parsing JSON:", e);
}
} else {
console.log("Response body is empty or undefined.");
}
return context.response;
}
and this is na answer :
Response body is empty or undefined.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.