Skip to content

Parameterize behavior on clicking a link that opens a new tab #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kamath opened this issue Mar 20, 2025 · 1 comment
Open

Parameterize behavior on clicking a link that opens a new tab #602

kamath opened this issue Mar 20, 2025 · 1 comment

Comments

@kamath
Copy link
Member

kamath commented Mar 20, 2025

Make an act flag that can parameterize the new tab behavior in the example below, such that the user can choose whether or not to switch to the newly opened tab.

await page.goto("https://playwright.dev");
  await page.setContent(`
      <html>
        <body>
          <a href="https://playwright.dev" target="_blank">Open Playwright</a>
        </body>
      </html>
    `);
  await page.act("Click on Open Playwright link");
@annaVeretennikova
Copy link

Hi, @kamath! Could you make sure that the newly opened tab supports Stagehand methods like act()? It doesn't seem that right now it's possible.

await page.goto("https://playwright.dev");
  await page.setContent(`
      <html>
        <body>
          <a href="https://playwright.dev" target="_blank">Open Playwright</a>
        </body>
      </html>
    `);

const [newTab] = await Promise.all([
  context.waitForEvent('page'),
  page.act({ action: 'Click on Open Playwright' })
]);

await newTab.waitForLoadState('load');
await newTab.act('Do smth') // getting an error accessing act method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants