So after solving yesterday's problem (linked below) another one has popped up.
Setting a FormData key/value on click with Puppeteer/NodeJS
The issue I'm having today is that I'm trying to modify an existing key in the FormData that's being sent to the server. The request gets intercepted correctly, I parse the FormData using the "qs" query string parsing package, then try to modify an existing key and use "NEW VALUE" in it's place. When I log it everything looks fine. However when I run chrome with headless=false and inspect the traffic I can see that the request is being sent without "NEW VALUE". It's as if I'm just calling continue() without passing any parameters in. I've attached the code below.
await this.page.setRequestInterception(true);
this.page.on("request", interceptedRequest => {
const formDataObj = qs.parse(interceptedRequest.postData());
if (interceptedRequest.url() === "https://www.someurl.com" && formDataObj.email) {
formDataObj.existingKey= "NEW VALUE";
const options = {
'method': 'POST',
'postData': qs.stringify(formDataObj),
'headers': {
...interceptedRequest.headers(),
'Content-Type': 'application/x-www-form-urlencoded'
},
};
console.log("Sending with new data");
console.log(qs.stringify(formDataObj));
interceptedRequest.continue(options);
} else {
interceptedRequest.continue();
}
Not sure where to go from here. I've done a lot of reading and tried some things like different versions of Puppeteer, passing ONLY the FormData (as a string) in to the continue() call and using some flags like "--enable-feature=NetworkService" (suggested on github) when launching chrome but nothing is working. Any help would be greatly appreciated!