0

I'm trying to open new tab in the same browser session and switch context to it.

When I do it with following code:

await BrowserSession.Browser.Contexts[0].NewPageAsync();

I got the error: Please use Browser.NewContextAsync()


await BrowserSession.Browser.NewPageAsync();

from other hand create new BrowserContext and open new page in separate window (not new tab).

ggorlen
  • 44,755
  • 7
  • 76
  • 106
laxsore
  • 143
  • 1
  • 2
  • 9

1 Answers1

0

Playwright's documentation states:

Page provides methods to interact with a single tab in a Browser... One Browser instance might have multiple Page instances.

https://playwright.dev/dotnet/docs/api/class-page

Using the above you should be able to open another tab using something like this:

using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Webkit.LaunchAsync();

var tabOne = await browser.NewPageAsync();
await tabOne.GotoAsync("https://www.theverge.com");

var tabTwo = await browser.NewPageAsync();
await tabTwo.GotoAsync("https://www.google.com");
BernardV
  • 640
  • 10
  • 28