Request interception continue method probably not working with POST method
See original GitHub issueI’m using Puppeteer 2.0.0 (Node.js v11.12.0) and want to perform a POST request. When running the following code:
const puppeteer = require("puppeteer");
const devices = require("puppeteer/DeviceDescriptors");
async function main() {
const browser = await puppeteer.launch({
args: ["--enable-features=NetworkService", "--no-sandbox"],
ignoreHTTPSErrors: true
});
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on("request", interceptedRequest => {
const method = "POST", postData = "foo=FOO&bar=BAR";
interceptedRequest.continue({ method, postData });
});
const response = await page.goto("https://postman-echo.com/post");
console.log({
url: response.url(),
statusCode: response.status(),
method: response.request().method(),
body: await response.text()
});
setTimeout(async () => await browser.close(), 1000);
}
main();
I get statusCode: 200 and method: ‘GET’ like it wasn’t intercepted.
What is even more confusing - when I try to do it with CDP Session:
const puppeteer = require("puppeteer");
const devices = require("puppeteer/DeviceDescriptors");
async function main() {
const browser = await puppeteer.launch({
args: ["--enable-features=NetworkService", "--no-sandbox"],
ignoreHTTPSErrors: true
});
const page = await browser.newPage();
const session = await page.target().createCDPSession();
await session.send( "Network.enable" );
await session.send( "Network.setRequestInterception", {
patterns: [{
urlPattern: "*",
interceptionStage: "HeadersReceived"
}]
});
session.on( "Network.requestIntercepted", async ({ interceptionId, request, responseHeaders, resourceType }) => {
await session.send( "Network.continueInterceptedRequest", {
interceptionId,
url: request.url,
method: "POST",
postData: "foo=FOO&bar=BAR"
});
session.detach();
});
const response = await page.goto("https://postman-echo.com/post");
console.log({
url: response.url(),
statusCode: response.status(),
method: response.request().method(),
body: await response.text()
});
setTimeout(async () => await browser.close(), 1000);
}
main();
I get statusCode: 404 and method: ‘GET’
Am I doing something wrong or is it an issue with Puppeteer?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to intercept request in Puppeteer before current page is ...
I tried request interception but at the moment request gets intercepted the current page is already lost so I would have to go...
Read more >Intercepting requests | Checkly
Request interception enables us to observe which requests and responses are being exchanged as part of our script's execution. For example, this is...
Read more >Request interception with Puppeteer and Playwright
Request interception enables us to observe which requests and responses are being exchanged as part of our script's execution.
Read more >Request Interception - Puppeteer
Once request interception is enabled, every request will stall unless it's continued, responded or aborted. An example of a naïve request interceptor that ......
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
By default, it intercepts requests matching any HTTP method. Thus when you define several intercepts, it is easy to get into the situation...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, I see
prints the server response body with the POST parameters in it. Thanks.
response.request
contains the original request being made.request.continue
won’t alter therequests
array. If you test that code using https://ptsv2.com/, you will see that you are getting posts on the other side.