-
Notifications
You must be signed in to change notification settings - Fork 5k
Closed
Description
Hey, I'd like to be able to make a POST request from the browser. I'm using playwright for web app security testing, and I'd like to skip the part of submitting the form on my page by performing clicks on the page, and directly send data to my webserver, and see the response that it generates.
I found that it is possible with a code like this:
async function run() {
const browser = await chromium.launch({
headless: false
});
const context = await browser.newContext();
const url = 'http://httpbin.org/post';
// Open new page
const page = await context.newPage();
await page.route(url, (route, request) => {
route.continue({method: 'POST', postData: 'Some data'});
});
await page.goto(url);
console.log(await page.content());
}This makes a valid POST request to the server, and logs back the response.
I think it would be helpful to fold just a route/continue call under new properties in page.goto call, so that the example above could look like this:
async function run() {
const browser = await chromium.launch({
headless: false
});
const context = await browser.newContext();
const url = 'http://httpbin.org/post';
// Open new page
const page = await context.newPage();
await page.goto(url, {method: 'POST', postData: 'Some data'});
console.log(await page.content());
}Metadata
Metadata
Assignees
Labels
No labels