Skip to content

[Feature] Ability to provide postData & method properties in page.goto. #5921

@domderen

Description

@domderen

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions