Based on Puppeteer extra sharp and Node.js Playwright extra
Long way
// Initialization plugin builder
var playwrightExtra = new PlaywrightExtra(BrowserTypeEnum.Chromium);
// Install browser
playwrightExtra.Install();
// Use stealth plugin
playwrightExtra.Use(new StealthExtraPlugin());
// Launch the puppeteer browser with plugins
await playwrightExtra.LaunchAsync(new ()
{
Headless = false
});
// Create a new page
var page = await playwrightExtra.NewPageAsync();
await page.GoToAsync("http://google.com");
Compact way
// Initialize, install, use plugin and launch
var playwrightExtra = await new PlaywrightExtra(BrowserTypeEnum.Chromium)
.Install()
.Use(new StealthExtraPlugin())
.LaunchAsync(new ()
{
Headless = false
});
// Create a new page
var page = await playwrightExtra.NewPageAsync();
await page.GoToAsync("http://google.com");
Because of how Playwright behaves with pages, you should only create new pages through PlaywrightExtra wrapper and not IBrowser. Please refer to examples above.
There are 4 different ways to work with context in PlaywrightExtra:
.LaunchAsync(new ()
{
Headless = false
},
persistContext: true)
.LaunchAsync(new ()
{
Headless = false
},
persistContext: false)
.LaunchPersistentAsync(new ()
{
Headless = false
},
persistContext: true)
.LaunchPersistentAsync(new ()
{
Headless = false
},
persistContext: false)
While running persistent mode you can specify path to user data directory.
When context is persisted, specify directory at launch:
.LaunchPersistentAsync(new ()
{
Headless = false
},
persistContext: true,
userDataDir: "/path/to/userdir")
When context is created for each page (persistContext: false
), specify directory at page creation:
var page = await _playwrightExtra.NewPageAsync(userDataDir: "/path/to/userdir");
For convenience, you can use helper method when performing request:
await page.GotoAndWaitForIdleAsync("http://google.com/",
idleTime: TimeSpan.FromMilliseconds(1000));
Basically this works like if you perform request with option WaitUntil = WaitUntilState.NetworkIdle
But unlike builtin method, you can specify amount of time to wait after last request has fired.