docs: hint that popup main request is accessible through BrowserContext (#30249)

Fixes #30229.
This commit is contained in:
Dmitry Gozman 2024-04-04 09:23:21 -07:00 committed by GitHub
parent 18b51308ff
commit 88f2717e87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 10 deletions

View File

@ -218,7 +218,7 @@ also fire for popup pages. See also [`event: Page.popup`] to receive events abou
The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
done and its response has started loading in the popup.
done and its response has started loading in the popup. If you would like to route/listen to this network request, use [`method: BrowserContext.route`] and [`event: BrowserContext.request`] respectively instead of similar methods on the [Page].
```js
const newPagePromise = context.waitForEvent('page');

View File

@ -448,7 +448,7 @@ Emitted when the page opens a new tab or window. This event is emitted in additi
The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
done and its response has started loading in the popup.
done and its response has started loading in the popup. If you would like to route/listen to this network request, use [`method: BrowserContext.route`] and [`event: BrowserContext.request`] respectively instead of similar methods on the [Page].
```js
// Start waiting for popup before clicking. Note no await.
@ -3411,6 +3411,10 @@ The handler will only be called for the first url if the response is a redirect.
[`method: Page.route`] will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`.
:::
:::note
[`method: Page.route`] will not intercept the first request of a popup page. Use [`method: BrowserContext.route`] instead.
:::
**Usage**
An example of a naive handler that aborts all image requests:

View File

@ -1031,7 +1031,12 @@ export interface Page {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* // Start waiting for popup before clicking. Note no await.
@ -1326,7 +1331,12 @@ export interface Page {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* // Start waiting for popup before clicking. Note no await.
@ -1716,7 +1726,12 @@ export interface Page {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* // Start waiting for popup before clicking. Note no await.
@ -3658,6 +3673,11 @@ export interface Page {
* issue. We recommend disabling Service Workers when using request interception by setting
* `Browser.newContext.serviceWorkers` to `'block'`.
*
* **NOTE** [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route) will not
* intercept the first request of a popup page. Use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* instead.
*
* **Usage**
*
* An example of a naive handler that aborts all image requests:
@ -4504,7 +4524,12 @@ export interface Page {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* // Start waiting for popup before clicking. Note no await.
@ -7745,7 +7770,12 @@ export interface BrowserContext {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* const newPagePromise = context.waitForEvent('page');
@ -7936,7 +7966,12 @@ export interface BrowserContext {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* const newPagePromise = context.waitForEvent('page');
@ -8182,7 +8217,12 @@ export interface BrowserContext {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* const newPagePromise = context.waitForEvent('page');
@ -8827,7 +8867,12 @@ export interface BrowserContext {
*
* The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
* popup with `window.open('http://example.com')`, this event will fire when the network request to
* "http://example.com" is done and its response has started loading in the popup.
* "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen
* to this network request, use
* [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route)
* and
* [browserContext.on('request')](https://playwright.dev/docs/api/class-browsercontext#browser-context-event-request)
* respectively instead of similar methods on the {@link Page}.
*
* ```js
* const newPagePromise = context.waitForEvent('page');