docs: update context.backgroundPage event examples (#30210)

Fixes https://github.com/microsoft/playwright-java/issues/1530
This commit is contained in:
Yury Semikhatsky 2024-04-02 11:32:57 -07:00 committed by GitHub
parent 4baacba4f9
commit 8056e5391f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -73,10 +73,9 @@ Only works with Chromium browser's persistent context.
Emitted when new background page is created in the context. Emitted when new background page is created in the context.
```java ```java
Page backgroundPage = context.waitForBackgroundPage(() -> { context.onBackgroundPage(backgroundPage -> {
page.getByText("activate extension").click(); System.out.println(backgroundPage.url());
}); });
System.out.println(backgroundPage.evaluate("location.href"));
``` ```
```js ```js
@ -92,11 +91,11 @@ background_page = context.wait_for_event("backgroundpage")
``` ```
```csharp ```csharp
var backgroundPage = await context.RunAndWaitForBackgoundPageAsync(async => context.BackgroundPage += (backgroundPage) =>
{ {
await page.GetByText("activate extension").ClickAsync(); Console.WriteLine(backgroundPage.Url());
}); };
Console.WriteLine(await backgroundPage.EvaluateAsync<string>("location.href"));
``` ```
## event: BrowserContext.close ## event: BrowserContext.close