docs(dotnet): Browser examples (#6490)

This commit is contained in:
Anže Vodovnik 2021-05-10 20:24:54 +02:00 committed by GitHub
parent 00ec43974d
commit 3f6461189b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,24 @@ with sync_playwright() as playwright:
run(playwright) run(playwright)
``` ```
```csharp
using Microsoft.Playwright;
using System.Threading.Tasks;
class BrowserExamples
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
var firefox = playwright.Firefox;
var browser = await firefox.LaunchAsync(headless: false);
var page = await browser.NewPageAsync();
await page.GoToAsync("https://www.bing.com");
await browser.CloseAsync();
}
}
```
## event: Browser.disconnected ## event: Browser.disconnected
- argument: <[Browser]> - argument: <[Browser]>
@ -112,6 +130,14 @@ context = browser.new_context()
print(len(browser.contexts())) # prints `1` print(len(browser.contexts())) # prints `1`
``` ```
```csharp
using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Webkit.LaunchAsync();
System.Console.WriteLine(browser.Contexts.Count); // prints "0"
var context = await browser.NewContextAsync();
System.Console.WriteLine(browser.Contexts.Count); // prints "1"
```
## method: Browser.isConnected ## method: Browser.isConnected
- returns: <[boolean]> - returns: <[boolean]>
@ -170,6 +196,16 @@ page = context.new_page()
page.goto("https://example.com") page.goto("https://example.com")
``` ```
```csharp
using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Firefox.LaunchAsync();
// Create a new incognito browser context.
var context = await browser.NewContextAsync();
// Create a new page in a pristine context.
var page = await context.NewPageAsync(); ;
await page.GoToAsync("https://www.bing.com");
```
### option: Browser.newContext.-inline- = %%-shared-context-params-list-%% ### option: Browser.newContext.-inline- = %%-shared-context-params-list-%%
### option: Browser.newContext.proxy = %%-context-option-proxy-%% ### option: Browser.newContext.proxy = %%-context-option-proxy-%%