From 8056e5391fea6c63f30377542c003b160550c204 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 2 Apr 2024 11:32:57 -0700 Subject: [PATCH] docs: update context.backgroundPage event examples (#30210) Fixes https://github.com/microsoft/playwright-java/issues/1530 --- docs/src/api/class-browsercontext.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index e4bae85f7d..58205d170a 100644 --- a/docs/src/api/class-browsercontext.md +++ b/docs/src/api/class-browsercontext.md @@ -73,10 +73,9 @@ Only works with Chromium browser's persistent context. Emitted when new background page is created in the context. ```java -Page backgroundPage = context.waitForBackgroundPage(() -> { - page.getByText("activate extension").click(); +context.onBackgroundPage(backgroundPage -> { + System.out.println(backgroundPage.url()); }); -System.out.println(backgroundPage.evaluate("location.href")); ``` ```js @@ -92,11 +91,11 @@ background_page = context.wait_for_event("backgroundpage") ``` ```csharp -var backgroundPage = await context.RunAndWaitForBackgoundPageAsync(async => +context.BackgroundPage += (backgroundPage) => { - await page.GetByText("activate extension").ClickAsync(); -}); -Console.WriteLine(await backgroundPage.EvaluateAsync("location.href")); + Console.WriteLine(backgroundPage.Url()); +}; + ``` ## event: BrowserContext.close