Giter VIP home page Giter VIP logo

playwright-extra-sharp's Introduction

PlaywrightExtraSharp

NuGet Badge

Based on Puppeteer extra sharp and Node.js Playwright extra

Quickstart

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");

Note

Because of how Playwright behaves with pages, you should only create new pages through PlaywrightExtra wrapper and not IBrowser. Please refer to examples above.

Context Persistence

There are 4 different ways to work with context in PlaywrightExtra:

  1. launch incognito (as default was) with permanent context
.LaunchAsync(new ()
    {
        Headless = false
    },
    persistContext: true)
  1. launch incognito with new context per page (so when page is closed, context is disposed)
.LaunchAsync(new ()
    {
        Headless = false
    },
    persistContext: false)
  1. launch persistent (user data dir is considered) with permanent context
.LaunchPersistentAsync(new ()
    {
        Headless = false
    },
    persistContext: true)
  1. launch persistent with new context per page
.LaunchPersistentAsync(new ()
    {
        Headless = false
    },
    persistContext: false)

User data directory

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");

Helpers

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.

playwright-extra-sharp's People

Contributors

gshev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.