UNPKG

434 kBTypeScriptView Raw
1// This file is generated by /utils/generate_types/index.js
2/**
3 * Copyright (c) Microsoft Corporation.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17import { Protocol } from './protocol';
18import { ChildProcess } from 'child_process';
19import { EventEmitter } from 'events';
20import { Readable } from 'stream';
21import { Serializable, EvaluationArgument, PageFunction, PageFunctionOn, SmartHandle, ElementHandleForTag, BindingSource } from './structs';
22
23type PageWaitForSelectorOptionsNotHidden = PageWaitForSelectorOptions & {
24 state: 'visible'|'attached';
25};
26type ElementHandleWaitForSelectorOptionsNotHidden = ElementHandleWaitForSelectorOptions & {
27 state: 'visible'|'attached';
28};
29
30/**
31 * - extends: [EventEmitter]
32 *
33 * Page provides methods to interact with a single tab in a [Browser], or an
34 * [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One [Browser]
35 * instance might have multiple [Page] instances.
36 *
37 * This example creates a page, navigates it to a URL, and then saves a screenshot:
38 *
39 * ```js
40 * const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
41 *
42 * (async () => {
43 * const browser = await webkit.launch();
44 * const context = await browser.newContext();
45 * const page = await context.newPage();
46 * await page.goto('https://example.com');
47 * await page.screenshot({path: 'screenshot.png'});
48 * await browser.close();
49 * })();
50 * ```
51 *
52 * The Page class emits various events (described below) which can be handled using any of Node's native
53 * [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on`, `once` or
54 * `removeListener`.
55 *
56 * This example logs a message for a single page `load` event:
57 *
58 * ```js
59 * page.once('load', () => console.log('Page loaded!'));
60 * ```
61 *
62 * To unsubscribe from events use the `removeListener` method:
63 *
64 * ```js
65 * function logRequest(interceptedRequest) {
66 * console.log('A request was made:', interceptedRequest.url());
67 * }
68 * page.on('request', logRequest);
69 * // Sometime later...
70 * page.removeListener('request', logRequest);
71 * ```
72 *
73 */
74export interface Page {
75 /**
76 * Returns the value of the `pageFunction` invocation.
77 *
78 * If the function passed to the
79 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg) returns a
80 * [Promise], then
81 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg) would wait
82 * for the promise to resolve and return its value.
83 *
84 * If the function passed to the
85 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg) returns a
86 * non-[Serializable] value, then
87 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg) resolves
88 * to `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: `-0`,
89 * `NaN`, `Infinity`, `-Infinity`.
90 *
91 * Passing argument to `pageFunction`:
92 *
93 * ```js
94 * const result = await page.evaluate(([x, y]) => {
95 * return Promise.resolve(x * y);
96 * }, [7, 8]);
97 * console.log(result); // prints "56"
98 * ```
99 *
100 * A string can also be passed in instead of a function:
101 *
102 * ```js
103 * console.log(await page.evaluate('1 + 2')); // prints "3"
104 * const x = 10;
105 * console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
106 * ```
107 *
108 * [ElementHandle] instances can be passed as an argument to the
109 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg):
110 *
111 * ```js
112 * const bodyHandle = await page.$('body');
113 * const html = await page.evaluate(([body, suffix]) => body.innerHTML + suffix, [bodyHandle, 'hello']);
114 * await bodyHandle.dispose();
115 * ```
116 *
117 * Shortcut for main frame's
118 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg).
119 * @param pageFunction Function to be evaluated in the page context.
120 * @param arg Optional argument to pass to `pageFunction`.
121 */
122 evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<R>;
123 evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<R>;
124
125 /**
126 * Returns the value of the `pageFunction` invocation as a [JSHandle].
127 *
128 * The only difference between
129 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg) and
130 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
131 * is that
132 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
133 * returns [JSHandle].
134 *
135 * If the function passed to the
136 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
137 * returns a [Promise], then
138 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
139 * would wait for the promise to resolve and return its value.
140 *
141 * ```js
142 * const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
143 * aWindowHandle; // Handle for the window object.
144 * ```
145 *
146 * A string can also be passed in instead of a function:
147 *
148 * ```js
149 * const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
150 * ```
151 *
152 * [JSHandle] instances can be passed as an argument to the
153 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg):
154 *
155 * ```js
156 * const aHandle = await page.evaluateHandle(() => document.body);
157 * const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle);
158 * console.log(await resultHandle.jsonValue());
159 * await resultHandle.dispose();
160 * ```
161 *
162 * @param pageFunction Function to be evaluated in the page context.
163 * @param arg Optional argument to pass to `pageFunction`.
164 */
165 evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<SmartHandle<R>>;
166 evaluateHandle<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<SmartHandle<R>>;
167
168 /**
169 * The method finds an element matching the specified selector within the page. If no elements match the selector, the
170 * return value resolves to `null`.
171 *
172 * Shortcut for main frame's [frame.$(selector)](https://playwright.dev/docs/api/class-frame#frameselector).
173 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
174 */
175 $<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K> | null>;
176 $(selector: string): Promise<ElementHandle<SVGElement | HTMLElement> | null>;
177
178 /**
179 * The method finds all elements matching the specified selector within the page. If no elements match the selector, the
180 * return value resolves to `[]`.
181 *
182 * Shortcut for main frame's [frame.$$(selector)](https://playwright.dev/docs/api/class-frame#frameselector).
183 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
184 */
185 $$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
186 $$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
187
188 /**
189 * The method finds an element matching the specified selector within the page and passes it as a first argument to
190 * `pageFunction`. If no elements match the selector, the method throws an error. Returns the value of `pageFunction`.
191 *
192 * If `pageFunction` returns a [Promise], then
193 * [page.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevalselector-pagefunction-arg)
194 * would wait for the promise to resolve and return its value.
195 *
196 * Examples:
197 *
198 * ```js
199 * const searchValue = await page.$eval('#search', el => el.value);
200 * const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
201 * const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
202 * ```
203 *
204 * Shortcut for main frame's
205 * [frame.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevalselector-pagefunction-arg).
206 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
207 * @param pageFunction Function to be evaluated in the page context.
208 * @param arg Optional argument to pass to `pageFunction`.
209 */
210 $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
211 $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
212 $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
213 $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
214
215 /**
216 * The method finds all elements matching the specified selector within the page and passes an array of matched elements as
217 * a first argument to `pageFunction`. Returns the result of `pageFunction` invocation.
218 *
219 * If `pageFunction` returns a [Promise], then
220 * [page.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevalselector-pagefunction-arg)
221 * would wait for the promise to resolve and return its value.
222 *
223 * Examples:
224 *
225 * ```js
226 * const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
227 * ```
228 *
229 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
230 * @param pageFunction Function to be evaluated in the page context.
231 * @param arg Optional argument to pass to `pageFunction`.
232 */
233 $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
234 $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
235 $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
236 $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
237
238 /**
239 * Returns when the `pageFunction` returns a truthy value. It resolves to a JSHandle of the truthy value.
240 *
241 * The
242 * [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#pagewaitforfunctionpagefunction-arg-options)
243 * can be used to observe viewport size change:
244 *
245 * ```js
246 * const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
247 *
248 * (async () => {
249 * const browser = await webkit.launch();
250 * const page = await browser.newPage();
251 * const watchDog = page.waitForFunction(() => window.innerWidth < 100);
252 * await page.setViewportSize({width: 50, height: 50});
253 * await watchDog;
254 * await browser.close();
255 * })();
256 * ```
257 *
258 * To pass an argument to the predicate of
259 * [page.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-page#pagewaitforfunctionpagefunction-arg-options)
260 * function:
261 *
262 * ```js
263 * const selector = '.foo';
264 * await page.waitForFunction(selector => !!document.querySelector(selector), selector);
265 * ```
266 *
267 * Shortcut for main frame's
268 * [frame.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#framewaitforfunctionpagefunction-arg-options).
269 * @param pageFunction Function to be evaluated in the page context.
270 * @param arg Optional argument to pass to `pageFunction`.
271 * @param options
272 */
273 waitForFunction<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
274 waitForFunction<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
275
276 /**
277 * Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
278 * `detached`.
279 *
280 * Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
281 * the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
282 * selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
283 *
284 * This method works across navigations:
285 *
286 * ```js
287 * const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
288 *
289 * (async () => {
290 * const browser = await chromium.launch();
291 * const page = await browser.newPage();
292 * for (let currentURL of ['https://google.com', 'https://bbc.com']) {
293 * await page.goto(currentURL);
294 * const element = await page.waitForSelector('img');
295 * console.log('Loaded image: ' + await element.getAttribute('src'));
296 * }
297 * await browser.close();
298 * })();
299 * ```
300 *
301 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
302 * @param options
303 */
304 waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandleForTag<K>>;
305 waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
306 waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;
307 waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
308
309 /**
310 * The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
311 * executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns
312 * a [Promise], it will be awaited.
313 *
314 * The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
315 * page: Page, frame: Frame }`.
316 *
317 * See
318 * [browserContext.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextexposebindingname-callback-options)
319 * for the context-wide version.
320 *
321 * > NOTE: Functions installed via
322 * [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#pageexposebindingname-callback-options)
323 * survive navigations.
324 *
325 * An example of exposing page URL to all frames in a page:
326 *
327 * ```js
328 * const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
329 *
330 * (async () => {
331 * const browser = await webkit.launch({ headless: false });
332 * const context = await browser.newContext();
333 * const page = await context.newPage();
334 * await page.exposeBinding('pageURL', ({ page }) => page.url());
335 * await page.setContent(`
336 * <script>
337 * async function onClick() {
338 * document.querySelector('div').textContent = await window.pageURL();
339 * }
340 * </script>
341 * <button onclick="onClick()">Click me</button>
342 * <div></div>
343 * `);
344 * await page.click('button');
345 * })();
346 * ```
347 *
348 * An example of passing an element handle:
349 *
350 * ```js
351 * await page.exposeBinding('clicked', async (source, element) => {
352 * console.log(await element.textContent());
353 * }, { handle: true });
354 * await page.setContent(`
355 * <script>
356 * document.addEventListener('click', event => window.clicked(event.target));
357 * </script>
358 * <div>Click me</div>
359 * <div>Or click me</div>
360 * `);
361 * ```
362 *
363 * @param name Name of the function on the window object.
364 * @param callback Callback function that will be called in the Playwright's context.
365 * @param options
366 */
367 exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
368 exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>;
369 /**
370 * Emitted when the page closes.
371 */
372 on(event: 'close', listener: (page: Page) => void): this;
373
374 /**
375 * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
376 * emitted if the page throws an error or a warning.
377 *
378 * The arguments passed into `console.log` appear as arguments on the event handler.
379 *
380 * An example of handling `console` event:
381 *
382 * ```js
383 * page.on('console', msg => {
384 * for (let i = 0; i < msg.args().length; ++i)
385 * console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
386 * });
387 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
388 * ```
389 *
390 */
391 on(event: 'console', listener: (consoleMessage: ConsoleMessage) => void): this;
392
393 /**
394 * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes,
395 * ongoing and subsequent operations will throw.
396 *
397 * The most common way to deal with crashes is to catch an exception:
398 *
399 * ```js
400 * try {
401 * // Crash might happen during a click.
402 * await page.click('button');
403 * // Or while waiting for an event.
404 * await page.waitForEvent('popup');
405 * } catch (e) {
406 * // When the page crashes, exception message contains 'crash'.
407 * }
408 * ```
409 *
410 */
411 on(event: 'crash', listener: (page: Page) => void): this;
412
413 /**
414 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must**
415 * either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
416 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
417 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
418 * actions like click will never finish.
419 *
420 * > NOTE: When no [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listeners are present, all
421 * dialogs are automatically dismissed.
422 */
423 on(event: 'dialog', listener: (dialog: Dialog) => void): this;
424
425 /**
426 * Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded)
427 * event is dispatched.
428 */
429 on(event: 'domcontentloaded', listener: (page: Page) => void): this;
430
431 /**
432 * Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
433 * [Download] instance.
434 *
435 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
436 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
437 * performed and user has no access to the downloaded files.
438 */
439 on(event: 'download', listener: (download: Download) => void): this;
440
441 /**
442 * Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can
443 * respond to it via setting the input files using
444 * [fileChooser.setFiles(files[, options])](https://playwright.dev/docs/api/class-filechooser#filechoosersetfilesfiles-options)
445 * that can be uploaded after that.
446 *
447 * ```js
448 * page.on('filechooser', async (fileChooser) => {
449 * await fileChooser.setFiles('/tmp/myfile.pdf');
450 * });
451 * ```
452 *
453 */
454 on(event: 'filechooser', listener: (fileChooser: FileChooser) => void): this;
455
456 /**
457 * Emitted when a frame is attached.
458 */
459 on(event: 'frameattached', listener: (frame: Frame) => void): this;
460
461 /**
462 * Emitted when a frame is detached.
463 */
464 on(event: 'framedetached', listener: (frame: Frame) => void): this;
465
466 /**
467 * Emitted when a frame is navigated to a new url.
468 */
469 on(event: 'framenavigated', listener: (frame: Frame) => void): this;
470
471 /**
472 * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
473 */
474 on(event: 'load', listener: (page: Page) => void): this;
475
476 /**
477 * Emitted when an uncaught exception happens within the page.
478 */
479 on(event: 'pageerror', listener: (error: Error) => void): this;
480
481 /**
482 * Emitted when the page opens a new tab or window. This event is emitted in addition to the
483 * [browserContext.on('page')](https://playwright.dev/docs/api/class-browsercontext#browsercontextonpage), but only for
484 * popups relevant to this page.
485 *
486 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
487 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
488 * done and its response has started loading in the popup.
489 *
490 * ```js
491 * const [popup] = await Promise.all([
492 * page.waitForEvent('popup'),
493 * page.evaluate(() => window.open('https://example.com')),
494 * ]);
495 * console.log(await popup.evaluate('location.href'));
496 * ```
497 *
498 * > NOTE: Use
499 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
500 * to wait until the page gets to a particular state (you should not need it in most cases).
501 */
502 on(event: 'popup', listener: (page: Page) => void): this;
503
504 /**
505 * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see
506 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
507 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
508 */
509 on(event: 'request', listener: (request: Request) => void): this;
510
511 /**
512 * Emitted when a request fails, for example by timing out.
513 *
514 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
515 * complete with [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) event and
516 * not with [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed).
517 */
518 on(event: 'requestfailed', listener: (request: Request) => void): this;
519
520 /**
521 * Emitted when a request finishes successfully after downloading the response body. For a successful response, the
522 * sequence of events is `request`, `response` and `requestfinished`.
523 */
524 on(event: 'requestfinished', listener: (request: Request) => void): this;
525
526 /**
527 * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
528 * is `request`, `response` and `requestfinished`.
529 */
530 on(event: 'response', listener: (response: Response) => void): this;
531
532 /**
533 * Emitted when [WebSocket] request is sent.
534 */
535 on(event: 'websocket', listener: (webSocket: WebSocket) => void): this;
536
537 /**
538 * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
539 * page.
540 */
541 on(event: 'worker', listener: (worker: Worker) => void): this;
542
543 /**
544 * Emitted when the page closes.
545 */
546 once(event: 'close', listener: (page: Page) => void): this;
547
548 /**
549 * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
550 * emitted if the page throws an error or a warning.
551 *
552 * The arguments passed into `console.log` appear as arguments on the event handler.
553 *
554 * An example of handling `console` event:
555 *
556 * ```js
557 * page.on('console', msg => {
558 * for (let i = 0; i < msg.args().length; ++i)
559 * console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
560 * });
561 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
562 * ```
563 *
564 */
565 once(event: 'console', listener: (consoleMessage: ConsoleMessage) => void): this;
566
567 /**
568 * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes,
569 * ongoing and subsequent operations will throw.
570 *
571 * The most common way to deal with crashes is to catch an exception:
572 *
573 * ```js
574 * try {
575 * // Crash might happen during a click.
576 * await page.click('button');
577 * // Or while waiting for an event.
578 * await page.waitForEvent('popup');
579 * } catch (e) {
580 * // When the page crashes, exception message contains 'crash'.
581 * }
582 * ```
583 *
584 */
585 once(event: 'crash', listener: (page: Page) => void): this;
586
587 /**
588 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must**
589 * either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
590 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
591 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
592 * actions like click will never finish.
593 *
594 * > NOTE: When no [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listeners are present, all
595 * dialogs are automatically dismissed.
596 */
597 once(event: 'dialog', listener: (dialog: Dialog) => void): this;
598
599 /**
600 * Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded)
601 * event is dispatched.
602 */
603 once(event: 'domcontentloaded', listener: (page: Page) => void): this;
604
605 /**
606 * Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
607 * [Download] instance.
608 *
609 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
610 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
611 * performed and user has no access to the downloaded files.
612 */
613 once(event: 'download', listener: (download: Download) => void): this;
614
615 /**
616 * Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can
617 * respond to it via setting the input files using
618 * [fileChooser.setFiles(files[, options])](https://playwright.dev/docs/api/class-filechooser#filechoosersetfilesfiles-options)
619 * that can be uploaded after that.
620 *
621 * ```js
622 * page.on('filechooser', async (fileChooser) => {
623 * await fileChooser.setFiles('/tmp/myfile.pdf');
624 * });
625 * ```
626 *
627 */
628 once(event: 'filechooser', listener: (fileChooser: FileChooser) => void): this;
629
630 /**
631 * Emitted when a frame is attached.
632 */
633 once(event: 'frameattached', listener: (frame: Frame) => void): this;
634
635 /**
636 * Emitted when a frame is detached.
637 */
638 once(event: 'framedetached', listener: (frame: Frame) => void): this;
639
640 /**
641 * Emitted when a frame is navigated to a new url.
642 */
643 once(event: 'framenavigated', listener: (frame: Frame) => void): this;
644
645 /**
646 * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
647 */
648 once(event: 'load', listener: (page: Page) => void): this;
649
650 /**
651 * Emitted when an uncaught exception happens within the page.
652 */
653 once(event: 'pageerror', listener: (error: Error) => void): this;
654
655 /**
656 * Emitted when the page opens a new tab or window. This event is emitted in addition to the
657 * [browserContext.on('page')](https://playwright.dev/docs/api/class-browsercontext#browsercontextonpage), but only for
658 * popups relevant to this page.
659 *
660 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
661 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
662 * done and its response has started loading in the popup.
663 *
664 * ```js
665 * const [popup] = await Promise.all([
666 * page.waitForEvent('popup'),
667 * page.evaluate(() => window.open('https://example.com')),
668 * ]);
669 * console.log(await popup.evaluate('location.href'));
670 * ```
671 *
672 * > NOTE: Use
673 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
674 * to wait until the page gets to a particular state (you should not need it in most cases).
675 */
676 once(event: 'popup', listener: (page: Page) => void): this;
677
678 /**
679 * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see
680 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
681 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
682 */
683 once(event: 'request', listener: (request: Request) => void): this;
684
685 /**
686 * Emitted when a request fails, for example by timing out.
687 *
688 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
689 * complete with [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) event and
690 * not with [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed).
691 */
692 once(event: 'requestfailed', listener: (request: Request) => void): this;
693
694 /**
695 * Emitted when a request finishes successfully after downloading the response body. For a successful response, the
696 * sequence of events is `request`, `response` and `requestfinished`.
697 */
698 once(event: 'requestfinished', listener: (request: Request) => void): this;
699
700 /**
701 * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
702 * is `request`, `response` and `requestfinished`.
703 */
704 once(event: 'response', listener: (response: Response) => void): this;
705
706 /**
707 * Emitted when [WebSocket] request is sent.
708 */
709 once(event: 'websocket', listener: (webSocket: WebSocket) => void): this;
710
711 /**
712 * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
713 * page.
714 */
715 once(event: 'worker', listener: (worker: Worker) => void): this;
716
717 /**
718 * Emitted when the page closes.
719 */
720 addListener(event: 'close', listener: (page: Page) => void): this;
721
722 /**
723 * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
724 * emitted if the page throws an error or a warning.
725 *
726 * The arguments passed into `console.log` appear as arguments on the event handler.
727 *
728 * An example of handling `console` event:
729 *
730 * ```js
731 * page.on('console', msg => {
732 * for (let i = 0; i < msg.args().length; ++i)
733 * console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
734 * });
735 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
736 * ```
737 *
738 */
739 addListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => void): this;
740
741 /**
742 * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes,
743 * ongoing and subsequent operations will throw.
744 *
745 * The most common way to deal with crashes is to catch an exception:
746 *
747 * ```js
748 * try {
749 * // Crash might happen during a click.
750 * await page.click('button');
751 * // Or while waiting for an event.
752 * await page.waitForEvent('popup');
753 * } catch (e) {
754 * // When the page crashes, exception message contains 'crash'.
755 * }
756 * ```
757 *
758 */
759 addListener(event: 'crash', listener: (page: Page) => void): this;
760
761 /**
762 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must**
763 * either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
764 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
765 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
766 * actions like click will never finish.
767 *
768 * > NOTE: When no [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listeners are present, all
769 * dialogs are automatically dismissed.
770 */
771 addListener(event: 'dialog', listener: (dialog: Dialog) => void): this;
772
773 /**
774 * Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded)
775 * event is dispatched.
776 */
777 addListener(event: 'domcontentloaded', listener: (page: Page) => void): this;
778
779 /**
780 * Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
781 * [Download] instance.
782 *
783 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
784 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
785 * performed and user has no access to the downloaded files.
786 */
787 addListener(event: 'download', listener: (download: Download) => void): this;
788
789 /**
790 * Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can
791 * respond to it via setting the input files using
792 * [fileChooser.setFiles(files[, options])](https://playwright.dev/docs/api/class-filechooser#filechoosersetfilesfiles-options)
793 * that can be uploaded after that.
794 *
795 * ```js
796 * page.on('filechooser', async (fileChooser) => {
797 * await fileChooser.setFiles('/tmp/myfile.pdf');
798 * });
799 * ```
800 *
801 */
802 addListener(event: 'filechooser', listener: (fileChooser: FileChooser) => void): this;
803
804 /**
805 * Emitted when a frame is attached.
806 */
807 addListener(event: 'frameattached', listener: (frame: Frame) => void): this;
808
809 /**
810 * Emitted when a frame is detached.
811 */
812 addListener(event: 'framedetached', listener: (frame: Frame) => void): this;
813
814 /**
815 * Emitted when a frame is navigated to a new url.
816 */
817 addListener(event: 'framenavigated', listener: (frame: Frame) => void): this;
818
819 /**
820 * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
821 */
822 addListener(event: 'load', listener: (page: Page) => void): this;
823
824 /**
825 * Emitted when an uncaught exception happens within the page.
826 */
827 addListener(event: 'pageerror', listener: (error: Error) => void): this;
828
829 /**
830 * Emitted when the page opens a new tab or window. This event is emitted in addition to the
831 * [browserContext.on('page')](https://playwright.dev/docs/api/class-browsercontext#browsercontextonpage), but only for
832 * popups relevant to this page.
833 *
834 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
835 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
836 * done and its response has started loading in the popup.
837 *
838 * ```js
839 * const [popup] = await Promise.all([
840 * page.waitForEvent('popup'),
841 * page.evaluate(() => window.open('https://example.com')),
842 * ]);
843 * console.log(await popup.evaluate('location.href'));
844 * ```
845 *
846 * > NOTE: Use
847 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
848 * to wait until the page gets to a particular state (you should not need it in most cases).
849 */
850 addListener(event: 'popup', listener: (page: Page) => void): this;
851
852 /**
853 * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see
854 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
855 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
856 */
857 addListener(event: 'request', listener: (request: Request) => void): this;
858
859 /**
860 * Emitted when a request fails, for example by timing out.
861 *
862 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
863 * complete with [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) event and
864 * not with [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed).
865 */
866 addListener(event: 'requestfailed', listener: (request: Request) => void): this;
867
868 /**
869 * Emitted when a request finishes successfully after downloading the response body. For a successful response, the
870 * sequence of events is `request`, `response` and `requestfinished`.
871 */
872 addListener(event: 'requestfinished', listener: (request: Request) => void): this;
873
874 /**
875 * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
876 * is `request`, `response` and `requestfinished`.
877 */
878 addListener(event: 'response', listener: (response: Response) => void): this;
879
880 /**
881 * Emitted when [WebSocket] request is sent.
882 */
883 addListener(event: 'websocket', listener: (webSocket: WebSocket) => void): this;
884
885 /**
886 * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
887 * page.
888 */
889 addListener(event: 'worker', listener: (worker: Worker) => void): this;
890
891 /**
892 * Emitted when the page closes.
893 */
894 removeListener(event: 'close', listener: (page: Page) => void): this;
895
896 /**
897 * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
898 * emitted if the page throws an error or a warning.
899 *
900 * The arguments passed into `console.log` appear as arguments on the event handler.
901 *
902 * An example of handling `console` event:
903 *
904 * ```js
905 * page.on('console', msg => {
906 * for (let i = 0; i < msg.args().length; ++i)
907 * console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
908 * });
909 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
910 * ```
911 *
912 */
913 removeListener(event: 'console', listener: (consoleMessage: ConsoleMessage) => void): this;
914
915 /**
916 * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes,
917 * ongoing and subsequent operations will throw.
918 *
919 * The most common way to deal with crashes is to catch an exception:
920 *
921 * ```js
922 * try {
923 * // Crash might happen during a click.
924 * await page.click('button');
925 * // Or while waiting for an event.
926 * await page.waitForEvent('popup');
927 * } catch (e) {
928 * // When the page crashes, exception message contains 'crash'.
929 * }
930 * ```
931 *
932 */
933 removeListener(event: 'crash', listener: (page: Page) => void): this;
934
935 /**
936 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must**
937 * either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
938 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
939 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
940 * actions like click will never finish.
941 *
942 * > NOTE: When no [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listeners are present, all
943 * dialogs are automatically dismissed.
944 */
945 removeListener(event: 'dialog', listener: (dialog: Dialog) => void): this;
946
947 /**
948 * Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded)
949 * event is dispatched.
950 */
951 removeListener(event: 'domcontentloaded', listener: (page: Page) => void): this;
952
953 /**
954 * Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
955 * [Download] instance.
956 *
957 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
958 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
959 * performed and user has no access to the downloaded files.
960 */
961 removeListener(event: 'download', listener: (download: Download) => void): this;
962
963 /**
964 * Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can
965 * respond to it via setting the input files using
966 * [fileChooser.setFiles(files[, options])](https://playwright.dev/docs/api/class-filechooser#filechoosersetfilesfiles-options)
967 * that can be uploaded after that.
968 *
969 * ```js
970 * page.on('filechooser', async (fileChooser) => {
971 * await fileChooser.setFiles('/tmp/myfile.pdf');
972 * });
973 * ```
974 *
975 */
976 removeListener(event: 'filechooser', listener: (fileChooser: FileChooser) => void): this;
977
978 /**
979 * Emitted when a frame is attached.
980 */
981 removeListener(event: 'frameattached', listener: (frame: Frame) => void): this;
982
983 /**
984 * Emitted when a frame is detached.
985 */
986 removeListener(event: 'framedetached', listener: (frame: Frame) => void): this;
987
988 /**
989 * Emitted when a frame is navigated to a new url.
990 */
991 removeListener(event: 'framenavigated', listener: (frame: Frame) => void): this;
992
993 /**
994 * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
995 */
996 removeListener(event: 'load', listener: (page: Page) => void): this;
997
998 /**
999 * Emitted when an uncaught exception happens within the page.
1000 */
1001 removeListener(event: 'pageerror', listener: (error: Error) => void): this;
1002
1003 /**
1004 * Emitted when the page opens a new tab or window. This event is emitted in addition to the
1005 * [browserContext.on('page')](https://playwright.dev/docs/api/class-browsercontext#browsercontextonpage), but only for
1006 * popups relevant to this page.
1007 *
1008 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
1009 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
1010 * done and its response has started loading in the popup.
1011 *
1012 * ```js
1013 * const [popup] = await Promise.all([
1014 * page.waitForEvent('popup'),
1015 * page.evaluate(() => window.open('https://example.com')),
1016 * ]);
1017 * console.log(await popup.evaluate('location.href'));
1018 * ```
1019 *
1020 * > NOTE: Use
1021 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
1022 * to wait until the page gets to a particular state (you should not need it in most cases).
1023 */
1024 removeListener(event: 'popup', listener: (page: Page) => void): this;
1025
1026 /**
1027 * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see
1028 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
1029 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
1030 */
1031 removeListener(event: 'request', listener: (request: Request) => void): this;
1032
1033 /**
1034 * Emitted when a request fails, for example by timing out.
1035 *
1036 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
1037 * complete with [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) event and
1038 * not with [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed).
1039 */
1040 removeListener(event: 'requestfailed', listener: (request: Request) => void): this;
1041
1042 /**
1043 * Emitted when a request finishes successfully after downloading the response body. For a successful response, the
1044 * sequence of events is `request`, `response` and `requestfinished`.
1045 */
1046 removeListener(event: 'requestfinished', listener: (request: Request) => void): this;
1047
1048 /**
1049 * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
1050 * is `request`, `response` and `requestfinished`.
1051 */
1052 removeListener(event: 'response', listener: (response: Response) => void): this;
1053
1054 /**
1055 * Emitted when [WebSocket] request is sent.
1056 */
1057 removeListener(event: 'websocket', listener: (webSocket: WebSocket) => void): this;
1058
1059 /**
1060 * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
1061 * page.
1062 */
1063 removeListener(event: 'worker', listener: (worker: Worker) => void): this;
1064
1065 /**
1066 * Emitted when the page closes.
1067 */
1068 off(event: 'close', listener: (page: Page) => void): this;
1069
1070 /**
1071 * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
1072 * emitted if the page throws an error or a warning.
1073 *
1074 * The arguments passed into `console.log` appear as arguments on the event handler.
1075 *
1076 * An example of handling `console` event:
1077 *
1078 * ```js
1079 * page.on('console', msg => {
1080 * for (let i = 0; i < msg.args().length; ++i)
1081 * console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
1082 * });
1083 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
1084 * ```
1085 *
1086 */
1087 off(event: 'console', listener: (consoleMessage: ConsoleMessage) => void): this;
1088
1089 /**
1090 * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes,
1091 * ongoing and subsequent operations will throw.
1092 *
1093 * The most common way to deal with crashes is to catch an exception:
1094 *
1095 * ```js
1096 * try {
1097 * // Crash might happen during a click.
1098 * await page.click('button');
1099 * // Or while waiting for an event.
1100 * await page.waitForEvent('popup');
1101 * } catch (e) {
1102 * // When the page crashes, exception message contains 'crash'.
1103 * }
1104 * ```
1105 *
1106 */
1107 off(event: 'crash', listener: (page: Page) => void): this;
1108
1109 /**
1110 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must**
1111 * either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
1112 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
1113 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
1114 * actions like click will never finish.
1115 *
1116 * > NOTE: When no [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listeners are present, all
1117 * dialogs are automatically dismissed.
1118 */
1119 off(event: 'dialog', listener: (dialog: Dialog) => void): this;
1120
1121 /**
1122 * Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded)
1123 * event is dispatched.
1124 */
1125 off(event: 'domcontentloaded', listener: (page: Page) => void): this;
1126
1127 /**
1128 * Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
1129 * [Download] instance.
1130 *
1131 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
1132 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
1133 * performed and user has no access to the downloaded files.
1134 */
1135 off(event: 'download', listener: (download: Download) => void): this;
1136
1137 /**
1138 * Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can
1139 * respond to it via setting the input files using
1140 * [fileChooser.setFiles(files[, options])](https://playwright.dev/docs/api/class-filechooser#filechoosersetfilesfiles-options)
1141 * that can be uploaded after that.
1142 *
1143 * ```js
1144 * page.on('filechooser', async (fileChooser) => {
1145 * await fileChooser.setFiles('/tmp/myfile.pdf');
1146 * });
1147 * ```
1148 *
1149 */
1150 off(event: 'filechooser', listener: (fileChooser: FileChooser) => void): this;
1151
1152 /**
1153 * Emitted when a frame is attached.
1154 */
1155 off(event: 'frameattached', listener: (frame: Frame) => void): this;
1156
1157 /**
1158 * Emitted when a frame is detached.
1159 */
1160 off(event: 'framedetached', listener: (frame: Frame) => void): this;
1161
1162 /**
1163 * Emitted when a frame is navigated to a new url.
1164 */
1165 off(event: 'framenavigated', listener: (frame: Frame) => void): this;
1166
1167 /**
1168 * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
1169 */
1170 off(event: 'load', listener: (page: Page) => void): this;
1171
1172 /**
1173 * Emitted when an uncaught exception happens within the page.
1174 */
1175 off(event: 'pageerror', listener: (error: Error) => void): this;
1176
1177 /**
1178 * Emitted when the page opens a new tab or window. This event is emitted in addition to the
1179 * [browserContext.on('page')](https://playwright.dev/docs/api/class-browsercontext#browsercontextonpage), but only for
1180 * popups relevant to this page.
1181 *
1182 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
1183 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
1184 * done and its response has started loading in the popup.
1185 *
1186 * ```js
1187 * const [popup] = await Promise.all([
1188 * page.waitForEvent('popup'),
1189 * page.evaluate(() => window.open('https://example.com')),
1190 * ]);
1191 * console.log(await popup.evaluate('location.href'));
1192 * ```
1193 *
1194 * > NOTE: Use
1195 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
1196 * to wait until the page gets to a particular state (you should not need it in most cases).
1197 */
1198 off(event: 'popup', listener: (page: Page) => void): this;
1199
1200 /**
1201 * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see
1202 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
1203 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
1204 */
1205 off(event: 'request', listener: (request: Request) => void): this;
1206
1207 /**
1208 * Emitted when a request fails, for example by timing out.
1209 *
1210 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
1211 * complete with [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) event and
1212 * not with [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed).
1213 */
1214 off(event: 'requestfailed', listener: (request: Request) => void): this;
1215
1216 /**
1217 * Emitted when a request finishes successfully after downloading the response body. For a successful response, the
1218 * sequence of events is `request`, `response` and `requestfinished`.
1219 */
1220 off(event: 'requestfinished', listener: (request: Request) => void): this;
1221
1222 /**
1223 * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
1224 * is `request`, `response` and `requestfinished`.
1225 */
1226 off(event: 'response', listener: (response: Response) => void): this;
1227
1228 /**
1229 * Emitted when [WebSocket] request is sent.
1230 */
1231 off(event: 'websocket', listener: (webSocket: WebSocket) => void): this;
1232
1233 /**
1234 * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
1235 * page.
1236 */
1237 off(event: 'worker', listener: (worker: Worker) => void): this;
1238
1239 accessibility: Accessibility;
1240
1241 /**
1242 * Adds a script which would be evaluated in one of the following scenarios:
1243 * - Whenever the page is navigated.
1244 * - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly
1245 * attached frame.
1246 *
1247 * The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
1248 * the JavaScript environment, e.g. to seed `Math.random`.
1249 *
1250 * An example of overriding `Math.random` before the page loads:
1251 *
1252 * ```js browser
1253 * // preload.js
1254 * Math.random = () => 42;
1255 * ```
1256 *
1257 * ```js
1258 * // In your playwright script, assuming the preload.js file is in same directory
1259 * await page.addInitScript({ path: './preload.js' });
1260 * ```
1261 *
1262 * > NOTE: The order of evaluation of multiple scripts installed via
1263 * [browserContext.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-browsercontext#browsercontextaddinitscriptscript-arg)
1264 * and [page.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-page#pageaddinitscriptscript-arg) is not
1265 * defined.
1266 * @param script Script to be evaluated in the page.
1267 * @param arg Optional argument to pass to `script` (only supported when passing a function).
1268 */
1269 addInitScript(script: Function|string|{
1270 /**
1271 * Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working
1272 * directory. Optional.
1273 */
1274 path?: string;
1275
1276 /**
1277 * Raw script content. Optional.
1278 */
1279 content?: string;
1280 }, arg?: Serializable): Promise<void>;
1281
1282 /**
1283 * Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
1284 * fires or when the script content was injected into frame.
1285 *
1286 * Shortcut for main frame's
1287 * [frame.addScriptTag([options])](https://playwright.dev/docs/api/class-frame#frameaddscripttagoptions).
1288 * @param options
1289 */
1290 addScriptTag(options?: {
1291 /**
1292 * Raw JavaScript content to be injected into frame.
1293 */
1294 content?: string;
1295
1296 /**
1297 * Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
1298 * current working directory.
1299 */
1300 path?: string;
1301
1302 /**
1303 * Script type. Use 'module' in order to load a Javascript ES6 module. See
1304 * [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details.
1305 */
1306 type?: string;
1307
1308 /**
1309 * URL of a script to be added.
1310 */
1311 url?: string;
1312 }): Promise<ElementHandle>;
1313
1314 /**
1315 * Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
1316 * content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
1317 *
1318 * Shortcut for main frame's
1319 * [frame.addStyleTag([options])](https://playwright.dev/docs/api/class-frame#frameaddstyletagoptions).
1320 * @param options
1321 */
1322 addStyleTag(options?: {
1323 /**
1324 * Raw CSS content to be injected into frame.
1325 */
1326 content?: string;
1327
1328 /**
1329 * Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
1330 * current working directory.
1331 */
1332 path?: string;
1333
1334 /**
1335 * URL of the `<link>` tag.
1336 */
1337 url?: string;
1338 }): Promise<ElementHandle>;
1339
1340 /**
1341 * Brings page to front (activates tab).
1342 */
1343 bringToFront(): Promise<void>;
1344
1345 /**
1346 * This method checks an element matching `selector` by performing the following steps:
1347 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1348 * 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
1349 * checked, this method returns immediately.
1350 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
1351 * element is detached during the checks, the whole action is retried.
1352 * 1. Scroll the element into view if needed.
1353 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element.
1354 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1355 * 1. Ensure that the element is now checked. If not, this method rejects.
1356 *
1357 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
1358 * Passing zero timeout disables this.
1359 *
1360 * Shortcut for main frame's
1361 * [frame.check(selector[, options])](https://playwright.dev/docs/api/class-frame#framecheckselector-options).
1362 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1363 * @param options
1364 */
1365 check(selector: string, options?: {
1366 /**
1367 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
1368 */
1369 force?: boolean;
1370
1371 /**
1372 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
1373 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
1374 * inaccessible pages. Defaults to `false`.
1375 */
1376 noWaitAfter?: boolean;
1377
1378 /**
1379 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1380 * using the
1381 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1382 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1383 */
1384 timeout?: number;
1385 }): Promise<void>;
1386
1387 /**
1388 * This method clicks an element matching `selector` by performing the following steps:
1389 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1390 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
1391 * element is detached during the checks, the whole action is retried.
1392 * 1. Scroll the element into view if needed.
1393 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element, or
1394 * the specified `position`.
1395 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1396 *
1397 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
1398 * Passing zero timeout disables this.
1399 *
1400 * Shortcut for main frame's
1401 * [frame.click(selector[, options])](https://playwright.dev/docs/api/class-frame#frameclickselector-options).
1402 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1403 * @param options
1404 */
1405 click(selector: string, options?: {
1406 /**
1407 * Defaults to `left`.
1408 */
1409 button?: "left"|"right"|"middle";
1410
1411 /**
1412 * defaults to 1. See [UIEvent.detail].
1413 */
1414 clickCount?: number;
1415
1416 /**
1417 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
1418 */
1419 delay?: number;
1420
1421 /**
1422 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
1423 */
1424 force?: boolean;
1425
1426 /**
1427 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
1428 * modifiers back. If not specified, currently pressed modifiers are used.
1429 */
1430 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
1431
1432 /**
1433 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
1434 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
1435 * inaccessible pages. Defaults to `false`.
1436 */
1437 noWaitAfter?: boolean;
1438
1439 /**
1440 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
1441 * element.
1442 */
1443 position?: {
1444 x: number;
1445
1446 y: number;
1447 };
1448
1449 /**
1450 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1451 * using the
1452 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1453 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1454 */
1455 timeout?: number;
1456 }): Promise<void>;
1457
1458 /**
1459 * If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
1460 * `runBeforeUnload` is `true` the method will run unload handlers, but will **not** wait for the page to close.
1461 *
1462 * By default, `page.close()` **does not** run `beforeunload` handlers.
1463 *
1464 * > NOTE: if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled manually
1465 * via [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) event.
1466 * @param options
1467 */
1468 close(options?: {
1469 /**
1470 * Defaults to `false`. Whether to run the
1471 * [before unload](https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload) page handlers.
1472 */
1473 runBeforeUnload?: boolean;
1474 }): Promise<void>;
1475
1476 /**
1477 * Gets the full HTML contents of the page, including the doctype.
1478 */
1479 content(): Promise<string>;
1480
1481 /**
1482 * Get the browser context that the page belongs to.
1483 */
1484 context(): BrowserContext;
1485
1486 /**
1487 * Browser-specific Coverage implementation, only available for Chromium atm. See
1488 * [ChromiumCoverage](#class-chromiumcoverage) for more details.
1489 */
1490 coverage: null|ChromiumCoverage;
1491
1492 /**
1493 * This method double clicks an element matching `selector` by performing the following steps:
1494 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1495 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
1496 * element is detached during the checks, the whole action is retried.
1497 * 1. Scroll the element into view if needed.
1498 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to double click in the center of the
1499 * element, or the specified `position`.
1500 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
1501 * first click of the `dblclick()` triggers a navigation event, this method will reject.
1502 *
1503 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
1504 * Passing zero timeout disables this.
1505 *
1506 * > NOTE: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
1507 *
1508 * Shortcut for main frame's
1509 * [frame.dblclick(selector[, options])](https://playwright.dev/docs/api/class-frame#framedblclickselector-options).
1510 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1511 * @param options
1512 */
1513 dblclick(selector: string, options?: {
1514 /**
1515 * Defaults to `left`.
1516 */
1517 button?: "left"|"right"|"middle";
1518
1519 /**
1520 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
1521 */
1522 delay?: number;
1523
1524 /**
1525 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
1526 */
1527 force?: boolean;
1528
1529 /**
1530 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
1531 * modifiers back. If not specified, currently pressed modifiers are used.
1532 */
1533 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
1534
1535 /**
1536 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
1537 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
1538 * inaccessible pages. Defaults to `false`.
1539 */
1540 noWaitAfter?: boolean;
1541
1542 /**
1543 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
1544 * element.
1545 */
1546 position?: {
1547 x: number;
1548
1549 y: number;
1550 };
1551
1552 /**
1553 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1554 * using the
1555 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1556 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1557 */
1558 timeout?: number;
1559 }): Promise<void>;
1560
1561 /**
1562 * The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
1563 * is dispatched. This is equivalend to calling
1564 * [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
1565 *
1566 * ```js
1567 * await page.dispatchEvent('button#submit', 'click');
1568 * ```
1569 *
1570 * Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
1571 * and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
1572 *
1573 * Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
1574 * - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
1575 * - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
1576 * - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
1577 * - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
1578 * - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
1579 * - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
1580 * - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
1581 *
1582 * You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
1583 *
1584 * ```js
1585 * // Note you can only create DataTransfer in Chromium and Firefox
1586 * const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
1587 * await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
1588 * ```
1589 *
1590 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1591 * @param type DOM event type: `"click"`, `"dragstart"`, etc.
1592 * @param eventInit Optional event-specific initialization properties.
1593 * @param options
1594 */
1595 dispatchEvent(selector: string, type: string, eventInit?: EvaluationArgument, options?: {
1596 /**
1597 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1598 * using the
1599 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1600 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1601 */
1602 timeout?: number;
1603 }): Promise<void>;
1604
1605 /**
1606 * ```js
1607 * await page.evaluate(() => matchMedia('screen').matches);
1608 * // → true
1609 * await page.evaluate(() => matchMedia('print').matches);
1610 * // → false
1611 *
1612 * await page.emulateMedia({ media: 'print' });
1613 * await page.evaluate(() => matchMedia('screen').matches);
1614 * // → false
1615 * await page.evaluate(() => matchMedia('print').matches);
1616 * // → true
1617 *
1618 * await page.emulateMedia({});
1619 * await page.evaluate(() => matchMedia('screen').matches);
1620 * // → true
1621 * await page.evaluate(() => matchMedia('print').matches);
1622 * // → false
1623 * ```
1624 *
1625 * ```js
1626 * await page.emulateMedia({ colorScheme: 'dark' });
1627 * await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
1628 * // → true
1629 * await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
1630 * // → false
1631 * await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches);
1632 * // → false
1633 * ```
1634 *
1635 * @param options
1636 */
1637 emulateMedia(options?: {
1638 /**
1639 * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
1640 * `null` disables color scheme emulation.
1641 */
1642 colorScheme?: null|"light"|"dark"|"no-preference";
1643
1644 /**
1645 * Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null`
1646 * disables CSS media emulation.
1647 */
1648 media?: null|"screen"|"print";
1649 }): Promise<void>;
1650
1651 /**
1652 * The method adds a function called `name` on the `window` object of every frame in the page. When called, the function
1653 * executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
1654 *
1655 * If the `callback` returns a [Promise], it will be awaited.
1656 *
1657 * See
1658 * [browserContext.exposeFunction(name, callback)](https://playwright.dev/docs/api/class-browsercontext#browsercontextexposefunctionname-callback)
1659 * for context-wide exposed function.
1660 *
1661 * > NOTE: Functions installed via
1662 * [page.exposeFunction(name, callback)](https://playwright.dev/docs/api/class-page#pageexposefunctionname-callback)
1663 * survive navigations.
1664 *
1665 * An example of adding an `sha1` function to the page:
1666 *
1667 * ```js
1668 * const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
1669 * const crypto = require('crypto');
1670 *
1671 * (async () => {
1672 * const browser = await webkit.launch({ headless: false });
1673 * const page = await browser.newPage();
1674 * await page.exposeFunction('sha1', text => crypto.createHash('sha1').update(text).digest('hex'));
1675 * await page.setContent(`
1676 * <script>
1677 * async function onClick() {
1678 * document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
1679 * }
1680 * </script>
1681 * <button onclick="onClick()">Click me</button>
1682 * <div></div>
1683 * `);
1684 * await page.click('button');
1685 * })();
1686 * ```
1687 *
1688 * @param name Name of the function on the window object
1689 * @param callback Callback function which will be called in Playwright's context.
1690 */
1691 exposeFunction(name: string, callback: Function): Promise<void>;
1692
1693 /**
1694 * This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/docs/actionability) checks, focuses the
1695 * element, fills it and triggers an `input` event after filling. If the element is inside the `<label>` element that has
1696 * associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), that control will be
1697 * filled instead. If the element to be filled is not an `<input>`, `<textarea>` or `[contenteditable]` element, this
1698 * method throws an error. Note that you can pass an empty string to clear the input field.
1699 *
1700 * To send fine-grained keyboard events, use
1701 * [page.type(selector, text[, options])](https://playwright.dev/docs/api/class-page#pagetypeselector-text-options).
1702 *
1703 * Shortcut for main frame's
1704 * [frame.fill(selector, value[, options])](https://playwright.dev/docs/api/class-frame#framefillselector-value-options)
1705 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1706 * @param value Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element.
1707 * @param options
1708 */
1709 fill(selector: string, value: string, options?: {
1710 /**
1711 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
1712 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
1713 * inaccessible pages. Defaults to `false`.
1714 */
1715 noWaitAfter?: boolean;
1716
1717 /**
1718 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1719 * using the
1720 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1721 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1722 */
1723 timeout?: number;
1724 }): Promise<void>;
1725
1726 /**
1727 * This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
1728 * waits until a matching element appears in the DOM.
1729 *
1730 * Shortcut for main frame's
1731 * [frame.focus(selector[, options])](https://playwright.dev/docs/api/class-frame#framefocusselector-options).
1732 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1733 * @param options
1734 */
1735 focus(selector: string, options?: {
1736 /**
1737 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1738 * using the
1739 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1740 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1741 */
1742 timeout?: number;
1743 }): Promise<void>;
1744
1745 /**
1746 * Returns frame matching the specified criteria. Either `name` or `url` must be specified.
1747 *
1748 * ```js
1749 * const frame = page.frame('frame-name');
1750 * ```
1751 *
1752 * ```js
1753 * const frame = page.frame({ url: /.*domain.*\/ });
1754 * ```
1755 *
1756 * @param frameSelector Frame name or other frame lookup options.
1757 */
1758 frame(frameSelector: string|{
1759 /**
1760 * Frame name specified in the `iframe`'s `name` attribute. Optional.
1761 */
1762 name?: string;
1763
1764 /**
1765 * A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional.
1766 */
1767 url?: string|RegExp|((url: URL) => boolean);
1768 }): null|Frame;
1769
1770 /**
1771 * An array of all frames attached to the page.
1772 */
1773 frames(): Array<Frame>;
1774
1775 /**
1776 * Returns element attribute value.
1777 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1778 * @param name Attribute name to get the value for.
1779 * @param options
1780 */
1781 getAttribute(selector: string, name: string, options?: {
1782 /**
1783 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1784 * using the
1785 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1786 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1787 */
1788 timeout?: number;
1789 }): Promise<null|string>;
1790
1791 /**
1792 * Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1793 * last redirect. If can not go back, returns `null`.
1794 *
1795 * Navigate to the previous page in history.
1796 * @param options
1797 */
1798 goBack(options?: {
1799 /**
1800 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
1801 * changed by using the
1802 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
1803 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
1804 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
1805 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1806 */
1807 timeout?: number;
1808
1809 /**
1810 * When to consider operation succeeded, defaults to `load`. Events can be either:
1811 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
1812 * - `'load'` - consider operation to be finished when the `load` event is fired.
1813 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
1814 */
1815 waitUntil?: "load"|"domcontentloaded"|"networkidle";
1816 }): Promise<null|Response>;
1817
1818 /**
1819 * Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1820 * last redirect. If can not go forward, returns `null`.
1821 *
1822 * Navigate to the next page in history.
1823 * @param options
1824 */
1825 goForward(options?: {
1826 /**
1827 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
1828 * changed by using the
1829 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
1830 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
1831 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
1832 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1833 */
1834 timeout?: number;
1835
1836 /**
1837 * When to consider operation succeeded, defaults to `load`. Events can be either:
1838 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
1839 * - `'load'` - consider operation to be finished when the `load` event is fired.
1840 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
1841 */
1842 waitUntil?: "load"|"domcontentloaded"|"networkidle";
1843 }): Promise<null|Response>;
1844
1845 /**
1846 * Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1847 * last redirect.
1848 *
1849 * `page.goto` will throw an error if:
1850 * - there's an SSL error (e.g. in case of self-signed certificates).
1851 * - target URL is invalid.
1852 * - the `timeout` is exceeded during navigation.
1853 * - the remote server does not respond or is unreachable.
1854 * - the main resource failed to load.
1855 *
1856 * `page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
1857 * Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
1858 * [response.status()](https://playwright.dev/docs/api/class-response#responsestatus).
1859 *
1860 * > NOTE: `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
1861 * `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
1862 * > NOTE: Headless mode doesn't support navigation to a PDF document. See the
1863 * [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
1864 *
1865 * Shortcut for main frame's [frame.goto(url[, options])](https://playwright.dev/docs/api/class-frame#framegotourl-options)
1866 * @param url URL to navigate page to. The url should include scheme, e.g. `https://`.
1867 * @param options
1868 */
1869 goto(url: string, options?: {
1870 /**
1871 * Referer header value. If provided it will take preference over the referer header value set by
1872 * [page.setExtraHTTPHeaders(headers)](https://playwright.dev/docs/api/class-page#pagesetextrahttpheadersheaders).
1873 */
1874 referer?: string;
1875
1876 /**
1877 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
1878 * changed by using the
1879 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
1880 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
1881 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
1882 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1883 */
1884 timeout?: number;
1885
1886 /**
1887 * When to consider operation succeeded, defaults to `load`. Events can be either:
1888 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
1889 * - `'load'` - consider operation to be finished when the `load` event is fired.
1890 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
1891 */
1892 waitUntil?: "load"|"domcontentloaded"|"networkidle";
1893 }): Promise<null|Response>;
1894
1895 /**
1896 * This method hovers over an element matching `selector` by performing the following steps:
1897 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1898 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
1899 * element is detached during the checks, the whole action is retried.
1900 * 1. Scroll the element into view if needed.
1901 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to hover over the center of the element, or
1902 * the specified `position`.
1903 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1904 *
1905 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
1906 * Passing zero timeout disables this.
1907 *
1908 * Shortcut for main frame's
1909 * [frame.hover(selector[, options])](https://playwright.dev/docs/api/class-frame#framehoverselector-options).
1910 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1911 * @param options
1912 */
1913 hover(selector: string, options?: {
1914 /**
1915 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
1916 */
1917 force?: boolean;
1918
1919 /**
1920 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
1921 * modifiers back. If not specified, currently pressed modifiers are used.
1922 */
1923 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
1924
1925 /**
1926 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
1927 * element.
1928 */
1929 position?: {
1930 x: number;
1931
1932 y: number;
1933 };
1934
1935 /**
1936 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1937 * using the
1938 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1939 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1940 */
1941 timeout?: number;
1942 }): Promise<void>;
1943
1944 /**
1945 * Returns `element.innerHTML`.
1946 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1947 * @param options
1948 */
1949 innerHTML(selector: string, options?: {
1950 /**
1951 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1952 * using the
1953 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1954 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1955 */
1956 timeout?: number;
1957 }): Promise<string>;
1958
1959 /**
1960 * Returns `element.innerText`.
1961 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1962 * @param options
1963 */
1964 innerText(selector: string, options?: {
1965 /**
1966 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1967 * using the
1968 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1969 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1970 */
1971 timeout?: number;
1972 }): Promise<string>;
1973
1974 /**
1975 * Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
1976 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1977 * @param options
1978 */
1979 isChecked(selector: string, options?: {
1980 /**
1981 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
1982 * using the
1983 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
1984 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
1985 */
1986 timeout?: number;
1987 }): Promise<boolean>;
1988
1989 /**
1990 * Indicates that the page has been closed.
1991 */
1992 isClosed(): boolean;
1993
1994 /**
1995 * Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/docs/actionability#enabled).
1996 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
1997 * @param options
1998 */
1999 isDisabled(selector: string, options?: {
2000 /**
2001 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2002 * using the
2003 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2004 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2005 */
2006 timeout?: number;
2007 }): Promise<boolean>;
2008
2009 /**
2010 * Returns whether the element is [editable](https://playwright.dev/docs/actionability#editable).
2011 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2012 * @param options
2013 */
2014 isEditable(selector: string, options?: {
2015 /**
2016 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2017 * using the
2018 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2019 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2020 */
2021 timeout?: number;
2022 }): Promise<boolean>;
2023
2024 /**
2025 * Returns whether the element is [enabled](https://playwright.dev/docs/actionability#enabled).
2026 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2027 * @param options
2028 */
2029 isEnabled(selector: string, options?: {
2030 /**
2031 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2032 * using the
2033 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2034 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2035 */
2036 timeout?: number;
2037 }): Promise<boolean>;
2038
2039 /**
2040 * Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
2041 * match any elements is considered hidden.
2042 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2043 * @param options
2044 */
2045 isHidden(selector: string, options?: {
2046 /**
2047 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2048 * using the
2049 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2050 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2051 */
2052 timeout?: number;
2053 }): Promise<boolean>;
2054
2055 /**
2056 * Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
2057 * considered not visible.
2058 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2059 * @param options
2060 */
2061 isVisible(selector: string, options?: {
2062 /**
2063 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2064 * using the
2065 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2066 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2067 */
2068 timeout?: number;
2069 }): Promise<boolean>;
2070
2071 keyboard: Keyboard;
2072
2073 /**
2074 * The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
2075 */
2076 mainFrame(): Frame;
2077
2078 mouse: Mouse;
2079
2080 /**
2081 * Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
2082 */
2083 opener(): Promise<null|Page>;
2084
2085 /**
2086 * Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' button
2087 * in the page overlay or to call `playwright.resume()` in the DevTools console.
2088 *
2089 * User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
2090 * the place it was paused.
2091 *
2092 * > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the
2093 * [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchoptions).
2094 */
2095 pause(): Promise<void>;
2096
2097 /**
2098 * Returns the PDF buffer.
2099 *
2100 * > NOTE: Generating a pdf is currently only supported in Chromium headless.
2101 *
2102 * `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
2103 * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) before calling
2104 * `page.pdf()`:
2105 *
2106 * > NOTE: By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
2107 * [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
2108 * force rendering of exact colors.
2109 *
2110 * ```js
2111 * // Generates a PDF with 'screen' media type.
2112 * await page.emulateMedia({media: 'screen'});
2113 * await page.pdf({path: 'page.pdf'});
2114 * ```
2115 *
2116 * The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled values are treated as pixels.
2117 *
2118 * A few examples:
2119 * - `page.pdf({width: 100})` - prints with width set to 100 pixels
2120 * - `page.pdf({width: '100px'})` - prints with width set to 100 pixels
2121 * - `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
2122 *
2123 * All possible units are:
2124 * - `px` - pixel
2125 * - `in` - inch
2126 * - `cm` - centimeter
2127 * - `mm` - millimeter
2128 *
2129 * The `format` options are:
2130 * - `Letter`: 8.5in x 11in
2131 * - `Legal`: 8.5in x 14in
2132 * - `Tabloid`: 11in x 17in
2133 * - `Ledger`: 17in x 11in
2134 * - `A0`: 33.1in x 46.8in
2135 * - `A1`: 23.4in x 33.1in
2136 * - `A2`: 16.54in x 23.4in
2137 * - `A3`: 11.7in x 16.54in
2138 * - `A4`: 8.27in x 11.7in
2139 * - `A5`: 5.83in x 8.27in
2140 * - `A6`: 4.13in x 5.83in
2141 *
2142 * > NOTE: `headerTemplate` and `footerTemplate` markup have the following limitations: > 1. Script tags inside templates
2143 * are not evaluated. > 2. Page styles are not visible inside templates.
2144 * @param options
2145 */
2146 pdf(options?: {
2147 /**
2148 * Display header and footer. Defaults to `false`.
2149 */
2150 displayHeaderFooter?: boolean;
2151
2152 /**
2153 * HTML template for the print footer. Should use the same format as the `headerTemplate`.
2154 */
2155 footerTemplate?: string;
2156
2157 /**
2158 * Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.
2159 */
2160 format?: string;
2161
2162 /**
2163 * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values
2164 * into them:
2165 * - `'date'` formatted print date
2166 * - `'title'` document title
2167 * - `'url'` document location
2168 * - `'pageNumber'` current page number
2169 * - `'totalPages'` total pages in the document
2170 */
2171 headerTemplate?: string;
2172
2173 /**
2174 * Paper height, accepts values labeled with units.
2175 */
2176 height?: string|number;
2177
2178 /**
2179 * Paper orientation. Defaults to `false`.
2180 */
2181 landscape?: boolean;
2182
2183 /**
2184 * Paper margins, defaults to none.
2185 */
2186 margin?: {
2187 /**
2188 * Top margin, accepts values labeled with units. Defaults to `0`.
2189 */
2190 top?: string|number;
2191
2192 /**
2193 * Right margin, accepts values labeled with units. Defaults to `0`.
2194 */
2195 right?: string|number;
2196
2197 /**
2198 * Bottom margin, accepts values labeled with units. Defaults to `0`.
2199 */
2200 bottom?: string|number;
2201
2202 /**
2203 * Left margin, accepts values labeled with units. Defaults to `0`.
2204 */
2205 left?: string|number;
2206 };
2207
2208 /**
2209 * Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
2210 */
2211 pageRanges?: string;
2212
2213 /**
2214 * The file path to save the PDF to. If `path` is a relative path, then it is resolved relative to the current working
2215 * directory. If no path is provided, the PDF won't be saved to the disk.
2216 */
2217 path?: string;
2218
2219 /**
2220 * Give any CSS `@page` size declared in the page priority over what is declared in `width` and `height` or `format`
2221 * options. Defaults to `false`, which will scale the content to fit the paper size.
2222 */
2223 preferCSSPageSize?: boolean;
2224
2225 /**
2226 * Print background graphics. Defaults to `false`.
2227 */
2228 printBackground?: boolean;
2229
2230 /**
2231 * Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
2232 */
2233 scale?: number;
2234
2235 /**
2236 * Paper width, accepts values labeled with units.
2237 */
2238 width?: string|number;
2239 }): Promise<Buffer>;
2240
2241 /**
2242 * Focuses the element, and then uses [keyboard.down(key)](https://playwright.dev/docs/api/class-keyboard#keyboarddownkey)
2243 * and [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboardupkey).
2244 *
2245 * `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
2246 * value or a single character to generate the text for. A superset of the `key` values can be found
2247 * [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
2248 *
2249 * `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
2250 * `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
2251 *
2252 * Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
2253 *
2254 * Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
2255 *
2256 * If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
2257 * texts.
2258 *
2259 * Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
2260 * modifier, modifier is pressed and being held while the subsequent key is being pressed.
2261 *
2262 * ```js
2263 * const page = await browser.newPage();
2264 * await page.goto('https://keycode.info');
2265 * await page.press('body', 'A');
2266 * await page.screenshot({ path: 'A.png' });
2267 * await page.press('body', 'ArrowLeft');
2268 * await page.screenshot({ path: 'ArrowLeft.png' });
2269 * await page.press('body', 'Shift+O');
2270 * await page.screenshot({ path: 'O.png' });
2271 * await browser.close();
2272 * ```
2273 *
2274 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2275 * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
2276 * @param options
2277 */
2278 press(selector: string, key: string, options?: {
2279 /**
2280 * Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
2281 */
2282 delay?: number;
2283
2284 /**
2285 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
2286 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
2287 * inaccessible pages. Defaults to `false`.
2288 */
2289 noWaitAfter?: boolean;
2290
2291 /**
2292 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2293 * using the
2294 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2295 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2296 */
2297 timeout?: number;
2298 }): Promise<void>;
2299
2300 /**
2301 * Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
2302 * last redirect.
2303 * @param options
2304 */
2305 reload(options?: {
2306 /**
2307 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
2308 * changed by using the
2309 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
2310 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
2311 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
2312 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2313 */
2314 timeout?: number;
2315
2316 /**
2317 * When to consider operation succeeded, defaults to `load`. Events can be either:
2318 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
2319 * - `'load'` - consider operation to be finished when the `load` event is fired.
2320 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
2321 */
2322 waitUntil?: "load"|"domcontentloaded"|"networkidle";
2323 }): Promise<null|Response>;
2324
2325 /**
2326 * Routing provides the capability to modify network requests that are made by a page.
2327 *
2328 * Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
2329 *
2330 * > NOTE: The handler will only be called for the first url if the response is a redirect.
2331 *
2332 * An example of a naïve handler that aborts all image requests:
2333 *
2334 * ```js
2335 * const page = await browser.newPage();
2336 * await page.route('**\/*.{png,jpg,jpeg}', route => route.abort());
2337 * await page.goto('https://example.com');
2338 * await browser.close();
2339 * ```
2340 *
2341 * or the same snippet using a regex pattern instead:
2342 *
2343 * ```js
2344 * const page = await browser.newPage();
2345 * await page.route(/(\.png$)|(\.jpg$)/, route => route.abort());
2346 * await page.goto('https://example.com');
2347 * await browser.close();
2348 * ```
2349 *
2350 * Page routes take precedence over browser context routes (set up with
2351 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler))
2352 * when request matches both handlers.
2353 *
2354 * > NOTE: Enabling routing disables http cache.
2355 * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing.
2356 * @param handler handler function to route the request.
2357 */
2358 route(url: string|RegExp|((url: URL) => boolean), handler: ((route: Route, request: Request) => void)): Promise<void>;
2359
2360 /**
2361 * Returns the buffer with the captured screenshot.
2362 *
2363 * > NOTE: Screenshots take at least 1/6 second on Chromium OS X and Chromium Windows. See https://crbug.com/741689 for
2364 * discussion.
2365 * @param options
2366 */
2367 screenshot(options?: {
2368 /**
2369 * An object which specifies clipping of the resulting image. Should have the following fields:
2370 */
2371 clip?: {
2372 /**
2373 * x-coordinate of top-left corner of clip area
2374 */
2375 x: number;
2376
2377 /**
2378 * y-coordinate of top-left corner of clip area
2379 */
2380 y: number;
2381
2382 /**
2383 * width of clipping area
2384 */
2385 width: number;
2386
2387 /**
2388 * height of clipping area
2389 */
2390 height: number;
2391 };
2392
2393 /**
2394 * When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
2395 * `false`.
2396 */
2397 fullPage?: boolean;
2398
2399 /**
2400 * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.
2401 * Defaults to `false`.
2402 */
2403 omitBackground?: boolean;
2404
2405 /**
2406 * The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative
2407 * path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to
2408 * the disk.
2409 */
2410 path?: string;
2411
2412 /**
2413 * The quality of the image, between 0-100. Not applicable to `png` images.
2414 */
2415 quality?: number;
2416
2417 /**
2418 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2419 * using the
2420 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2421 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2422 */
2423 timeout?: number;
2424
2425 /**
2426 * Specify screenshot type, defaults to `png`.
2427 */
2428 type?: "png"|"jpeg";
2429 }): Promise<Buffer>;
2430
2431 /**
2432 * Returns the array of option values that have been successfully selected.
2433 *
2434 * Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element
2435 * matching `selector`, the method throws an error.
2436 *
2437 * Will wait until all specified options are present in the `<select>` element.
2438 *
2439 * ```js
2440 * // single selection matching the value
2441 * page.selectOption('select#colors', 'blue');
2442 *
2443 * // single selection matching the label
2444 * page.selectOption('select#colors', { label: 'Blue' });
2445 *
2446 * // multiple selection
2447 * page.selectOption('select#colors', ['red', 'green', 'blue']);
2448 *
2449 * ```
2450 *
2451 * Shortcut for main frame's
2452 * [frame.selectOption(selector, values[, options])](https://playwright.dev/docs/api/class-frame#frameselectoptionselector-values-options)
2453 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2454 * @param values Options to select. If the `<select>` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option
2455 * is considered matching if all specified properties match.
2456 * @param options
2457 */
2458 selectOption(selector: string, values: null|string|ElementHandle|Array<string>|{
2459 /**
2460 * Matches by `option.value`. Optional.
2461 */
2462 value?: string;
2463
2464 /**
2465 * Matches by `option.label`. Optional.
2466 */
2467 label?: string;
2468
2469 /**
2470 * Matches by the index. Optional.
2471 */
2472 index?: number;
2473 }|Array<ElementHandle>|Array<{
2474 /**
2475 * Matches by `option.value`. Optional.
2476 */
2477 value?: string;
2478
2479 /**
2480 * Matches by `option.label`. Optional.
2481 */
2482 label?: string;
2483
2484 /**
2485 * Matches by the index. Optional.
2486 */
2487 index?: number;
2488 }>, options?: {
2489 /**
2490 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
2491 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
2492 * inaccessible pages. Defaults to `false`.
2493 */
2494 noWaitAfter?: boolean;
2495
2496 /**
2497 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2498 * using the
2499 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2500 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2501 */
2502 timeout?: number;
2503 }): Promise<Array<string>>;
2504
2505 /**
2506 * @param html HTML markup to assign to the page.
2507 * @param options
2508 */
2509 setContent(html: string, options?: {
2510 /**
2511 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
2512 * changed by using the
2513 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
2514 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
2515 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
2516 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2517 */
2518 timeout?: number;
2519
2520 /**
2521 * When to consider operation succeeded, defaults to `load`. Events can be either:
2522 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
2523 * - `'load'` - consider operation to be finished when the `load` event is fired.
2524 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
2525 */
2526 waitUntil?: "load"|"domcontentloaded"|"networkidle";
2527 }): Promise<void>;
2528
2529 /**
2530 * This setting will change the default maximum navigation time for the following methods and related shortcuts:
2531 * - [page.goBack([options])](https://playwright.dev/docs/api/class-page#pagegobackoptions)
2532 * - [page.goForward([options])](https://playwright.dev/docs/api/class-page#pagegoforwardoptions)
2533 * - [page.goto(url[, options])](https://playwright.dev/docs/api/class-page#pagegotourl-options)
2534 * - [page.reload([options])](https://playwright.dev/docs/api/class-page#pagereloadoptions)
2535 * - [page.setContent(html[, options])](https://playwright.dev/docs/api/class-page#pagesetcontenthtml-options)
2536 * - [page.waitForNavigation([options])](https://playwright.dev/docs/api/class-page#pagewaitfornavigationoptions)
2537 *
2538 * > NOTE:
2539 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
2540 * takes priority over
2541 * [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout),
2542 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2543 * and
2544 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout).
2545 * @param timeout Maximum navigation time in milliseconds
2546 */
2547 setDefaultNavigationTimeout(timeout: number): void;
2548
2549 /**
2550 * This setting will change the default maximum time for all the methods accepting `timeout` option.
2551 *
2552 * > NOTE:
2553 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
2554 * takes priority over
2555 * [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout).
2556 * @param timeout Maximum time in milliseconds
2557 */
2558 setDefaultTimeout(timeout: number): void;
2559
2560 /**
2561 * The extra HTTP headers will be sent with every request the page initiates.
2562 *
2563 * > NOTE: [page.setExtraHTTPHeaders(headers)](https://playwright.dev/docs/api/class-page#pagesetextrahttpheadersheaders)
2564 * does not guarantee the order of headers in the outgoing requests.
2565 * @param headers An object containing additional HTTP headers to be sent with every request. All header values must be strings.
2566 */
2567 setExtraHTTPHeaders(headers: { [key: string]: string; }): Promise<void>;
2568
2569 /**
2570 * This method expects `selector` to point to an
2571 * [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
2572 *
2573 * Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
2574 * are resolved relative to the the current working directory. For empty array, clears the selected files.
2575 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2576 * @param files
2577 * @param options
2578 */
2579 setInputFiles(selector: string, files: string|Array<string>|{
2580 /**
2581 * File name
2582 */
2583 name: string;
2584
2585 /**
2586 * File type
2587 */
2588 mimeType: string;
2589
2590 /**
2591 * File content
2592 */
2593 buffer: Buffer;
2594 }|Array<{
2595 /**
2596 * File name
2597 */
2598 name: string;
2599
2600 /**
2601 * File type
2602 */
2603 mimeType: string;
2604
2605 /**
2606 * File content
2607 */
2608 buffer: Buffer;
2609 }>, options?: {
2610 /**
2611 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
2612 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
2613 * inaccessible pages. Defaults to `false`.
2614 */
2615 noWaitAfter?: boolean;
2616
2617 /**
2618 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2619 * using the
2620 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2621 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2622 */
2623 timeout?: number;
2624 }): Promise<void>;
2625
2626 /**
2627 * In the case of multiple pages in a single browser, each page can have its own viewport size. However,
2628 * [browser.newContext([options])](https://playwright.dev/docs/api/class-browser#browsernewcontextoptions) allows to set
2629 * viewport size (and more) for all pages in the context at once.
2630 *
2631 * `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
2632 * viewport size before navigating to the page.
2633 *
2634 * ```js
2635 * const page = await browser.newPage();
2636 * await page.setViewportSize({
2637 * width: 640,
2638 * height: 480,
2639 * });
2640 * await page.goto('https://example.com');
2641 * ```
2642 *
2643 * @param viewportSize
2644 */
2645 setViewportSize(viewportSize: {
2646 /**
2647 * page width in pixels.
2648 */
2649 width: number;
2650
2651 /**
2652 * page height in pixels.
2653 */
2654 height: number;
2655 }): Promise<void>;
2656
2657 /**
2658 * This method taps an element matching `selector` by performing the following steps:
2659 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
2660 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
2661 * element is detached during the checks, the whole action is retried.
2662 * 1. Scroll the element into view if needed.
2663 * 1. Use [page.touchscreen](https://playwright.dev/docs/api/class-page#pagetouchscreen) to tap the center of the
2664 * element, or the specified `position`.
2665 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
2666 *
2667 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
2668 * Passing zero timeout disables this.
2669 *
2670 * > NOTE: [page.tap(selector[, options])](https://playwright.dev/docs/api/class-page#pagetapselector-options) requires
2671 * that the `hasTouch` option of the browser context be set to true.
2672 *
2673 * Shortcut for main frame's
2674 * [frame.tap(selector[, options])](https://playwright.dev/docs/api/class-frame#frametapselector-options).
2675 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2676 * @param options
2677 */
2678 tap(selector: string, options?: {
2679 /**
2680 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
2681 */
2682 force?: boolean;
2683
2684 /**
2685 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
2686 * modifiers back. If not specified, currently pressed modifiers are used.
2687 */
2688 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
2689
2690 /**
2691 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
2692 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
2693 * inaccessible pages. Defaults to `false`.
2694 */
2695 noWaitAfter?: boolean;
2696
2697 /**
2698 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
2699 * element.
2700 */
2701 position?: {
2702 x: number;
2703
2704 y: number;
2705 };
2706
2707 /**
2708 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2709 * using the
2710 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2711 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2712 */
2713 timeout?: number;
2714 }): Promise<void>;
2715
2716 /**
2717 * Returns `element.textContent`.
2718 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2719 * @param options
2720 */
2721 textContent(selector: string, options?: {
2722 /**
2723 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2724 * using the
2725 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2726 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2727 */
2728 timeout?: number;
2729 }): Promise<null|string>;
2730
2731 /**
2732 * Returns the page's title. Shortcut for main frame's
2733 * [frame.title()](https://playwright.dev/docs/api/class-frame#frametitle).
2734 */
2735 title(): Promise<string>;
2736
2737 touchscreen: Touchscreen;
2738
2739 /**
2740 * Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
2741 * fine-grained keyboard events. To fill values in form fields, use
2742 * [page.fill(selector, value[, options])](https://playwright.dev/docs/api/class-page#pagefillselector-value-options).
2743 *
2744 * To press a special key, like `Control` or `ArrowDown`, use
2745 * [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboardpresskey-options).
2746 *
2747 * ```js
2748 * await page.type('#mytextarea', 'Hello'); // Types instantly
2749 * await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
2750 * ```
2751 *
2752 * Shortcut for main frame's
2753 * [frame.type(selector, text[, options])](https://playwright.dev/docs/api/class-frame#frametypeselector-text-options).
2754 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2755 * @param text A text to type into a focused element.
2756 * @param options
2757 */
2758 type(selector: string, text: string, options?: {
2759 /**
2760 * Time to wait between key presses in milliseconds. Defaults to 0.
2761 */
2762 delay?: number;
2763
2764 /**
2765 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
2766 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
2767 * inaccessible pages. Defaults to `false`.
2768 */
2769 noWaitAfter?: boolean;
2770
2771 /**
2772 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2773 * using the
2774 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2775 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2776 */
2777 timeout?: number;
2778 }): Promise<void>;
2779
2780 /**
2781 * This method unchecks an element matching `selector` by performing the following steps:
2782 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
2783 * 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
2784 * unchecked, this method returns immediately.
2785 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
2786 * element is detached during the checks, the whole action is retried.
2787 * 1. Scroll the element into view if needed.
2788 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element.
2789 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
2790 * 1. Ensure that the element is now unchecked. If not, this method rejects.
2791 *
2792 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
2793 * Passing zero timeout disables this.
2794 *
2795 * Shortcut for main frame's
2796 * [frame.uncheck(selector[, options])](https://playwright.dev/docs/api/class-frame#frameuncheckselector-options).
2797 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
2798 * @param options
2799 */
2800 uncheck(selector: string, options?: {
2801 /**
2802 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
2803 */
2804 force?: boolean;
2805
2806 /**
2807 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
2808 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
2809 * inaccessible pages. Defaults to `false`.
2810 */
2811 noWaitAfter?: boolean;
2812
2813 /**
2814 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
2815 * using the
2816 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
2817 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
2818 */
2819 timeout?: number;
2820 }): Promise<void>;
2821
2822 /**
2823 * Removes a route created with
2824 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler). When `handler` is not
2825 * specified, removes all routes for the `url`.
2826 * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing.
2827 * @param handler Optional handler function to route the request.
2828 */
2829 unroute(url: string|RegExp|((url: URL) => boolean), handler?: ((route: Route, request: Request) => void)): Promise<void>;
2830
2831 /**
2832 * Shortcut for main frame's [frame.url()](https://playwright.dev/docs/api/class-frame#frameurl).
2833 */
2834 url(): string;
2835
2836 /**
2837 * Video object associated with this page.
2838 */
2839 video(): null|Video;
2840
2841 viewportSize(): null|{
2842 /**
2843 * page width in pixels.
2844 */
2845 width: number;
2846
2847 /**
2848 * page height in pixels.
2849 */
2850 height: number;
2851 };
2852
2853 /**
2854 * Emitted when the page closes.
2855 */
2856 waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
2857
2858 /**
2859 * Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
2860 * emitted if the page throws an error or a warning.
2861 *
2862 * The arguments passed into `console.log` appear as arguments on the event handler.
2863 *
2864 * An example of handling `console` event:
2865 *
2866 * ```js
2867 * page.on('console', msg => {
2868 * for (let i = 0; i < msg.args().length; ++i)
2869 * console.log(`${i}: ${await msg.args()[i].jsonValue()}`);
2870 * });
2871 * page.evaluate(() => console.log('hello', 5, {foo: 'bar'}));
2872 * ```
2873 *
2874 */
2875 waitForEvent(event: 'console', optionsOrPredicate?: { predicate?: (consoleMessage: ConsoleMessage) => boolean, timeout?: number } | ((consoleMessage: ConsoleMessage) => boolean)): Promise<ConsoleMessage>;
2876
2877 /**
2878 * Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes,
2879 * ongoing and subsequent operations will throw.
2880 *
2881 * The most common way to deal with crashes is to catch an exception:
2882 *
2883 * ```js
2884 * try {
2885 * // Crash might happen during a click.
2886 * await page.click('button');
2887 * // Or while waiting for an event.
2888 * await page.waitForEvent('popup');
2889 * } catch (e) {
2890 * // When the page crashes, exception message contains 'crash'.
2891 * }
2892 * ```
2893 *
2894 */
2895 waitForEvent(event: 'crash', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
2896
2897 /**
2898 * Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must**
2899 * either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
2900 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
2901 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
2902 * actions like click will never finish.
2903 *
2904 * > NOTE: When no [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listeners are present, all
2905 * dialogs are automatically dismissed.
2906 */
2907 waitForEvent(event: 'dialog', optionsOrPredicate?: { predicate?: (dialog: Dialog) => boolean, timeout?: number } | ((dialog: Dialog) => boolean)): Promise<Dialog>;
2908
2909 /**
2910 * Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded)
2911 * event is dispatched.
2912 */
2913 waitForEvent(event: 'domcontentloaded', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
2914
2915 /**
2916 * Emitted when attachment download started. User can access basic file operations on downloaded content via the passed
2917 * [Download] instance.
2918 *
2919 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
2920 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
2921 * performed and user has no access to the downloaded files.
2922 */
2923 waitForEvent(event: 'download', optionsOrPredicate?: { predicate?: (download: Download) => boolean, timeout?: number } | ((download: Download) => boolean)): Promise<Download>;
2924
2925 /**
2926 * Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can
2927 * respond to it via setting the input files using
2928 * [fileChooser.setFiles(files[, options])](https://playwright.dev/docs/api/class-filechooser#filechoosersetfilesfiles-options)
2929 * that can be uploaded after that.
2930 *
2931 * ```js
2932 * page.on('filechooser', async (fileChooser) => {
2933 * await fileChooser.setFiles('/tmp/myfile.pdf');
2934 * });
2935 * ```
2936 *
2937 */
2938 waitForEvent(event: 'filechooser', optionsOrPredicate?: { predicate?: (fileChooser: FileChooser) => boolean, timeout?: number } | ((fileChooser: FileChooser) => boolean)): Promise<FileChooser>;
2939
2940 /**
2941 * Emitted when a frame is attached.
2942 */
2943 waitForEvent(event: 'frameattached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean, timeout?: number } | ((frame: Frame) => boolean)): Promise<Frame>;
2944
2945 /**
2946 * Emitted when a frame is detached.
2947 */
2948 waitForEvent(event: 'framedetached', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean, timeout?: number } | ((frame: Frame) => boolean)): Promise<Frame>;
2949
2950 /**
2951 * Emitted when a frame is navigated to a new url.
2952 */
2953 waitForEvent(event: 'framenavigated', optionsOrPredicate?: { predicate?: (frame: Frame) => boolean, timeout?: number } | ((frame: Frame) => boolean)): Promise<Frame>;
2954
2955 /**
2956 * Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
2957 */
2958 waitForEvent(event: 'load', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
2959
2960 /**
2961 * Emitted when an uncaught exception happens within the page.
2962 */
2963 waitForEvent(event: 'pageerror', optionsOrPredicate?: { predicate?: (error: Error) => boolean, timeout?: number } | ((error: Error) => boolean)): Promise<Error>;
2964
2965 /**
2966 * Emitted when the page opens a new tab or window. This event is emitted in addition to the
2967 * [browserContext.on('page')](https://playwright.dev/docs/api/class-browsercontext#browsercontextonpage), but only for
2968 * popups relevant to this page.
2969 *
2970 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
2971 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
2972 * done and its response has started loading in the popup.
2973 *
2974 * ```js
2975 * const [popup] = await Promise.all([
2976 * page.waitForEvent('popup'),
2977 * page.evaluate(() => window.open('https://example.com')),
2978 * ]);
2979 * console.log(await popup.evaluate('location.href'));
2980 * ```
2981 *
2982 * > NOTE: Use
2983 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
2984 * to wait until the page gets to a particular state (you should not need it in most cases).
2985 */
2986 waitForEvent(event: 'popup', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
2987
2988 /**
2989 * Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, see
2990 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
2991 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
2992 */
2993 waitForEvent(event: 'request', optionsOrPredicate?: { predicate?: (request: Request) => boolean, timeout?: number } | ((request: Request) => boolean)): Promise<Request>;
2994
2995 /**
2996 * Emitted when a request fails, for example by timing out.
2997 *
2998 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
2999 * complete with [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) event and
3000 * not with [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed).
3001 */
3002 waitForEvent(event: 'requestfailed', optionsOrPredicate?: { predicate?: (request: Request) => boolean, timeout?: number } | ((request: Request) => boolean)): Promise<Request>;
3003
3004 /**
3005 * Emitted when a request finishes successfully after downloading the response body. For a successful response, the
3006 * sequence of events is `request`, `response` and `requestfinished`.
3007 */
3008 waitForEvent(event: 'requestfinished', optionsOrPredicate?: { predicate?: (request: Request) => boolean, timeout?: number } | ((request: Request) => boolean)): Promise<Request>;
3009
3010 /**
3011 * Emitted when [response] status and headers are received for a request. For a successful response, the sequence of events
3012 * is `request`, `response` and `requestfinished`.
3013 */
3014 waitForEvent(event: 'response', optionsOrPredicate?: { predicate?: (response: Response) => boolean, timeout?: number } | ((response: Response) => boolean)): Promise<Response>;
3015
3016 /**
3017 * Emitted when [WebSocket] request is sent.
3018 */
3019 waitForEvent(event: 'websocket', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean, timeout?: number } | ((webSocket: WebSocket) => boolean)): Promise<WebSocket>;
3020
3021 /**
3022 * Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the
3023 * page.
3024 */
3025 waitForEvent(event: 'worker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean, timeout?: number } | ((worker: Worker) => boolean)): Promise<Worker>;
3026
3027
3028 /**
3029 * Returns when the required load state has been reached.
3030 *
3031 * This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
3032 * when this method is called. If current document has already reached the required state, resolves immediately.
3033 *
3034 * ```js
3035 * await page.click('button'); // Click triggers navigation.
3036 * await page.waitForLoadState(); // The promise resolves after 'load' event.
3037 * ```
3038 *
3039 * ```js
3040 * const [popup] = await Promise.all([
3041 * page.waitForEvent('popup'),
3042 * page.click('button'), // Click triggers a popup.
3043 * ])
3044 * await popup.waitForLoadState('domcontentloaded'); // The promise resolves after 'domcontentloaded' event.
3045 * console.log(await popup.title()); // Popup is ready to use.
3046 * ```
3047 *
3048 * Shortcut for main frame's
3049 * [frame.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-frame#framewaitforloadstatestate-options).
3050 * @param state Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately. Can be one of:
3051 * - `'load'` - wait for the `load` event to be fired.
3052 * - `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
3053 * - `'networkidle'` - wait until there are no network connections for at least `500` ms.
3054 * @param options
3055 */
3056 waitForLoadState(state?: "load"|"domcontentloaded"|"networkidle", options?: {
3057 /**
3058 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
3059 * changed by using the
3060 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
3061 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
3062 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
3063 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3064 */
3065 timeout?: number;
3066 }): Promise<void>;
3067
3068 /**
3069 * Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the
3070 * navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or
3071 * navigation due to History API usage, the navigation will resolve with `null`.
3072 *
3073 * This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
3074 * cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
3075 * Consider this example:
3076 *
3077 * ```js
3078 * const [response] = await Promise.all([
3079 * page.waitForNavigation(), // The promise resolves after navigation has finished
3080 * page.click('a.delayed-navigation'), // Clicking the link will indirectly cause a navigation
3081 * ]);
3082 * ```
3083 *
3084 * > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
3085 * considered a navigation.
3086 *
3087 * Shortcut for main frame's
3088 * [frame.waitForNavigation([options])](https://playwright.dev/docs/api/class-frame#framewaitfornavigationoptions).
3089 * @param options
3090 */
3091 waitForNavigation(options?: {
3092 /**
3093 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
3094 * changed by using the
3095 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
3096 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
3097 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
3098 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3099 */
3100 timeout?: number;
3101
3102 /**
3103 * A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
3104 */
3105 url?: string|RegExp|((url: URL) => boolean);
3106
3107 /**
3108 * When to consider operation succeeded, defaults to `load`. Events can be either:
3109 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
3110 * - `'load'` - consider operation to be finished when the `load` event is fired.
3111 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
3112 */
3113 waitUntil?: "load"|"domcontentloaded"|"networkidle";
3114 }): Promise<null|Response>;
3115
3116 /**
3117 * Waits for the matching request and returns it.
3118 *
3119 * ```js
3120 * const firstRequest = await page.waitForRequest('http://example.com/resource');
3121 * const finalRequest = await page.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET');
3122 * return firstRequest.url();
3123 * ```
3124 *
3125 * ```js
3126 * await page.waitForRequest(request => request.url().searchParams.get('foo') === 'bar' && request.url().searchParams.get('foo2') === 'bar2');
3127 * ```
3128 *
3129 * @param urlOrPredicate Request URL string, regex or predicate receiving [Request] object.
3130 * @param options
3131 */
3132 waitForRequest(urlOrPredicate: string|RegExp|((request: Request) => boolean), options?: {
3133 /**
3134 * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be
3135 * changed by using the
3136 * [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) method.
3137 */
3138 timeout?: number;
3139 }): Promise<Request>;
3140
3141 /**
3142 * Returns the matched response.
3143 *
3144 * ```js
3145 * const firstResponse = await page.waitForResponse('https://example.com/resource');
3146 * const finalResponse = await page.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200);
3147 * return finalResponse.ok();
3148 * ```
3149 *
3150 * @param urlOrPredicate Request URL string, regex or predicate receiving [Response] object.
3151 * @param options
3152 */
3153 waitForResponse(urlOrPredicate: string|RegExp|((response: Response) => boolean), options?: {
3154 /**
3155 * Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can be
3156 * changed by using the
3157 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3158 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3159 */
3160 timeout?: number;
3161 }): Promise<Response>;
3162
3163 /**
3164 * Waits for the given `timeout` in milliseconds.
3165 *
3166 * Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
3167 * flaky. Use signals such as network events, selectors becoming visible and others instead.
3168 *
3169 * ```js
3170 * // wait for 1 second
3171 * await page.waitForTimeout(1000);
3172 * ```
3173 *
3174 * Shortcut for main frame's
3175 * [frame.waitForTimeout(timeout)](https://playwright.dev/docs/api/class-frame#framewaitfortimeouttimeout).
3176 * @param timeout A timeout to wait for
3177 */
3178 waitForTimeout(timeout: number): Promise<void>;
3179
3180 /**
3181 * This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
3182 * associated with the page.
3183 *
3184 * > NOTE: This does not contain ServiceWorkers
3185 */
3186 workers(): Array<Worker>;}
3187
3188/**
3189 * At every point of time, page exposes its current frame tree via the
3190 * [page.mainFrame()](https://playwright.dev/docs/api/class-page#pagemainframe) and
3191 * [frame.childFrames()](https://playwright.dev/docs/api/class-frame#framechildframes) methods.
3192 *
3193 * [Frame] object's lifecycle is controlled by three events, dispatched on the page object:
3194 * - [page.on('frameattached')](https://playwright.dev/docs/api/class-page#pageonframeattached) - fired when the frame
3195 * gets attached to the page. A Frame can be attached to the page only once.
3196 * - [page.on('framenavigated')](https://playwright.dev/docs/api/class-page#pageonframenavigated) - fired when the frame
3197 * commits navigation to a different URL.
3198 * - [page.on('framedetached')](https://playwright.dev/docs/api/class-page#pageonframedetached) - fired when the frame
3199 * gets detached from the page. A Frame can be detached from the page only once.
3200 *
3201 * An example of dumping frame tree:
3202 *
3203 * ```js
3204 * const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
3205 *
3206 * (async () => {
3207 * const browser = await firefox.launch();
3208 * const page = await browser.newPage();
3209 * await page.goto('https://www.google.com/chrome/browser/canary.html');
3210 * dumpFrameTree(page.mainFrame(), '');
3211 * await browser.close();
3212 *
3213 * function dumpFrameTree(frame, indent) {
3214 * console.log(indent + frame.url());
3215 * for (const child of frame.childFrames()) {
3216 * dumpFrameTree(child, indent + ' ');
3217 * }
3218 * }
3219 * })();
3220 * ```
3221 *
3222 */
3223export interface Frame {
3224 /**
3225 * Returns the return value of `pageFunction`.
3226 *
3227 * If the function passed to the
3228 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg) returns
3229 * a [Promise], then
3230 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg) would
3231 * wait for the promise to resolve and return its value.
3232 *
3233 * If the function passed to the
3234 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg) returns
3235 * a non-[Serializable] value, then
3236 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg) returns
3237 * `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: `-0`,
3238 * `NaN`, `Infinity`, `-Infinity`.
3239 *
3240 * ```js
3241 * const result = await frame.evaluate(([x, y]) => {
3242 * return Promise.resolve(x * y);
3243 * }, [7, 8]);
3244 * console.log(result); // prints "56"
3245 * ```
3246 *
3247 * A string can also be passed in instead of a function.
3248 *
3249 * ```js
3250 * console.log(await frame.evaluate('1 + 2')); // prints "3"
3251 * ```
3252 *
3253 * [ElementHandle] instances can be passed as an argument to the
3254 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg):
3255 *
3256 * ```js
3257 * const bodyHandle = await frame.$('body');
3258 * const html = await frame.evaluate(([body, suffix]) => body.innerHTML + suffix, [bodyHandle, 'hello']);
3259 * await bodyHandle.dispose();
3260 * ```
3261 *
3262 * @param pageFunction Function to be evaluated in the page context.
3263 * @param arg Optional argument to pass to `pageFunction`.
3264 */
3265 evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<R>;
3266 evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<R>;
3267
3268 /**
3269 * Returns the return value of `pageFunction` as a [JSHandle].
3270 *
3271 * The only difference between
3272 * [frame.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatepagefunction-arg) and
3273 * [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatehandlepagefunction-arg)
3274 * is that
3275 * [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatehandlepagefunction-arg)
3276 * returns [JSHandle].
3277 *
3278 * If the function, passed to the
3279 * [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatehandlepagefunction-arg),
3280 * returns a [Promise], then
3281 * [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatehandlepagefunction-arg)
3282 * would wait for the promise to resolve and return its value.
3283 *
3284 * ```js
3285 * const aWindowHandle = await frame.evaluateHandle(() => Promise.resolve(window));
3286 * aWindowHandle; // Handle for the window object.
3287 * ```
3288 *
3289 * A string can also be passed in instead of a function.
3290 *
3291 * ```js
3292 * const aHandle = await frame.evaluateHandle('document'); // Handle for the 'document'.
3293 * ```
3294 *
3295 * [JSHandle] instances can be passed as an argument to the
3296 * [frame.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevaluatehandlepagefunction-arg):
3297 *
3298 * ```js
3299 * const aHandle = await frame.evaluateHandle(() => document.body);
3300 * const resultHandle = await frame.evaluateHandle(([body, suffix]) => body.innerHTML + suffix, [aHandle, 'hello']);
3301 * console.log(await resultHandle.jsonValue());
3302 * await resultHandle.dispose();
3303 * ```
3304 *
3305 * @param pageFunction Function to be evaluated in the page context.
3306 * @param arg Optional argument to pass to `pageFunction`.
3307 */
3308 evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<SmartHandle<R>>;
3309 evaluateHandle<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<SmartHandle<R>>;
3310
3311 /**
3312 * Returns the ElementHandle pointing to the frame element.
3313 *
3314 * The method finds an element matching the specified selector within the frame. See
3315 * [Working with selectors](https://playwright.dev/docs/selectors) for more details. If no elements match the selector, returns `null`.
3316 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3317 */
3318 $<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K> | null>;
3319 $(selector: string): Promise<ElementHandle<SVGElement | HTMLElement> | null>;
3320
3321 /**
3322 * Returns the ElementHandles pointing to the frame elements.
3323 *
3324 * The method finds all elements matching the specified selector within the frame. See
3325 * [Working with selectors](https://playwright.dev/docs/selectors) for more details. If no elements match the selector, returns empty array.
3326 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3327 */
3328 $$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
3329 $$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
3330
3331 /**
3332 * Returns the return value of `pageFunction`.
3333 *
3334 * The method finds an element matching the specified selector within the frame and passes it as a first argument to
3335 * `pageFunction`. See [Working with selectors](https://playwright.dev/docs/selectors) for more details. If no elements match the selector, the
3336 * method throws an error.
3337 *
3338 * If `pageFunction` returns a [Promise], then
3339 * [frame.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevalselector-pagefunction-arg)
3340 * would wait for the promise to resolve and return its value.
3341 *
3342 * Examples:
3343 *
3344 * ```js
3345 * const searchValue = await frame.$eval('#search', el => el.value);
3346 * const preloadHref = await frame.$eval('link[rel=preload]', el => el.href);
3347 * const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
3348 * ```
3349 *
3350 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3351 * @param pageFunction Function to be evaluated in the page context.
3352 * @param arg Optional argument to pass to `pageFunction`.
3353 */
3354 $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
3355 $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
3356 $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
3357 $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
3358
3359 /**
3360 * Returns the return value of `pageFunction`.
3361 *
3362 * The method finds all elements matching the specified selector within the frame and passes an array of matched elements
3363 * as a first argument to `pageFunction`. See [Working with selectors](https://playwright.dev/docs/selectors) for more details.
3364 *
3365 * If `pageFunction` returns a [Promise], then
3366 * [frame.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-frame#frameevalselector-pagefunction-arg)
3367 * would wait for the promise to resolve and return its value.
3368 *
3369 * Examples:
3370 *
3371 * ```js
3372 * const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);
3373 * ```
3374 *
3375 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3376 * @param pageFunction Function to be evaluated in the page context.
3377 * @param arg Optional argument to pass to `pageFunction`.
3378 */
3379 $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
3380 $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
3381 $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
3382 $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
3383
3384 /**
3385 * Returns when the `pageFunction` returns a truthy value, returns that value.
3386 *
3387 * The
3388 * [frame.waitForFunction(pageFunction[, arg, options])](https://playwright.dev/docs/api/class-frame#framewaitforfunctionpagefunction-arg-options)
3389 * can be used to observe viewport size change:
3390 *
3391 * ```js
3392 * const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
3393 *
3394 * (async () => {
3395 * const browser = await firefox.launch();
3396 * const page = await browser.newPage();
3397 * const watchDog = page.mainFrame().waitForFunction('window.innerWidth < 100');
3398 * page.setViewportSize({width: 50, height: 50});
3399 * await watchDog;
3400 * await browser.close();
3401 * })();
3402 * ```
3403 *
3404 * To pass an argument to the predicate of `frame.waitForFunction` function:
3405 *
3406 * ```js
3407 * const selector = '.foo';
3408 * await frame.waitForFunction(selector => !!document.querySelector(selector), selector);
3409 * ```
3410 *
3411 * @param pageFunction Function to be evaluated in the page context.
3412 * @param arg Optional argument to pass to `pageFunction`.
3413 * @param options
3414 */
3415 waitForFunction<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
3416 waitForFunction<R>(pageFunction: PageFunction<void, R>, arg?: any, options?: PageWaitForFunctionOptions): Promise<SmartHandle<R>>;
3417
3418 /**
3419 * Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
3420 * `detached`.
3421 *
3422 * Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
3423 * the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
3424 * selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
3425 *
3426 * This method works across navigations:
3427 *
3428 * ```js
3429 * const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
3430 *
3431 * (async () => {
3432 * const browser = await chromium.launch();
3433 * const page = await browser.newPage();
3434 * for (let currentURL of ['https://google.com', 'https://bbc.com']) {
3435 * await page.goto(currentURL);
3436 * const element = await page.mainFrame().waitForSelector('img');
3437 * console.log('Loaded image: ' + await element.getAttribute('src'));
3438 * }
3439 * await browser.close();
3440 * })();
3441 * ```
3442 *
3443 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3444 * @param options
3445 */
3446 waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandleForTag<K>>;
3447 waitForSelector(selector: string, options?: PageWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
3448 waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: PageWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;
3449 waitForSelector(selector: string, options: PageWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
3450 /**
3451 * Returns the added tag when the script's onload fires or when the script content was injected into frame.
3452 *
3453 * Adds a `<script>` tag into the page with the desired url or content.
3454 * @param options
3455 */
3456 addScriptTag(options?: {
3457 /**
3458 * Raw JavaScript content to be injected into frame.
3459 */
3460 content?: string;
3461
3462 /**
3463 * Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
3464 * current working directory.
3465 */
3466 path?: string;
3467
3468 /**
3469 * Script type. Use 'module' in order to load a Javascript ES6 module. See
3470 * [script](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script) for more details.
3471 */
3472 type?: string;
3473
3474 /**
3475 * URL of a script to be added.
3476 */
3477 url?: string;
3478 }): Promise<ElementHandle>;
3479
3480 /**
3481 * Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
3482 *
3483 * Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
3484 * content.
3485 * @param options
3486 */
3487 addStyleTag(options?: {
3488 /**
3489 * Raw CSS content to be injected into frame.
3490 */
3491 content?: string;
3492
3493 /**
3494 * Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the
3495 * current working directory.
3496 */
3497 path?: string;
3498
3499 /**
3500 * URL of the `<link>` tag.
3501 */
3502 url?: string;
3503 }): Promise<ElementHandle>;
3504
3505 /**
3506 * This method checks an element matching `selector` by performing the following steps:
3507 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
3508 * 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
3509 * checked, this method returns immediately.
3510 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
3511 * element is detached during the checks, the whole action is retried.
3512 * 1. Scroll the element into view if needed.
3513 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element.
3514 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
3515 * 1. Ensure that the element is now checked. If not, this method rejects.
3516 *
3517 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
3518 * Passing zero timeout disables this.
3519 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3520 * @param options
3521 */
3522 check(selector: string, options?: {
3523 /**
3524 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
3525 */
3526 force?: boolean;
3527
3528 /**
3529 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
3530 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
3531 * inaccessible pages. Defaults to `false`.
3532 */
3533 noWaitAfter?: boolean;
3534
3535 /**
3536 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3537 * using the
3538 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3539 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3540 */
3541 timeout?: number;
3542 }): Promise<void>;
3543
3544 childFrames(): Array<Frame>;
3545
3546 /**
3547 * This method clicks an element matching `selector` by performing the following steps:
3548 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
3549 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
3550 * element is detached during the checks, the whole action is retried.
3551 * 1. Scroll the element into view if needed.
3552 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element, or
3553 * the specified `position`.
3554 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
3555 *
3556 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
3557 * Passing zero timeout disables this.
3558 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3559 * @param options
3560 */
3561 click(selector: string, options?: {
3562 /**
3563 * Defaults to `left`.
3564 */
3565 button?: "left"|"right"|"middle";
3566
3567 /**
3568 * defaults to 1. See [UIEvent.detail].
3569 */
3570 clickCount?: number;
3571
3572 /**
3573 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
3574 */
3575 delay?: number;
3576
3577 /**
3578 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
3579 */
3580 force?: boolean;
3581
3582 /**
3583 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
3584 * modifiers back. If not specified, currently pressed modifiers are used.
3585 */
3586 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
3587
3588 /**
3589 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
3590 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
3591 * inaccessible pages. Defaults to `false`.
3592 */
3593 noWaitAfter?: boolean;
3594
3595 /**
3596 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
3597 * element.
3598 */
3599 position?: {
3600 x: number;
3601
3602 y: number;
3603 };
3604
3605 /**
3606 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3607 * using the
3608 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3609 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3610 */
3611 timeout?: number;
3612 }): Promise<void>;
3613
3614 /**
3615 * Gets the full HTML contents of the frame, including the doctype.
3616 */
3617 content(): Promise<string>;
3618
3619 /**
3620 * This method double clicks an element matching `selector` by performing the following steps:
3621 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
3622 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
3623 * element is detached during the checks, the whole action is retried.
3624 * 1. Scroll the element into view if needed.
3625 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to double click in the center of the
3626 * element, or the specified `position`.
3627 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
3628 * first click of the `dblclick()` triggers a navigation event, this method will reject.
3629 *
3630 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
3631 * Passing zero timeout disables this.
3632 *
3633 * > NOTE: `frame.dblclick()` dispatches two `click` events and a single `dblclick` event.
3634 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3635 * @param options
3636 */
3637 dblclick(selector: string, options?: {
3638 /**
3639 * Defaults to `left`.
3640 */
3641 button?: "left"|"right"|"middle";
3642
3643 /**
3644 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
3645 */
3646 delay?: number;
3647
3648 /**
3649 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
3650 */
3651 force?: boolean;
3652
3653 /**
3654 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
3655 * modifiers back. If not specified, currently pressed modifiers are used.
3656 */
3657 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
3658
3659 /**
3660 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
3661 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
3662 * inaccessible pages. Defaults to `false`.
3663 */
3664 noWaitAfter?: boolean;
3665
3666 /**
3667 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
3668 * element.
3669 */
3670 position?: {
3671 x: number;
3672
3673 y: number;
3674 };
3675
3676 /**
3677 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3678 * using the
3679 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3680 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3681 */
3682 timeout?: number;
3683 }): Promise<void>;
3684
3685 /**
3686 * The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
3687 * is dispatched. This is equivalend to calling
3688 * [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
3689 *
3690 * ```js
3691 * await frame.dispatchEvent('button#submit', 'click');
3692 * ```
3693 *
3694 * Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
3695 * and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
3696 *
3697 * Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
3698 * - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
3699 * - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
3700 * - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
3701 * - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
3702 * - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
3703 * - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
3704 * - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
3705 *
3706 * You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
3707 *
3708 * ```js
3709 * // Note you can only create DataTransfer in Chromium and Firefox
3710 * const dataTransfer = await frame.evaluateHandle(() => new DataTransfer());
3711 * await frame.dispatchEvent('#source', 'dragstart', { dataTransfer });
3712 * ```
3713 *
3714 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3715 * @param type DOM event type: `"click"`, `"dragstart"`, etc.
3716 * @param eventInit Optional event-specific initialization properties.
3717 * @param options
3718 */
3719 dispatchEvent(selector: string, type: string, eventInit?: EvaluationArgument, options?: {
3720 /**
3721 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3722 * using the
3723 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3724 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3725 */
3726 timeout?: number;
3727 }): Promise<void>;
3728
3729 /**
3730 * This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/docs/actionability) checks, focuses the
3731 * element, fills it and triggers an `input` event after filling. If the element is inside the `<label>` element that has
3732 * associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), that control will be
3733 * filled instead. If the element to be filled is not an `<input>`, `<textarea>` or `[contenteditable]` element, this
3734 * method throws an error. Note that you can pass an empty string to clear the input field.
3735 *
3736 * To send fine-grained keyboard events, use
3737 * [frame.type(selector, text[, options])](https://playwright.dev/docs/api/class-frame#frametypeselector-text-options).
3738 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3739 * @param value Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element.
3740 * @param options
3741 */
3742 fill(selector: string, value: string, options?: {
3743 /**
3744 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
3745 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
3746 * inaccessible pages. Defaults to `false`.
3747 */
3748 noWaitAfter?: boolean;
3749
3750 /**
3751 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3752 * using the
3753 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3754 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3755 */
3756 timeout?: number;
3757 }): Promise<void>;
3758
3759 /**
3760 * This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
3761 * waits until a matching element appears in the DOM.
3762 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3763 * @param options
3764 */
3765 focus(selector: string, options?: {
3766 /**
3767 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3768 * using the
3769 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3770 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3771 */
3772 timeout?: number;
3773 }): Promise<void>;
3774
3775 /**
3776 * Returns the `frame` or `iframe` element handle which corresponds to this frame.
3777 *
3778 * This is an inverse of
3779 * [elementHandle.contentFrame()](https://playwright.dev/docs/api/class-elementhandle#elementhandlecontentframe). Note that
3780 * returned handle actually belongs to the parent frame.
3781 *
3782 * This method throws an error if the frame has been detached before `frameElement()` returns.
3783 *
3784 * ```js
3785 * const frameElement = await frame.frameElement();
3786 * const contentFrame = await frameElement.contentFrame();
3787 * console.log(frame === contentFrame); // -> true
3788 * ```
3789 *
3790 */
3791 frameElement(): Promise<ElementHandle>;
3792
3793 /**
3794 * Returns element attribute value.
3795 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3796 * @param name Attribute name to get the value for.
3797 * @param options
3798 */
3799 getAttribute(selector: string, name: string, options?: {
3800 /**
3801 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3802 * using the
3803 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3804 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3805 */
3806 timeout?: number;
3807 }): Promise<null|string>;
3808
3809 /**
3810 * Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
3811 * last redirect.
3812 *
3813 * `frame.goto` will throw an error if:
3814 * - there's an SSL error (e.g. in case of self-signed certificates).
3815 * - target URL is invalid.
3816 * - the `timeout` is exceeded during navigation.
3817 * - the remote server does not respond or is unreachable.
3818 * - the main resource failed to load.
3819 *
3820 * `frame.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404
3821 * "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
3822 * [response.status()](https://playwright.dev/docs/api/class-response#responsestatus).
3823 *
3824 * > NOTE: `frame.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
3825 * `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
3826 * > NOTE: Headless mode doesn't support navigation to a PDF document. See the
3827 * [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
3828 * @param url URL to navigate frame to. The url should include scheme, e.g. `https://`.
3829 * @param options
3830 */
3831 goto(url: string, options?: {
3832 /**
3833 * Referer header value. If provided it will take preference over the referer header value set by
3834 * [page.setExtraHTTPHeaders(headers)](https://playwright.dev/docs/api/class-page#pagesetextrahttpheadersheaders).
3835 */
3836 referer?: string;
3837
3838 /**
3839 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
3840 * changed by using the
3841 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
3842 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
3843 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
3844 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3845 */
3846 timeout?: number;
3847
3848 /**
3849 * When to consider operation succeeded, defaults to `load`. Events can be either:
3850 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
3851 * - `'load'` - consider operation to be finished when the `load` event is fired.
3852 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
3853 */
3854 waitUntil?: "load"|"domcontentloaded"|"networkidle";
3855 }): Promise<null|Response>;
3856
3857 /**
3858 * This method hovers over an element matching `selector` by performing the following steps:
3859 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
3860 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
3861 * element is detached during the checks, the whole action is retried.
3862 * 1. Scroll the element into view if needed.
3863 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to hover over the center of the element, or
3864 * the specified `position`.
3865 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
3866 *
3867 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
3868 * Passing zero timeout disables this.
3869 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3870 * @param options
3871 */
3872 hover(selector: string, options?: {
3873 /**
3874 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
3875 */
3876 force?: boolean;
3877
3878 /**
3879 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
3880 * modifiers back. If not specified, currently pressed modifiers are used.
3881 */
3882 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
3883
3884 /**
3885 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
3886 * element.
3887 */
3888 position?: {
3889 x: number;
3890
3891 y: number;
3892 };
3893
3894 /**
3895 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3896 * using the
3897 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3898 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3899 */
3900 timeout?: number;
3901 }): Promise<void>;
3902
3903 /**
3904 * Returns `element.innerHTML`.
3905 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3906 * @param options
3907 */
3908 innerHTML(selector: string, options?: {
3909 /**
3910 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3911 * using the
3912 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3913 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3914 */
3915 timeout?: number;
3916 }): Promise<string>;
3917
3918 /**
3919 * Returns `element.innerText`.
3920 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3921 * @param options
3922 */
3923 innerText(selector: string, options?: {
3924 /**
3925 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3926 * using the
3927 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3928 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3929 */
3930 timeout?: number;
3931 }): Promise<string>;
3932
3933 /**
3934 * Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
3935 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3936 * @param options
3937 */
3938 isChecked(selector: string, options?: {
3939 /**
3940 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3941 * using the
3942 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3943 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3944 */
3945 timeout?: number;
3946 }): Promise<boolean>;
3947
3948 /**
3949 * Returns `true` if the frame has been detached, or `false` otherwise.
3950 */
3951 isDetached(): boolean;
3952
3953 /**
3954 * Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/docs/actionability#enabled).
3955 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3956 * @param options
3957 */
3958 isDisabled(selector: string, options?: {
3959 /**
3960 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3961 * using the
3962 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3963 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3964 */
3965 timeout?: number;
3966 }): Promise<boolean>;
3967
3968 /**
3969 * Returns whether the element is [editable](https://playwright.dev/docs/actionability#editable).
3970 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3971 * @param options
3972 */
3973 isEditable(selector: string, options?: {
3974 /**
3975 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3976 * using the
3977 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3978 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3979 */
3980 timeout?: number;
3981 }): Promise<boolean>;
3982
3983 /**
3984 * Returns whether the element is [enabled](https://playwright.dev/docs/actionability#enabled).
3985 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
3986 * @param options
3987 */
3988 isEnabled(selector: string, options?: {
3989 /**
3990 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
3991 * using the
3992 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
3993 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
3994 */
3995 timeout?: number;
3996 }): Promise<boolean>;
3997
3998 /**
3999 * Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not
4000 * match any elements is considered hidden.
4001 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4002 * @param options
4003 */
4004 isHidden(selector: string, options?: {
4005 /**
4006 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4007 * using the
4008 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4009 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4010 */
4011 timeout?: number;
4012 }): Promise<boolean>;
4013
4014 /**
4015 * Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible). `selector` that does not match any elements is
4016 * considered not visible.
4017 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4018 * @param options
4019 */
4020 isVisible(selector: string, options?: {
4021 /**
4022 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4023 * using the
4024 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4025 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4026 */
4027 timeout?: number;
4028 }): Promise<boolean>;
4029
4030 /**
4031 * Returns frame's name attribute as specified in the tag.
4032 *
4033 * If the name is empty, returns the id attribute instead.
4034 *
4035 * > NOTE: This value is calculated once when the frame is created, and will not update if the attribute is changed later.
4036 */
4037 name(): string;
4038
4039 /**
4040 * Returns the page containing this frame.
4041 */
4042 page(): Page;
4043
4044 /**
4045 * Parent frame, if any. Detached frames and main frames return `null`.
4046 */
4047 parentFrame(): null|Frame;
4048
4049 /**
4050 * `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
4051 * value or a single character to generate the text for. A superset of the `key` values can be found
4052 * [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
4053 *
4054 * `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
4055 * `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
4056 *
4057 * Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
4058 *
4059 * Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
4060 *
4061 * If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
4062 * texts.
4063 *
4064 * Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
4065 * modifier, modifier is pressed and being held while the subsequent key is being pressed.
4066 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4067 * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
4068 * @param options
4069 */
4070 press(selector: string, key: string, options?: {
4071 /**
4072 * Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
4073 */
4074 delay?: number;
4075
4076 /**
4077 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
4078 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
4079 * inaccessible pages. Defaults to `false`.
4080 */
4081 noWaitAfter?: boolean;
4082
4083 /**
4084 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4085 * using the
4086 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4087 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4088 */
4089 timeout?: number;
4090 }): Promise<void>;
4091
4092 /**
4093 * Returns the array of option values that have been successfully selected.
4094 *
4095 * Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element
4096 * matching `selector`, the method throws an error.
4097 *
4098 * Will wait until all specified options are present in the `<select>` element.
4099 *
4100 * ```js
4101 * // single selection matching the value
4102 * frame.selectOption('select#colors', 'blue');
4103 *
4104 * // single selection matching both the value and the label
4105 * frame.selectOption('select#colors', { label: 'Blue' });
4106 *
4107 * // multiple selection
4108 * frame.selectOption('select#colors', 'red', 'green', 'blue');
4109 * ```
4110 *
4111 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4112 * @param values Options to select. If the `<select>` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option
4113 * is considered matching if all specified properties match.
4114 * @param options
4115 */
4116 selectOption(selector: string, values: null|string|ElementHandle|Array<string>|{
4117 /**
4118 * Matches by `option.value`. Optional.
4119 */
4120 value?: string;
4121
4122 /**
4123 * Matches by `option.label`. Optional.
4124 */
4125 label?: string;
4126
4127 /**
4128 * Matches by the index. Optional.
4129 */
4130 index?: number;
4131 }|Array<ElementHandle>|Array<{
4132 /**
4133 * Matches by `option.value`. Optional.
4134 */
4135 value?: string;
4136
4137 /**
4138 * Matches by `option.label`. Optional.
4139 */
4140 label?: string;
4141
4142 /**
4143 * Matches by the index. Optional.
4144 */
4145 index?: number;
4146 }>, options?: {
4147 /**
4148 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
4149 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
4150 * inaccessible pages. Defaults to `false`.
4151 */
4152 noWaitAfter?: boolean;
4153
4154 /**
4155 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4156 * using the
4157 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4158 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4159 */
4160 timeout?: number;
4161 }): Promise<Array<string>>;
4162
4163 /**
4164 * @param html HTML markup to assign to the page.
4165 * @param options
4166 */
4167 setContent(html: string, options?: {
4168 /**
4169 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
4170 * changed by using the
4171 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
4172 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
4173 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
4174 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4175 */
4176 timeout?: number;
4177
4178 /**
4179 * When to consider operation succeeded, defaults to `load`. Events can be either:
4180 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
4181 * - `'load'` - consider operation to be finished when the `load` event is fired.
4182 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
4183 */
4184 waitUntil?: "load"|"domcontentloaded"|"networkidle";
4185 }): Promise<void>;
4186
4187 /**
4188 * This method expects `selector` to point to an
4189 * [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
4190 *
4191 * Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
4192 * are resolved relative to the the current working directory. For empty array, clears the selected files.
4193 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4194 * @param files
4195 * @param options
4196 */
4197 setInputFiles(selector: string, files: string|Array<string>|{
4198 /**
4199 * File name
4200 */
4201 name: string;
4202
4203 /**
4204 * File type
4205 */
4206 mimeType: string;
4207
4208 /**
4209 * File content
4210 */
4211 buffer: Buffer;
4212 }|Array<{
4213 /**
4214 * File name
4215 */
4216 name: string;
4217
4218 /**
4219 * File type
4220 */
4221 mimeType: string;
4222
4223 /**
4224 * File content
4225 */
4226 buffer: Buffer;
4227 }>, options?: {
4228 /**
4229 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
4230 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
4231 * inaccessible pages. Defaults to `false`.
4232 */
4233 noWaitAfter?: boolean;
4234
4235 /**
4236 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4237 * using the
4238 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4239 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4240 */
4241 timeout?: number;
4242 }): Promise<void>;
4243
4244 /**
4245 * This method taps an element matching `selector` by performing the following steps:
4246 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
4247 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
4248 * element is detached during the checks, the whole action is retried.
4249 * 1. Scroll the element into view if needed.
4250 * 1. Use [page.touchscreen](https://playwright.dev/docs/api/class-page#pagetouchscreen) to tap the center of the
4251 * element, or the specified `position`.
4252 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
4253 *
4254 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
4255 * Passing zero timeout disables this.
4256 *
4257 * > NOTE: `frame.tap()` requires that the `hasTouch` option of the browser context be set to true.
4258 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4259 * @param options
4260 */
4261 tap(selector: string, options?: {
4262 /**
4263 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
4264 */
4265 force?: boolean;
4266
4267 /**
4268 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
4269 * modifiers back. If not specified, currently pressed modifiers are used.
4270 */
4271 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
4272
4273 /**
4274 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
4275 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
4276 * inaccessible pages. Defaults to `false`.
4277 */
4278 noWaitAfter?: boolean;
4279
4280 /**
4281 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
4282 * element.
4283 */
4284 position?: {
4285 x: number;
4286
4287 y: number;
4288 };
4289
4290 /**
4291 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4292 * using the
4293 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4294 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4295 */
4296 timeout?: number;
4297 }): Promise<void>;
4298
4299 /**
4300 * Returns `element.textContent`.
4301 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4302 * @param options
4303 */
4304 textContent(selector: string, options?: {
4305 /**
4306 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4307 * using the
4308 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4309 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4310 */
4311 timeout?: number;
4312 }): Promise<null|string>;
4313
4314 /**
4315 * Returns the page title.
4316 */
4317 title(): Promise<string>;
4318
4319 /**
4320 * Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `frame.type` can be used to
4321 * send fine-grained keyboard events. To fill values in form fields, use
4322 * [frame.fill(selector, value[, options])](https://playwright.dev/docs/api/class-frame#framefillselector-value-options).
4323 *
4324 * To press a special key, like `Control` or `ArrowDown`, use
4325 * [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboardpresskey-options).
4326 *
4327 * ```js
4328 * await frame.type('#mytextarea', 'Hello'); // Types instantly
4329 * await frame.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
4330 * ```
4331 *
4332 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4333 * @param text A text to type into a focused element.
4334 * @param options
4335 */
4336 type(selector: string, text: string, options?: {
4337 /**
4338 * Time to wait between key presses in milliseconds. Defaults to 0.
4339 */
4340 delay?: number;
4341
4342 /**
4343 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
4344 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
4345 * inaccessible pages. Defaults to `false`.
4346 */
4347 noWaitAfter?: boolean;
4348
4349 /**
4350 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4351 * using the
4352 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4353 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4354 */
4355 timeout?: number;
4356 }): Promise<void>;
4357
4358 /**
4359 * This method checks an element matching `selector` by performing the following steps:
4360 * 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
4361 * 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
4362 * unchecked, this method returns immediately.
4363 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the matched element, unless `force` option is set. If the
4364 * element is detached during the checks, the whole action is retried.
4365 * 1. Scroll the element into view if needed.
4366 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element.
4367 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
4368 * 1. Ensure that the element is now unchecked. If not, this method rejects.
4369 *
4370 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
4371 * Passing zero timeout disables this.
4372 * @param selector A selector to search for element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
4373 * @param options
4374 */
4375 uncheck(selector: string, options?: {
4376 /**
4377 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
4378 */
4379 force?: boolean;
4380
4381 /**
4382 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
4383 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
4384 * inaccessible pages. Defaults to `false`.
4385 */
4386 noWaitAfter?: boolean;
4387
4388 /**
4389 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
4390 * using the
4391 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
4392 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4393 */
4394 timeout?: number;
4395 }): Promise<void>;
4396
4397 /**
4398 * Returns frame's url.
4399 */
4400 url(): string;
4401
4402 /**
4403 * Waits for the required load state to be reached.
4404 *
4405 * This returns when the frame reaches a required load state, `load` by default. The navigation must have been committed
4406 * when this method is called. If current document has already reached the required state, resolves immediately.
4407 *
4408 * ```js
4409 * await frame.click('button'); // Click triggers navigation.
4410 * await frame.waitForLoadState(); // Waits for 'load' state by default.
4411 * ```
4412 *
4413 * @param state Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately. Can be one of:
4414 * - `'load'` - wait for the `load` event to be fired.
4415 * - `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
4416 * - `'networkidle'` - wait until there are no network connections for at least `500` ms.
4417 * @param options
4418 */
4419 waitForLoadState(state?: "load"|"domcontentloaded"|"networkidle", options?: {
4420 /**
4421 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
4422 * changed by using the
4423 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
4424 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
4425 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
4426 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4427 */
4428 timeout?: number;
4429 }): Promise<void>;
4430
4431 /**
4432 * Waits for the frame navigation and returns the main resource response. In case of multiple redirects, the navigation
4433 * will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to
4434 * History API usage, the navigation will resolve with `null`.
4435 *
4436 * This method waits for the frame to navigate to a new URL. It is useful for when you run code which will indirectly cause
4437 * the frame to navigate. Consider this example:
4438 *
4439 * ```js
4440 * const [response] = await Promise.all([
4441 * frame.waitForNavigation(), // The promise resolves after navigation has finished
4442 * frame.click('a.delayed-navigation'), // Clicking the link will indirectly cause a navigation
4443 * ]);
4444 * ```
4445 *
4446 * > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
4447 * considered a navigation.
4448 * @param options
4449 */
4450 waitForNavigation(options?: {
4451 /**
4452 * Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be
4453 * changed by using the
4454 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout),
4455 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout),
4456 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
4457 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
4458 */
4459 timeout?: number;
4460
4461 /**
4462 * A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation.
4463 */
4464 url?: string|RegExp|((url: URL) => boolean);
4465
4466 /**
4467 * When to consider operation succeeded, defaults to `load`. Events can be either:
4468 * - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
4469 * - `'load'` - consider operation to be finished when the `load` event is fired.
4470 * - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms.
4471 */
4472 waitUntil?: "load"|"domcontentloaded"|"networkidle";
4473 }): Promise<null|Response>;
4474
4475 /**
4476 * Waits for the given `timeout` in milliseconds.
4477 *
4478 * Note that `frame.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to
4479 * be flaky. Use signals such as network events, selectors becoming visible and others instead.
4480 * @param timeout A timeout to wait for
4481 */
4482 waitForTimeout(timeout: number): Promise<void>;}
4483
4484/**
4485 * - extends: [EventEmitter]
4486 *
4487 * BrowserContexts provide a way to operate multiple independent browser sessions.
4488 *
4489 * If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser
4490 * context.
4491 *
4492 * Playwright allows creation of "incognito" browser contexts with `browser.newContext()` method. "Incognito" browser
4493 * contexts don't write any browsing data to disk.
4494 *
4495 * ```js
4496 * // Create a new incognito browser context
4497 * const context = await browser.newContext();
4498 * // Create a new page inside context.
4499 * const page = await context.newPage();
4500 * await page.goto('https://example.com');
4501 * // Dispose context once it's no longer needed.
4502 * await context.close();
4503 * ```
4504 *
4505 */
4506export interface BrowserContext {
4507 /**
4508 * The method adds a function called `name` on the `window` object of every frame in every page in the context. When
4509 * called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If
4510 * the `callback` returns a [Promise], it will be awaited.
4511 *
4512 * The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
4513 * page: Page, frame: Frame }`.
4514 *
4515 * See
4516 * [page.exposeBinding(name, callback[, options])](https://playwright.dev/docs/api/class-page#pageexposebindingname-callback-options)
4517 * for page-only version.
4518 *
4519 * An example of exposing page URL to all frames in all pages in the context:
4520 *
4521 * ```js
4522 * const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
4523 *
4524 * (async () => {
4525 * const browser = await webkit.launch({ headless: false });
4526 * const context = await browser.newContext();
4527 * await context.exposeBinding('pageURL', ({ page }) => page.url());
4528 * const page = await context.newPage();
4529 * await page.setContent(`
4530 * <script>
4531 * async function onClick() {
4532 * document.querySelector('div').textContent = await window.pageURL();
4533 * }
4534 * </script>
4535 * <button onclick="onClick()">Click me</button>
4536 * <div></div>
4537 * `);
4538 * await page.click('button');
4539 * })();
4540 * ```
4541 *
4542 * An example of passing an element handle:
4543 *
4544 * ```js
4545 * await context.exposeBinding('clicked', async (source, element) => {
4546 * console.log(await element.textContent());
4547 * }, { handle: true });
4548 * await page.setContent(`
4549 * <script>
4550 * document.addEventListener('click', event => window.clicked(event.target));
4551 * </script>
4552 * <div>Click me</div>
4553 * <div>Or click me</div>
4554 * `);
4555 * ```
4556 *
4557 * @param name Name of the function on the window object.
4558 * @param callback Callback function that will be called in the Playwright's context.
4559 * @param options
4560 */
4561 exposeBinding(name: string, playwrightBinding: (source: BindingSource, arg: JSHandle) => any, options: { handle: true }): Promise<void>;
4562 exposeBinding(name: string, playwrightBinding: (source: BindingSource, ...args: any[]) => any, options?: { handle?: boolean }): Promise<void>;
4563 /**
4564 * Emitted when Browser context gets closed. This might happen because of one of the following:
4565 * - Browser context is closed.
4566 * - Browser application is closed or crashed.
4567 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
4568 */
4569 on(event: 'close', listener: (browserContext: BrowserContext) => void): this;
4570
4571 /**
4572 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
4573 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
4574 * receive events about popups relevant to a specific page.
4575 *
4576 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
4577 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
4578 * done and its response has started loading in the popup.
4579 *
4580 * ```js
4581 * const [newPage] = await Promise.all([
4582 * context.waitForEvent('page'),
4583 * page.click('a[target=_blank]'),
4584 * ]);
4585 * console.log(await newPage.evaluate('location.href'));
4586 * ```
4587 *
4588 * > NOTE: Use
4589 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
4590 * to wait until the page gets to a particular state (you should not need it in most cases).
4591 */
4592 on(event: 'page', listener: (page: Page) => void): this;
4593
4594 /**
4595 * Emitted when Browser context gets closed. This might happen because of one of the following:
4596 * - Browser context is closed.
4597 * - Browser application is closed or crashed.
4598 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
4599 */
4600 once(event: 'close', listener: (browserContext: BrowserContext) => void): this;
4601
4602 /**
4603 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
4604 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
4605 * receive events about popups relevant to a specific page.
4606 *
4607 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
4608 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
4609 * done and its response has started loading in the popup.
4610 *
4611 * ```js
4612 * const [newPage] = await Promise.all([
4613 * context.waitForEvent('page'),
4614 * page.click('a[target=_blank]'),
4615 * ]);
4616 * console.log(await newPage.evaluate('location.href'));
4617 * ```
4618 *
4619 * > NOTE: Use
4620 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
4621 * to wait until the page gets to a particular state (you should not need it in most cases).
4622 */
4623 once(event: 'page', listener: (page: Page) => void): this;
4624
4625 /**
4626 * Emitted when Browser context gets closed. This might happen because of one of the following:
4627 * - Browser context is closed.
4628 * - Browser application is closed or crashed.
4629 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
4630 */
4631 addListener(event: 'close', listener: (browserContext: BrowserContext) => void): this;
4632
4633 /**
4634 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
4635 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
4636 * receive events about popups relevant to a specific page.
4637 *
4638 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
4639 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
4640 * done and its response has started loading in the popup.
4641 *
4642 * ```js
4643 * const [newPage] = await Promise.all([
4644 * context.waitForEvent('page'),
4645 * page.click('a[target=_blank]'),
4646 * ]);
4647 * console.log(await newPage.evaluate('location.href'));
4648 * ```
4649 *
4650 * > NOTE: Use
4651 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
4652 * to wait until the page gets to a particular state (you should not need it in most cases).
4653 */
4654 addListener(event: 'page', listener: (page: Page) => void): this;
4655
4656 /**
4657 * Emitted when Browser context gets closed. This might happen because of one of the following:
4658 * - Browser context is closed.
4659 * - Browser application is closed or crashed.
4660 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
4661 */
4662 removeListener(event: 'close', listener: (browserContext: BrowserContext) => void): this;
4663
4664 /**
4665 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
4666 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
4667 * receive events about popups relevant to a specific page.
4668 *
4669 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
4670 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
4671 * done and its response has started loading in the popup.
4672 *
4673 * ```js
4674 * const [newPage] = await Promise.all([
4675 * context.waitForEvent('page'),
4676 * page.click('a[target=_blank]'),
4677 * ]);
4678 * console.log(await newPage.evaluate('location.href'));
4679 * ```
4680 *
4681 * > NOTE: Use
4682 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
4683 * to wait until the page gets to a particular state (you should not need it in most cases).
4684 */
4685 removeListener(event: 'page', listener: (page: Page) => void): this;
4686
4687 /**
4688 * Emitted when Browser context gets closed. This might happen because of one of the following:
4689 * - Browser context is closed.
4690 * - Browser application is closed or crashed.
4691 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
4692 */
4693 off(event: 'close', listener: (browserContext: BrowserContext) => void): this;
4694
4695 /**
4696 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
4697 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
4698 * receive events about popups relevant to a specific page.
4699 *
4700 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
4701 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
4702 * done and its response has started loading in the popup.
4703 *
4704 * ```js
4705 * const [newPage] = await Promise.all([
4706 * context.waitForEvent('page'),
4707 * page.click('a[target=_blank]'),
4708 * ]);
4709 * console.log(await newPage.evaluate('location.href'));
4710 * ```
4711 *
4712 * > NOTE: Use
4713 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
4714 * to wait until the page gets to a particular state (you should not need it in most cases).
4715 */
4716 off(event: 'page', listener: (page: Page) => void): this;
4717
4718 /**
4719 * Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
4720 * obtained via
4721 * [browserContext.cookies([urls])](https://playwright.dev/docs/api/class-browsercontext#browsercontextcookiesurls).
4722 *
4723 * ```js
4724 * await browserContext.addCookies([cookieObject1, cookieObject2]);
4725 * ```
4726 *
4727 * @param cookies
4728 */
4729 addCookies(cookies: Array<{
4730 name: string;
4731
4732 value: string;
4733
4734 /**
4735 * either url or domain / path are required. Optional.
4736 */
4737 url?: string;
4738
4739 /**
4740 * either url or domain / path are required Optional.
4741 */
4742 domain?: string;
4743
4744 /**
4745 * either url or domain / path are required Optional.
4746 */
4747 path?: string;
4748
4749 /**
4750 * Unix time in seconds. Optional.
4751 */
4752 expires?: number;
4753
4754 /**
4755 * Optional.
4756 */
4757 httpOnly?: boolean;
4758
4759 /**
4760 * Optional.
4761 */
4762 secure?: boolean;
4763
4764 /**
4765 * Optional.
4766 */
4767 sameSite?: "Strict"|"Lax"|"None";
4768 }>): Promise<void>;
4769
4770 /**
4771 * Adds a script which would be evaluated in one of the following scenarios:
4772 * - Whenever a page is created in the browser context or is navigated.
4773 * - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
4774 * evaluated in the context of the newly attached frame.
4775 *
4776 * The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
4777 * the JavaScript environment, e.g. to seed `Math.random`.
4778 *
4779 * An example of overriding `Math.random` before the page loads:
4780 *
4781 * ```js browser
4782 * // preload.js
4783 * Math.random = () => 42;
4784 * ```
4785 *
4786 * ```js
4787 * // In your playwright script, assuming the preload.js file is in same directory.
4788 * await browserContext.addInitScript({
4789 * path: 'preload.js'
4790 * });
4791 * ```
4792 *
4793 * > NOTE: The order of evaluation of multiple scripts installed via
4794 * [browserContext.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-browsercontext#browsercontextaddinitscriptscript-arg)
4795 * and [page.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-page#pageaddinitscriptscript-arg) is not
4796 * defined.
4797 * @param script Script to be evaluated in all pages in the browser context.
4798 * @param arg Optional argument to pass to `script` (only supported when passing a function).
4799 */
4800 addInitScript(script: Function|string|{
4801 /**
4802 * Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working
4803 * directory. Optional.
4804 */
4805 path?: string;
4806
4807 /**
4808 * Raw script content. Optional.
4809 */
4810 content?: string;
4811 }, arg?: Serializable): Promise<void>;
4812
4813 /**
4814 * Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
4815 */
4816 browser(): null|Browser;
4817
4818 /**
4819 * Clears context cookies.
4820 */
4821 clearCookies(): Promise<void>;
4822
4823 /**
4824 * Clears all permission overrides for the browser context.
4825 *
4826 * ```js
4827 * const context = await browser.newContext();
4828 * await context.grantPermissions(['clipboard-read']);
4829 * // do stuff ..
4830 * context.clearPermissions();
4831 * ```
4832 *
4833 */
4834 clearPermissions(): Promise<void>;
4835
4836 /**
4837 * Closes the browser context. All the pages that belong to the browser context will be closed.
4838 *
4839 * > NOTE: The default browser context cannot be closed.
4840 */
4841 close(): Promise<void>;
4842
4843 /**
4844 * If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
4845 * are returned.
4846 * @param urls Optional list of URLs.
4847 */
4848 cookies(urls?: string|Array<string>): Promise<Array<Cookie>>;
4849
4850 /**
4851 * The method adds a function called `name` on the `window` object of every frame in every page in the context. When
4852 * called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
4853 *
4854 * If the `callback` returns a [Promise], it will be awaited.
4855 *
4856 * See [page.exposeFunction(name, callback)](https://playwright.dev/docs/api/class-page#pageexposefunctionname-callback)
4857 * for page-only version.
4858 *
4859 * An example of adding an `md5` function to all pages in the context:
4860 *
4861 * ```js
4862 * const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
4863 * const crypto = require('crypto');
4864 *
4865 * (async () => {
4866 * const browser = await webkit.launch({ headless: false });
4867 * const context = await browser.newContext();
4868 * await context.exposeFunction('md5', text => crypto.createHash('md5').update(text).digest('hex'));
4869 * const page = await context.newPage();
4870 * await page.setContent(`
4871 * <script>
4872 * async function onClick() {
4873 * document.querySelector('div').textContent = await window.md5('PLAYWRIGHT');
4874 * }
4875 * </script>
4876 * <button onclick="onClick()">Click me</button>
4877 * <div></div>
4878 * `);
4879 * await page.click('button');
4880 * })();
4881 * ```
4882 *
4883 * @param name Name of the function on the window object.
4884 * @param callback Callback function that will be called in the Playwright's context.
4885 */
4886 exposeFunction(name: string, callback: Function): Promise<void>;
4887
4888 /**
4889 * Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
4890 * specified.
4891 * @param permissions A permission or an array of permissions to grant. Permissions can be one of the following values: - `'geolocation'`
4892 * - `'midi'`
4893 * - `'midi-sysex'` (system-exclusive midi)
4894 * - `'notifications'`
4895 * - `'push'`
4896 * - `'camera'`
4897 * - `'microphone'`
4898 * - `'background-sync'`
4899 * - `'ambient-light-sensor'`
4900 * - `'accelerometer'`
4901 * - `'gyroscope'`
4902 * - `'magnetometer'`
4903 * - `'accessibility-events'`
4904 * - `'clipboard-read'`
4905 * - `'clipboard-write'`
4906 * - `'payment-handler'`
4907 * @param options
4908 */
4909 grantPermissions(permissions: Array<string>, options?: {
4910 /**
4911 * The [origin] to grant permissions to, e.g. "https://example.com".
4912 */
4913 origin?: string;
4914 }): Promise<void>;
4915
4916 /**
4917 * Creates a new page in the browser context.
4918 */
4919 newPage(): Promise<Page>;
4920
4921 /**
4922 * Returns all open pages in the context.
4923 */
4924 pages(): Array<Page>;
4925
4926 /**
4927 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
4928 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
4929 *
4930 * An example of a naïve handler that aborts all image requests:
4931 *
4932 * ```js
4933 * const context = await browser.newContext();
4934 * await context.route('**\/*.{png,jpg,jpeg}', route => route.abort());
4935 * const page = await context.newPage();
4936 * await page.goto('https://example.com');
4937 * await browser.close();
4938 * ```
4939 *
4940 * or the same snippet using a regex pattern instead:
4941 *
4942 * ```js
4943 * const context = await browser.newContext();
4944 * await context.route(/(\.png$)|(\.jpg$)/, route => route.abort());
4945 * const page = await context.newPage();
4946 * await page.goto('https://example.com');
4947 * await browser.close();
4948 * ```
4949 *
4950 * Page routes (set up with [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler))
4951 * take precedence over browser context routes when request matches both handlers.
4952 *
4953 * > NOTE: Enabling routing disables http cache.
4954 * @param url A glob pattern, regex pattern or predicate receiving [URL] to match while routing.
4955 * @param handler handler function to route the request.
4956 */
4957 route(url: string|RegExp|((url: URL) => boolean), handler: ((route: Route, request: Request) => void)): Promise<void>;
4958
4959 /**
4960 * This setting will change the default maximum navigation time for the following methods and related shortcuts:
4961 * - [page.goBack([options])](https://playwright.dev/docs/api/class-page#pagegobackoptions)
4962 * - [page.goForward([options])](https://playwright.dev/docs/api/class-page#pagegoforwardoptions)
4963 * - [page.goto(url[, options])](https://playwright.dev/docs/api/class-page#pagegotourl-options)
4964 * - [page.reload([options])](https://playwright.dev/docs/api/class-page#pagereloadoptions)
4965 * - [page.setContent(html[, options])](https://playwright.dev/docs/api/class-page#pagesetcontenthtml-options)
4966 * - [page.waitForNavigation([options])](https://playwright.dev/docs/api/class-page#pagewaitfornavigationoptions)
4967 *
4968 * > NOTE:
4969 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout)
4970 * and [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) take
4971 * priority over
4972 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout).
4973 * @param timeout Maximum navigation time in milliseconds
4974 */
4975 setDefaultNavigationTimeout(timeout: number): void;
4976
4977 /**
4978 * This setting will change the default maximum time for all the methods accepting `timeout` option.
4979 *
4980 * > NOTE:
4981 * [page.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaultnavigationtimeouttimeout),
4982 * [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) and
4983 * [browserContext.setDefaultNavigationTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaultnavigationtimeouttimeout)
4984 * take priority over
4985 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout).
4986 * @param timeout Maximum time in milliseconds
4987 */
4988 setDefaultTimeout(timeout: number): void;
4989
4990 /**
4991 * The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
4992 * with page-specific extra HTTP headers set with
4993 * [page.setExtraHTTPHeaders(headers)](https://playwright.dev/docs/api/class-page#pagesetextrahttpheadersheaders). If page
4994 * overrides a particular header, page-specific header value will be used instead of the browser context header value.
4995 *
4996 * > NOTE:
4997 * [browserContext.setExtraHTTPHeaders(headers)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetextrahttpheadersheaders)
4998 * does not guarantee the order of headers in the outgoing requests.
4999 * @param headers An object containing additional HTTP headers to be sent with every request. All header values must be strings.
5000 */
5001 setExtraHTTPHeaders(headers: { [key: string]: string; }): Promise<void>;
5002
5003 /**
5004 * Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
5005 *
5006 * ```js
5007 * await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});
5008 * ```
5009 *
5010 * > NOTE: Consider using
5011 * [browserContext.grantPermissions(permissions[, options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextgrantpermissionspermissions-options)
5012 * to grant permissions for the browser context pages to read its geolocation.
5013 * @param geolocation
5014 */
5015 setGeolocation(geolocation: null|{
5016 /**
5017 * Latitude between -90 and 90.
5018 */
5019 latitude: number;
5020
5021 /**
5022 * Longitude between -180 and 180.
5023 */
5024 longitude: number;
5025
5026 /**
5027 * Non-negative accuracy value. Defaults to `0`.
5028 */
5029 accuracy?: number;
5030 }): Promise<void>;
5031
5032 /**
5033 * **DEPRECATED** Browsers may cache credentials after successful authentication. Create a new browser context instead.
5034 * @deprecated
5035 * @param httpCredentials
5036 */
5037 setHTTPCredentials(httpCredentials: null|{
5038 username: string;
5039
5040 password: string;
5041 }): Promise<void>;
5042
5043 /**
5044 * @param offline Whether to emulate network being offline for the browser context.
5045 */
5046 setOffline(offline: boolean): Promise<void>;
5047
5048 /**
5049 * Returns storage state for this browser context, contains current cookies and local storage snapshot.
5050 * @param options
5051 */
5052 storageState(options?: {
5053 /**
5054 * The file path to save the storage state to. If `path` is a relative path, then it is resolved relative to current
5055 * working directory. If no path is provided, storage state is still returned, but won't be saved to the disk.
5056 */
5057 path?: string;
5058 }): Promise<{
5059 cookies: Array<{
5060 name: string;
5061
5062 value: string;
5063
5064 domain: string;
5065
5066 path: string;
5067
5068 /**
5069 * Unix time in seconds.
5070 */
5071 expires: number;
5072
5073 httpOnly: boolean;
5074
5075 secure: boolean;
5076
5077 sameSite: "Strict"|"Lax"|"None";
5078 }>;
5079
5080 origins: Array<{
5081 origin: string;
5082
5083 localStorage: Array<{
5084 name: string;
5085
5086 value: string;
5087 }>;
5088 }>;
5089 }>;
5090
5091 /**
5092 * Removes a route created with
5093 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
5094 * When `handler` is not specified, removes all routes for the `url`.
5095 * @param url A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
5096 * @param handler Optional handler function used to register a routing with [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler).
5097 */
5098 unroute(url: string|RegExp|((url: URL) => boolean), handler?: ((route: Route, request: Request) => void)): Promise<void>;
5099
5100 /**
5101 * Emitted when Browser context gets closed. This might happen because of one of the following:
5102 * - Browser context is closed.
5103 * - Browser application is closed or crashed.
5104 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
5105 */
5106 waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (browserContext: BrowserContext) => boolean, timeout?: number } | ((browserContext: BrowserContext) => boolean)): Promise<BrowserContext>;
5107
5108 /**
5109 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
5110 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
5111 * receive events about popups relevant to a specific page.
5112 *
5113 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
5114 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
5115 * done and its response has started loading in the popup.
5116 *
5117 * ```js
5118 * const [newPage] = await Promise.all([
5119 * context.waitForEvent('page'),
5120 * page.click('a[target=_blank]'),
5121 * ]);
5122 * console.log(await newPage.evaluate('location.href'));
5123 * ```
5124 *
5125 * > NOTE: Use
5126 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
5127 * to wait until the page gets to a particular state (you should not need it in most cases).
5128 */
5129 waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
5130}
5131
5132/**
5133 * The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). `worker`
5134 * event is emitted on the page object to signal a worker creation. `close` event is emitted on the worker object when the
5135 * worker is gone.
5136 *
5137 * ```js
5138 * page.on('worker', worker => {
5139 * console.log('Worker created: ' + worker.url());
5140 * worker.on('close', worker => console.log('Worker destroyed: ' + worker.url()));
5141 * });
5142 *
5143 * console.log('Current workers:');
5144 * for (const worker of page.workers())
5145 * console.log(' ' + worker.url());
5146 * ```
5147 *
5148 */
5149export interface Worker {
5150 /**
5151 * Returns the return value of `pageFunction`.
5152 *
5153 * If the function passed to the
5154 * [worker.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatepagefunction-arg)
5155 * returns a [Promise], then
5156 * [worker.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatepagefunction-arg)
5157 * would wait for the promise to resolve and return its value.
5158 *
5159 * If the function passed to the
5160 * [worker.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatepagefunction-arg)
5161 * returns a non-[Serializable] value, then
5162 * [worker.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatepagefunction-arg)
5163 * returns `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:
5164 * `-0`, `NaN`, `Infinity`, `-Infinity`.
5165 * @param pageFunction Function to be evaluated in the worker context.
5166 * @param arg Optional argument to pass to `pageFunction`.
5167 */
5168 evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<R>;
5169 evaluate<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<R>;
5170
5171 /**
5172 * Returns the return value of `pageFunction` as a [JSHandle].
5173 *
5174 * The only difference between
5175 * [worker.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatepagefunction-arg) and
5176 * [worker.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatehandlepagefunction-arg)
5177 * is that
5178 * [worker.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatehandlepagefunction-arg)
5179 * returns [JSHandle].
5180 *
5181 * If the function passed to the
5182 * [worker.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatehandlepagefunction-arg)
5183 * returns a [Promise], then
5184 * [worker.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-worker#workerevaluatehandlepagefunction-arg)
5185 * would wait for the promise to resolve and return its value.
5186 * @param pageFunction Function to be evaluated in the worker context.
5187 * @param arg Optional argument to pass to `pageFunction`.
5188 */
5189 evaluateHandle<R, Arg>(pageFunction: PageFunction<Arg, R>, arg: Arg): Promise<SmartHandle<R>>;
5190 evaluateHandle<R>(pageFunction: PageFunction<void, R>, arg?: any): Promise<SmartHandle<R>>;
5191 /**
5192 * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is terminated.
5193 */
5194 on(event: 'close', listener: (worker: Worker) => void): this;
5195
5196 /**
5197 * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is terminated.
5198 */
5199 once(event: 'close', listener: (worker: Worker) => void): this;
5200
5201 /**
5202 * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is terminated.
5203 */
5204 addListener(event: 'close', listener: (worker: Worker) => void): this;
5205
5206 /**
5207 * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is terminated.
5208 */
5209 removeListener(event: 'close', listener: (worker: Worker) => void): this;
5210
5211 /**
5212 * Emitted when this dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is terminated.
5213 */
5214 off(event: 'close', listener: (worker: Worker) => void): this;
5215
5216 url(): string;}
5217
5218/**
5219 * JSHandle represents an in-page JavaScript object. JSHandles can be created with the
5220 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
5221 * method.
5222 *
5223 * ```js
5224 * const windowHandle = await page.evaluateHandle(() => window);
5225 * // ...
5226 * ```
5227 *
5228 * JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with
5229 * [jsHandle.dispose()](https://playwright.dev/docs/api/class-jshandle#jshandledispose). JSHandles are auto-disposed when
5230 * their origin frame gets navigated or the parent context gets destroyed.
5231 *
5232 * JSHandle instances can be used as an argument in
5233 * [page.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevalselector-pagefunction-arg),
5234 * [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg) and
5235 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
5236 * methods.
5237 */
5238export interface JSHandle<T = any> {
5239 /**
5240 * Returns the return value of `pageFunction`.
5241 *
5242 * This method passes this handle as the first argument to `pageFunction`.
5243 *
5244 * If `pageFunction` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its
5245 * value.
5246 *
5247 * Examples:
5248 *
5249 * ```js
5250 * const tweetHandle = await page.$('.tweet .retweets');
5251 * expect(await tweetHandle.evaluate(node => node.innerText)).toBe('10 retweets');
5252 * ```
5253 *
5254 * @param pageFunction Function to be evaluated in the page context.
5255 * @param arg Optional argument to pass to `pageFunction`.
5256 */
5257 evaluate<R, Arg, O extends T = T>(pageFunction: PageFunctionOn<O, Arg, R>, arg: Arg): Promise<R>;
5258 evaluate<R, O extends T = T>(pageFunction: PageFunctionOn<O, void, R>, arg?: any): Promise<R>;
5259
5260 /**
5261 * Returns the return value of `pageFunction` as a [JSHandle].
5262 *
5263 * This method passes this handle as the first argument to `pageFunction`.
5264 *
5265 * The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns
5266 * [JSHandle].
5267 *
5268 * If the function passed to the `jsHandle.evaluateHandle` returns a [Promise], then `jsHandle.evaluateHandle` would wait
5269 * for the promise to resolve and return its value.
5270 *
5271 * See
5272 * [page.evaluateHandle(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatehandlepagefunction-arg)
5273 * for more details.
5274 * @param pageFunction Function to be evaluated in the page context.
5275 * @param arg Optional argument to pass to `pageFunction`.
5276 */
5277 evaluateHandle<R, Arg, O extends T = T>(pageFunction: PageFunctionOn<O, Arg, R>, arg: Arg): Promise<SmartHandle<R>>;
5278 evaluateHandle<R, O extends T = T>(pageFunction: PageFunctionOn<O, void, R>, arg?: any): Promise<SmartHandle<R>>;
5279
5280 /**
5281 * Returns a JSON representation of the object. If the object has a `toJSON` function, it **will not be called**.
5282 *
5283 * > NOTE: The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an
5284 * error if the object has circular references.
5285 */
5286 jsonValue(): Promise<T>;
5287 /**
5288 * Returns either `null` or the object handle itself, if the object handle is an instance of [ElementHandle].
5289 */
5290 asElement(): T extends Node ? ElementHandle<T> : null;
5291 /**
5292 * The `jsHandle.dispose` method stops referencing the element handle.
5293 */
5294 dispose(): Promise<void>;
5295
5296 /**
5297 * The method returns a map with **own property names** as keys and JSHandle instances for the property values.
5298 *
5299 * ```js
5300 * const handle = await page.evaluateHandle(() => ({window, document}));
5301 * const properties = await handle.getProperties();
5302 * const windowHandle = properties.get('window');
5303 * const documentHandle = properties.get('document');
5304 * await handle.dispose();
5305 * ```
5306 *
5307 */
5308 getProperties(): Promise<Map<string, JSHandle>>;
5309
5310 /**
5311 * Fetches a single property from the referenced object.
5312 * @param propertyName property to get
5313 */
5314 getProperty(propertyName: string): Promise<JSHandle>;}
5315
5316/**
5317 * - extends: [JSHandle]
5318 *
5319 * ElementHandle represents an in-page DOM element. ElementHandles can be created with the
5320 * [page.$(selector)](https://playwright.dev/docs/api/class-page#pageselector) method.
5321 *
5322 * ```js
5323 * const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
5324 *
5325 * (async () => {
5326 * const browser = await chromium.launch();
5327 * const page = await browser.newPage();
5328 * await page.goto('https://example.com');
5329 * const hrefElement = await page.$('a');
5330 * await hrefElement.click();
5331 * // ...
5332 * })();
5333 * ```
5334 *
5335 * ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
5336 * [jsHandle.dispose()](https://playwright.dev/docs/api/class-jshandle#jshandledispose). ElementHandles are auto-disposed
5337 * when their origin frame gets navigated.
5338 *
5339 * ElementHandle instances can be used as an argument in
5340 * [page.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevalselector-pagefunction-arg)
5341 * and [page.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-page#pageevaluatepagefunction-arg)
5342 * methods.
5343 */
5344export interface ElementHandle<T=Node> extends JSHandle<T> {
5345 /**
5346 * The method finds an element matching the specified selector in the `ElementHandle`'s subtree. See
5347 * [Working with selectors](https://playwright.dev/docs/selectors) for more details. If no elements match the selector, returns `null`.
5348 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
5349 */
5350 $<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K> | null>;
5351 $(selector: string): Promise<ElementHandle<SVGElement | HTMLElement> | null>;
5352
5353 /**
5354 * The method finds all elements matching the specified selector in the `ElementHandle`s subtree. See
5355 * [Working with selectors](https://playwright.dev/docs/selectors) for more details. If no elements match the selector, returns empty array.
5356 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
5357 */
5358 $$<K extends keyof HTMLElementTagNameMap>(selector: K): Promise<ElementHandleForTag<K>[]>;
5359 $$(selector: string): Promise<ElementHandle<SVGElement | HTMLElement>[]>;
5360
5361 /**
5362 * Returns the return value of `pageFunction`.
5363 *
5364 * The method finds an element matching the specified selector in the `ElementHandle`s subtree and passes it as a first
5365 * argument to `pageFunction`. See [Working with selectors](https://playwright.dev/docs/selectors) for more details. If no elements match the
5366 * selector, the method throws an error.
5367 *
5368 * If `pageFunction` returns a [Promise], then
5369 * [elementHandle.$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#elementhandleevalselector-pagefunction-arg)
5370 * would wait for the promise to resolve and return its value.
5371 *
5372 * Examples:
5373 *
5374 * ```js
5375 * const tweetHandle = await page.$('.tweet');
5376 * expect(await tweetHandle.$eval('.like', node => node.innerText)).toBe('100');
5377 * expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10');
5378 * ```
5379 *
5380 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
5381 * @param pageFunction Function to be evaluated in the page context.
5382 * @param arg Optional argument to pass to `pageFunction`.
5383 */
5384 $eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], Arg, R>, arg: Arg): Promise<R>;
5385 $eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, Arg, R>, arg: Arg): Promise<R>;
5386 $eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K], void, R>, arg?: any): Promise<R>;
5387 $eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E, void, R>, arg?: any): Promise<R>;
5388
5389 /**
5390 * Returns the return value of `pageFunction`.
5391 *
5392 * The method finds all elements matching the specified selector in the `ElementHandle`'s subtree and passes an array of
5393 * matched elements as a first argument to `pageFunction`. See [Working with selectors](https://playwright.dev/docs/selectors) for more details.
5394 *
5395 * If `pageFunction` returns a [Promise], then
5396 * [elementHandle.$$eval(selector, pageFunction[, arg])](https://playwright.dev/docs/api/class-elementhandle#elementhandleevalselector-pagefunction-arg)
5397 * would wait for the promise to resolve and return its value.
5398 *
5399 * Examples:
5400 *
5401 * ```html
5402 * <div class="feed">
5403 * <div class="tweet">Hello!</div>
5404 * <div class="tweet">Hi!</div>
5405 * </div>
5406 * ```
5407 *
5408 * ```js
5409 * const feedHandle = await page.$('.feed');
5410 * expect(await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText))).toEqual(['Hello!', 'Hi!']);
5411 * ```
5412 *
5413 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
5414 * @param pageFunction Function to be evaluated in the page context.
5415 * @param arg Optional argument to pass to `pageFunction`.
5416 */
5417 $$eval<K extends keyof HTMLElementTagNameMap, R, Arg>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], Arg, R>, arg: Arg): Promise<R>;
5418 $$eval<R, Arg, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], Arg, R>, arg: Arg): Promise<R>;
5419 $$eval<K extends keyof HTMLElementTagNameMap, R>(selector: K, pageFunction: PageFunctionOn<HTMLElementTagNameMap[K][], void, R>, arg?: any): Promise<R>;
5420 $$eval<R, E extends SVGElement | HTMLElement = SVGElement | HTMLElement>(selector: string, pageFunction: PageFunctionOn<E[], void, R>, arg?: any): Promise<R>;
5421
5422 /**
5423 * Returns element specified by selector when it satisfies `state` option. Returns `null` if waiting for `hidden` or
5424 * `detached`.
5425 *
5426 * Wait for the `selector` relative to the element handle to satisfy `state` option (either appear/disappear from dom, or
5427 * become visible/hidden). If at the moment of calling the method `selector` already satisfies the condition, the method
5428 * will return immediately. If the selector doesn't satisfy the condition for the `timeout` milliseconds, the function will
5429 * throw.
5430 *
5431 * ```js
5432 * await page.setContent(`<div><span></span></div>`);
5433 * const div = await page.$('div');
5434 * // Waiting for the 'span' selector relative to the div.
5435 * const span = await div.waitForSelector('span', { state: 'attached' });
5436 * ```
5437 *
5438 * > NOTE: This method does not work across navigations, use
5439 * [page.waitForSelector(selector[, options])](https://playwright.dev/docs/api/class-page#pagewaitforselectorselector-options)
5440 * instead.
5441 * @param selector A selector to query for. See [working with selectors](https://playwright.dev/docs/selectors) for more details.
5442 * @param options
5443 */
5444 waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options?: ElementHandleWaitForSelectorOptionsNotHidden): Promise<ElementHandleForTag<K>>;
5445 waitForSelector(selector: string, options?: ElementHandleWaitForSelectorOptionsNotHidden): Promise<ElementHandle<SVGElement | HTMLElement>>;
5446 waitForSelector<K extends keyof HTMLElementTagNameMap>(selector: K, options: ElementHandleWaitForSelectorOptions): Promise<ElementHandleForTag<K> | null>;
5447 waitForSelector(selector: string, options: ElementHandleWaitForSelectorOptions): Promise<null|ElementHandle<SVGElement | HTMLElement>>;
5448 /**
5449 * This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
5450 * calculated relative to the main frame viewport - which is usually the same as the browser window.
5451 *
5452 * Scrolling affects the returned bonding box, similarly to
5453 * [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
5454 * means `x` and/or `y` may be negative.
5455 *
5456 * Elements from child frames return the bounding box relative to the main frame, unlike the
5457 * [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect).
5458 *
5459 * Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
5460 * snippet should click the center of the element.
5461 *
5462 * ```js
5463 * const box = await elementHandle.boundingBox();
5464 * await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
5465 * ```
5466 *
5467 */
5468 boundingBox(): Promise<null|{
5469 /**
5470 * the x coordinate of the element in pixels.
5471 */
5472 x: number;
5473
5474 /**
5475 * the y coordinate of the element in pixels.
5476 */
5477 y: number;
5478
5479 /**
5480 * the width of the element in pixels.
5481 */
5482 width: number;
5483
5484 /**
5485 * the height of the element in pixels.
5486 */
5487 height: number;
5488 }>;
5489
5490 /**
5491 * This method checks the element by performing the following steps:
5492 * 1. Ensure that element is a checkbox or a radio input. If not, this method rejects. If the element is already
5493 * checked, this method returns immediately.
5494 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the element, unless `force` option is set.
5495 * 1. Scroll the element into view if needed.
5496 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element.
5497 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
5498 * 1. Ensure that the element is now checked. If not, this method rejects.
5499 *
5500 * If the element is detached from the DOM at any moment during the action, this method rejects.
5501 *
5502 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
5503 * Passing zero timeout disables this.
5504 * @param options
5505 */
5506 check(options?: {
5507 /**
5508 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
5509 */
5510 force?: boolean;
5511
5512 /**
5513 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
5514 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
5515 * inaccessible pages. Defaults to `false`.
5516 */
5517 noWaitAfter?: boolean;
5518
5519 /**
5520 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5521 * using the
5522 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5523 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5524 */
5525 timeout?: number;
5526 }): Promise<void>;
5527
5528 /**
5529 * This method clicks the element by performing the following steps:
5530 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the element, unless `force` option is set.
5531 * 1. Scroll the element into view if needed.
5532 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element, or
5533 * the specified `position`.
5534 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
5535 *
5536 * If the element is detached from the DOM at any moment during the action, this method rejects.
5537 *
5538 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
5539 * Passing zero timeout disables this.
5540 * @param options
5541 */
5542 click(options?: {
5543 /**
5544 * Defaults to `left`.
5545 */
5546 button?: "left"|"right"|"middle";
5547
5548 /**
5549 * defaults to 1. See [UIEvent.detail].
5550 */
5551 clickCount?: number;
5552
5553 /**
5554 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
5555 */
5556 delay?: number;
5557
5558 /**
5559 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
5560 */
5561 force?: boolean;
5562
5563 /**
5564 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
5565 * modifiers back. If not specified, currently pressed modifiers are used.
5566 */
5567 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
5568
5569 /**
5570 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
5571 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
5572 * inaccessible pages. Defaults to `false`.
5573 */
5574 noWaitAfter?: boolean;
5575
5576 /**
5577 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
5578 * element.
5579 */
5580 position?: {
5581 x: number;
5582
5583 y: number;
5584 };
5585
5586 /**
5587 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5588 * using the
5589 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5590 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5591 */
5592 timeout?: number;
5593 }): Promise<void>;
5594
5595 /**
5596 * Returns the content frame for element handles referencing iframe nodes, or `null` otherwise
5597 */
5598 contentFrame(): Promise<null|Frame>;
5599
5600 /**
5601 * This method double clicks the element by performing the following steps:
5602 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the element, unless `force` option is set.
5603 * 1. Scroll the element into view if needed.
5604 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to double click in the center of the
5605 * element, or the specified `position`.
5606 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
5607 * first click of the `dblclick()` triggers a navigation event, this method will reject.
5608 *
5609 * If the element is detached from the DOM at any moment during the action, this method rejects.
5610 *
5611 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
5612 * Passing zero timeout disables this.
5613 *
5614 * > NOTE: `elementHandle.dblclick()` dispatches two `click` events and a single `dblclick` event.
5615 * @param options
5616 */
5617 dblclick(options?: {
5618 /**
5619 * Defaults to `left`.
5620 */
5621 button?: "left"|"right"|"middle";
5622
5623 /**
5624 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
5625 */
5626 delay?: number;
5627
5628 /**
5629 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
5630 */
5631 force?: boolean;
5632
5633 /**
5634 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
5635 * modifiers back. If not specified, currently pressed modifiers are used.
5636 */
5637 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
5638
5639 /**
5640 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
5641 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
5642 * inaccessible pages. Defaults to `false`.
5643 */
5644 noWaitAfter?: boolean;
5645
5646 /**
5647 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
5648 * element.
5649 */
5650 position?: {
5651 x: number;
5652
5653 y: number;
5654 };
5655
5656 /**
5657 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5658 * using the
5659 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5660 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5661 */
5662 timeout?: number;
5663 }): Promise<void>;
5664
5665 /**
5666 * The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
5667 * is dispatched. This is equivalend to calling
5668 * [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
5669 *
5670 * ```js
5671 * await elementHandle.dispatchEvent('click');
5672 * ```
5673 *
5674 * Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
5675 * and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
5676 *
5677 * Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
5678 * - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
5679 * - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
5680 * - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
5681 * - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
5682 * - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
5683 * - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
5684 * - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
5685 *
5686 * You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
5687 *
5688 * ```js
5689 * // Note you can only create DataTransfer in Chromium and Firefox
5690 * const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
5691 * await elementHandle.dispatchEvent('dragstart', { dataTransfer });
5692 * ```
5693 *
5694 * @param type DOM event type: `"click"`, `"dragstart"`, etc.
5695 * @param eventInit Optional event-specific initialization properties.
5696 */
5697 dispatchEvent(type: string, eventInit?: EvaluationArgument): Promise<void>;
5698
5699 /**
5700 * This method waits for [actionability](https://playwright.dev/docs/actionability) checks, focuses the element, fills it and triggers an `input`
5701 * event after filling. If the element is inside the `<label>` element that has associated
5702 * [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), that control will be filled
5703 * instead. If the element to be filled is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method
5704 * throws an error. Note that you can pass an empty string to clear the input field.
5705 * @param value Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element.
5706 * @param options
5707 */
5708 fill(value: string, options?: {
5709 /**
5710 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
5711 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
5712 * inaccessible pages. Defaults to `false`.
5713 */
5714 noWaitAfter?: boolean;
5715
5716 /**
5717 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5718 * using the
5719 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5720 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5721 */
5722 timeout?: number;
5723 }): Promise<void>;
5724
5725 /**
5726 * Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element.
5727 */
5728 focus(): Promise<void>;
5729
5730 /**
5731 * Returns element attribute value.
5732 * @param name Attribute name to get the value for.
5733 */
5734 getAttribute(name: string): Promise<null|string>;
5735
5736 /**
5737 * This method hovers over the element by performing the following steps:
5738 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the element, unless `force` option is set.
5739 * 1. Scroll the element into view if needed.
5740 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to hover over the center of the element, or
5741 * the specified `position`.
5742 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
5743 *
5744 * If the element is detached from the DOM at any moment during the action, this method rejects.
5745 *
5746 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
5747 * Passing zero timeout disables this.
5748 * @param options
5749 */
5750 hover(options?: {
5751 /**
5752 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
5753 */
5754 force?: boolean;
5755
5756 /**
5757 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
5758 * modifiers back. If not specified, currently pressed modifiers are used.
5759 */
5760 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
5761
5762 /**
5763 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
5764 * element.
5765 */
5766 position?: {
5767 x: number;
5768
5769 y: number;
5770 };
5771
5772 /**
5773 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5774 * using the
5775 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5776 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5777 */
5778 timeout?: number;
5779 }): Promise<void>;
5780
5781 /**
5782 * Returns the `element.innerHTML`.
5783 */
5784 innerHTML(): Promise<string>;
5785
5786 /**
5787 * Returns the `element.innerText`.
5788 */
5789 innerText(): Promise<string>;
5790
5791 /**
5792 * Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
5793 */
5794 isChecked(): Promise<boolean>;
5795
5796 /**
5797 * Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/docs/actionability#enabled).
5798 */
5799 isDisabled(): Promise<boolean>;
5800
5801 /**
5802 * Returns whether the element is [editable](https://playwright.dev/docs/actionability#editable).
5803 */
5804 isEditable(): Promise<boolean>;
5805
5806 /**
5807 * Returns whether the element is [enabled](https://playwright.dev/docs/actionability#enabled).
5808 */
5809 isEnabled(): Promise<boolean>;
5810
5811 /**
5812 * Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/docs/actionability#visible).
5813 */
5814 isHidden(): Promise<boolean>;
5815
5816 /**
5817 * Returns whether the element is [visible](https://playwright.dev/docs/actionability#visible).
5818 */
5819 isVisible(): Promise<boolean>;
5820
5821 /**
5822 * Returns the frame containing the given element.
5823 */
5824 ownerFrame(): Promise<null|Frame>;
5825
5826 /**
5827 * Focuses the element, and then uses [keyboard.down(key)](https://playwright.dev/docs/api/class-keyboard#keyboarddownkey)
5828 * and [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboardupkey).
5829 *
5830 * `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
5831 * value or a single character to generate the text for. A superset of the `key` values can be found
5832 * [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
5833 *
5834 * `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
5835 * `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
5836 *
5837 * Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
5838 *
5839 * Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
5840 *
5841 * If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
5842 * texts.
5843 *
5844 * Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
5845 * modifier, modifier is pressed and being held while the subsequent key is being pressed.
5846 * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
5847 * @param options
5848 */
5849 press(key: string, options?: {
5850 /**
5851 * Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
5852 */
5853 delay?: number;
5854
5855 /**
5856 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
5857 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
5858 * inaccessible pages. Defaults to `false`.
5859 */
5860 noWaitAfter?: boolean;
5861
5862 /**
5863 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5864 * using the
5865 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5866 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5867 */
5868 timeout?: number;
5869 }): Promise<void>;
5870
5871 /**
5872 * Returns the buffer with the captured screenshot.
5873 *
5874 * This method waits for the [actionability](https://playwright.dev/docs/actionability) checks, then scrolls element into view before taking a
5875 * screenshot. If the element is detached from DOM, the method throws an error.
5876 * @param options
5877 */
5878 screenshot(options?: {
5879 /**
5880 * Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.
5881 * Defaults to `false`.
5882 */
5883 omitBackground?: boolean;
5884
5885 /**
5886 * The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative
5887 * path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to
5888 * the disk.
5889 */
5890 path?: string;
5891
5892 /**
5893 * The quality of the image, between 0-100. Not applicable to `png` images.
5894 */
5895 quality?: number;
5896
5897 /**
5898 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5899 * using the
5900 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5901 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5902 */
5903 timeout?: number;
5904
5905 /**
5906 * Specify screenshot type, defaults to `png`.
5907 */
5908 type?: "png"|"jpeg";
5909 }): Promise<Buffer>;
5910
5911 /**
5912 * This method waits for [actionability](https://playwright.dev/docs/actionability) checks, then tries to scroll element into view, unless it is
5913 * completely visible as defined by
5914 * [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)'s `ratio`.
5915 *
5916 * Throws when `elementHandle` does not point to an element
5917 * [connected](https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected) to a Document or a ShadowRoot.
5918 * @param options
5919 */
5920 scrollIntoViewIfNeeded(options?: {
5921 /**
5922 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5923 * using the
5924 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5925 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5926 */
5927 timeout?: number;
5928 }): Promise<void>;
5929
5930 /**
5931 * Returns the array of option values that have been successfully selected.
5932 *
5933 * Triggers a `change` and `input` event once all the provided options have been selected. If element is not a `<select>`
5934 * element, the method throws an error.
5935 *
5936 * Will wait until all specified options are present in the `<select>` element.
5937 *
5938 * ```js
5939 * // single selection matching the value
5940 * handle.selectOption('blue');
5941 *
5942 * // single selection matching the label
5943 * handle.selectOption({ label: 'Blue' });
5944 *
5945 * // multiple selection
5946 * handle.selectOption(['red', 'green', 'blue']);
5947 * ```
5948 *
5949 * @param values Options to select. If the `<select>` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option
5950 * is considered matching if all specified properties match.
5951 * @param options
5952 */
5953 selectOption(values: null|string|ElementHandle|Array<string>|{
5954 /**
5955 * Matches by `option.value`. Optional.
5956 */
5957 value?: string;
5958
5959 /**
5960 * Matches by `option.label`. Optional.
5961 */
5962 label?: string;
5963
5964 /**
5965 * Matches by the index. Optional.
5966 */
5967 index?: number;
5968 }|Array<ElementHandle>|Array<{
5969 /**
5970 * Matches by `option.value`. Optional.
5971 */
5972 value?: string;
5973
5974 /**
5975 * Matches by `option.label`. Optional.
5976 */
5977 label?: string;
5978
5979 /**
5980 * Matches by the index. Optional.
5981 */
5982 index?: number;
5983 }>, options?: {
5984 /**
5985 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
5986 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
5987 * inaccessible pages. Defaults to `false`.
5988 */
5989 noWaitAfter?: boolean;
5990
5991 /**
5992 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
5993 * using the
5994 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
5995 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
5996 */
5997 timeout?: number;
5998 }): Promise<Array<string>>;
5999
6000 /**
6001 * This method waits for [actionability](https://playwright.dev/docs/actionability) checks, then focuses the element and selects all its text
6002 * content.
6003 * @param options
6004 */
6005 selectText(options?: {
6006 /**
6007 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
6008 * using the
6009 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
6010 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
6011 */
6012 timeout?: number;
6013 }): Promise<void>;
6014
6015 /**
6016 * This method expects `elementHandle` to point to an
6017 * [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
6018 *
6019 * Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
6020 * are resolved relative to the the current working directory. For empty array, clears the selected files.
6021 * @param files
6022 * @param options
6023 */
6024 setInputFiles(files: string|Array<string>|{
6025 /**
6026 * File name
6027 */
6028 name: string;
6029
6030 /**
6031 * File type
6032 */
6033 mimeType: string;
6034
6035 /**
6036 * File content
6037 */
6038 buffer: Buffer;
6039 }|Array<{
6040 /**
6041 * File name
6042 */
6043 name: string;
6044
6045 /**
6046 * File type
6047 */
6048 mimeType: string;
6049
6050 /**
6051 * File content
6052 */
6053 buffer: Buffer;
6054 }>, options?: {
6055 /**
6056 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
6057 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
6058 * inaccessible pages. Defaults to `false`.
6059 */
6060 noWaitAfter?: boolean;
6061
6062 /**
6063 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
6064 * using the
6065 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
6066 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
6067 */
6068 timeout?: number;
6069 }): Promise<void>;
6070
6071 /**
6072 * This method taps the element by performing the following steps:
6073 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the element, unless `force` option is set.
6074 * 1. Scroll the element into view if needed.
6075 * 1. Use [page.touchscreen](https://playwright.dev/docs/api/class-page#pagetouchscreen) to tap the center of the
6076 * element, or the specified `position`.
6077 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
6078 *
6079 * If the element is detached from the DOM at any moment during the action, this method rejects.
6080 *
6081 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
6082 * Passing zero timeout disables this.
6083 *
6084 * > NOTE: `elementHandle.tap()` requires that the `hasTouch` option of the browser context be set to true.
6085 * @param options
6086 */
6087 tap(options?: {
6088 /**
6089 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
6090 */
6091 force?: boolean;
6092
6093 /**
6094 * Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current
6095 * modifiers back. If not specified, currently pressed modifiers are used.
6096 */
6097 modifiers?: Array<"Alt"|"Control"|"Meta"|"Shift">;
6098
6099 /**
6100 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
6101 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
6102 * inaccessible pages. Defaults to `false`.
6103 */
6104 noWaitAfter?: boolean;
6105
6106 /**
6107 * A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the
6108 * element.
6109 */
6110 position?: {
6111 x: number;
6112
6113 y: number;
6114 };
6115
6116 /**
6117 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
6118 * using the
6119 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
6120 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
6121 */
6122 timeout?: number;
6123 }): Promise<void>;
6124
6125 /**
6126 * Returns the `node.textContent`.
6127 */
6128 textContent(): Promise<null|string>;
6129
6130 /**
6131 * Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
6132 *
6133 * To press a special key, like `Control` or `ArrowDown`, use
6134 * [elementHandle.press(key[, options])](https://playwright.dev/docs/api/class-elementhandle#elementhandlepresskey-options).
6135 *
6136 * ```js
6137 * await elementHandle.type('Hello'); // Types instantly
6138 * await elementHandle.type('World', {delay: 100}); // Types slower, like a user
6139 * ```
6140 *
6141 * An example of typing into a text field and then submitting the form:
6142 *
6143 * ```js
6144 * const elementHandle = await page.$('input');
6145 * await elementHandle.type('some text');
6146 * await elementHandle.press('Enter');
6147 * ```
6148 *
6149 * @param text A text to type into a focused element.
6150 * @param options
6151 */
6152 type(text: string, options?: {
6153 /**
6154 * Time to wait between key presses in milliseconds. Defaults to 0.
6155 */
6156 delay?: number;
6157
6158 /**
6159 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
6160 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
6161 * inaccessible pages. Defaults to `false`.
6162 */
6163 noWaitAfter?: boolean;
6164
6165 /**
6166 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
6167 * using the
6168 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
6169 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
6170 */
6171 timeout?: number;
6172 }): Promise<void>;
6173
6174 /**
6175 * This method checks the element by performing the following steps:
6176 * 1. Ensure that element is a checkbox or a radio input. If not, this method rejects. If the element is already
6177 * unchecked, this method returns immediately.
6178 * 1. Wait for [actionability](https://playwright.dev/docs/actionability) checks on the element, unless `force` option is set.
6179 * 1. Scroll the element into view if needed.
6180 * 1. Use [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse) to click in the center of the element.
6181 * 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
6182 * 1. Ensure that the element is now unchecked. If not, this method rejects.
6183 *
6184 * If the element is detached from the DOM at any moment during the action, this method rejects.
6185 *
6186 * When all steps combined have not finished during the specified `timeout`, this method rejects with a [TimeoutError].
6187 * Passing zero timeout disables this.
6188 * @param options
6189 */
6190 uncheck(options?: {
6191 /**
6192 * Whether to bypass the [actionability](https://playwright.dev/docs/actionability) checks. Defaults to `false`.
6193 */
6194 force?: boolean;
6195
6196 /**
6197 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
6198 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
6199 * inaccessible pages. Defaults to `false`.
6200 */
6201 noWaitAfter?: boolean;
6202
6203 /**
6204 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
6205 * using the
6206 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
6207 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
6208 */
6209 timeout?: number;
6210 }): Promise<void>;
6211
6212 /**
6213 * Returns when the element satisfies the `state`.
6214 *
6215 * Depending on the `state` parameter, this method waits for one of the [actionability](https://playwright.dev/docs/actionability) checks to pass.
6216 * This method throws when the element is detached while waiting, unless waiting for the `"hidden"` state.
6217 * - `"visible"` Wait until the element is [visible](https://playwright.dev/docs/actionability#visible).
6218 * - `"hidden"` Wait until the element is [not visible](https://playwright.dev/docs/actionability#visible) or
6219 * [not attached](https://playwright.dev/docs/actionability#attached). Note that waiting for hidden does not throw when the element detaches.
6220 * - `"stable"` Wait until the element is both [visible](https://playwright.dev/docs/actionability#visible) and
6221 * [stable](https://playwright.dev/docs/actionability#stable).
6222 * - `"enabled"` Wait until the element is [enabled](https://playwright.dev/docs/actionability#enabled).
6223 * - `"disabled"` Wait until the element is [not enabled](https://playwright.dev/docs/actionability#enabled).
6224 * - `"editable"` Wait until the element is [editable](https://playwright.dev/docs/actionability#editable).
6225 *
6226 * If the element does not satisfy the condition for the `timeout` milliseconds, this method will throw.
6227 * @param state A state to wait for, see below for more details.
6228 * @param options
6229 */
6230 waitForElementState(state: "visible"|"hidden"|"stable"|"enabled"|"disabled"|"editable", options?: {
6231 /**
6232 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
6233 * using the
6234 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
6235 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
6236 */
6237 timeout?: number;
6238 }): Promise<void>;}
6239
6240/**
6241 * BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
6242 * typical example of using Playwright to drive automation:
6243 *
6244 * ```js
6245 * const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
6246 *
6247 * (async () => {
6248 * const browser = await chromium.launch();
6249 * const page = await browser.newPage();
6250 * await page.goto('https://example.com');
6251 * // other actions...
6252 * await browser.close();
6253 * })();
6254 * ```
6255 *
6256 */
6257export interface BrowserType<Browser> {
6258
6259 /**
6260 * This methods attaches Playwright to an existing browser instance.
6261 * @param params
6262 */
6263 connect(params: ConnectOptions): Promise<Browser>;
6264
6265 /**
6266 * This methods attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
6267 *
6268 * The default browser context is accessible via
6269 * [browser.contexts()](https://playwright.dev/docs/api/class-browser#browsercontexts).
6270 *
6271 * > NOTE: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
6272 * @param params
6273 */
6274 connectOverCDP(params: {
6275 /**
6276 * A CDP websocket endpoint to connect to.
6277 */
6278 wsEndpoint: string;
6279
6280 /**
6281 * Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
6282 * Defaults to 0.
6283 */
6284 slowMo?: number;
6285
6286 /**
6287 * Logger sink for Playwright logging. Optional.
6288 */
6289 logger?: Logger;
6290
6291 /**
6292 * Maximum time in milliseconds to wait for the connection to be established. Defaults to `30000` (30 seconds). Pass `0` to
6293 * disable timeout.
6294 */
6295 timeout?: number;
6296 }): Promise<Browser>;
6297
6298 /**
6299 * A path where Playwright expects to find a bundled browser executable.
6300 */
6301 executablePath(): string;
6302
6303 /**
6304 * Returns the browser instance.
6305 *
6306 * You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
6307 *
6308 * ```js
6309 * const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
6310 * ignoreDefaultArgs: ['--mute-audio']
6311 * });
6312 * ```
6313 *
6314 * > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works
6315 * best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use
6316 * `executablePath` option with extreme caution.
6317 * >
6318 * > If Google Chrome (rather than Chromium) is preferred, a
6319 * [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
6320 * [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
6321 * >
6322 * > Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for
6323 * video playback. See
6324 * [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other
6325 * differences between Chromium and Chrome.
6326 * [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
6327 * describes some differences for Linux users.
6328 * @param options
6329 */
6330 launch(options?: LaunchOptions): Promise<Browser>;
6331
6332 /**
6333 * Returns the persistent browser context instance.
6334 *
6335 * Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing this
6336 * context will automatically close the browser.
6337 * @param userDataDir Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md#introduction) and
6338 * [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile). Note that Chromium's user
6339 * data directory is the **parent** directory of the "Profile Path" seen at `chrome://version`.
6340 * @param options
6341 */
6342 launchPersistentContext(userDataDir: string, options?: {
6343 /**
6344 * Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
6345 */
6346 acceptDownloads?: boolean;
6347
6348 /**
6349 * Additional arguments to pass to the browser instance. The list of Chromium flags can be found
6350 * [here](http://peter.sh/experiments/chromium-command-line-switches/).
6351 */
6352 args?: Array<string>;
6353
6354 /**
6355 * Toggles bypassing page's Content-Security-Policy.
6356 */
6357 bypassCSP?: boolean;
6358
6359 /**
6360 * Browser distribution channel.
6361 */
6362 channel?: "chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary";
6363
6364 /**
6365 * Enable Chromium sandboxing. Defaults to `true`.
6366 */
6367 chromiumSandbox?: boolean;
6368
6369 /**
6370 * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
6371 * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
6372 * Defaults to `'light'`.
6373 */
6374 colorScheme?: "light"|"dark"|"no-preference";
6375
6376 /**
6377 * Specify device scale factor (can be thought of as dpr). Defaults to `1`.
6378 */
6379 deviceScaleFactor?: number;
6380
6381 /**
6382 * **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless`
6383 * option will be set `false`.
6384 */
6385 devtools?: boolean;
6386
6387 /**
6388 * If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
6389 * deleted when browser is closed.
6390 */
6391 downloadsPath?: string;
6392
6393 /**
6394 * Specify environment variables that will be visible to the browser. Defaults to `process.env`.
6395 */
6396 env?: { [key: string]: string|number|boolean; };
6397
6398 /**
6399 * Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
6400 * resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled
6401 * Chromium, Firefox or WebKit, use at your own risk.
6402 */
6403 executablePath?: string;
6404
6405 /**
6406 * An object containing additional HTTP headers to be sent with every request. All header values must be strings.
6407 */
6408 extraHTTPHeaders?: { [key: string]: string; };
6409
6410 geolocation?: {
6411 /**
6412 * Latitude between -90 and 90.
6413 */
6414 latitude: number;
6415
6416 /**
6417 * Longitude between -180 and 180.
6418 */
6419 longitude: number;
6420
6421 /**
6422 * Non-negative accuracy value. Defaults to `0`.
6423 */
6424 accuracy?: number;
6425 };
6426
6427 /**
6428 * Close the browser process on SIGHUP. Defaults to `true`.
6429 */
6430 handleSIGHUP?: boolean;
6431
6432 /**
6433 * Close the browser process on Ctrl-C. Defaults to `true`.
6434 */
6435 handleSIGINT?: boolean;
6436
6437 /**
6438 * Close the browser process on SIGTERM. Defaults to `true`.
6439 */
6440 handleSIGTERM?: boolean;
6441
6442 /**
6443 * Specifies if viewport supports touch events. Defaults to false.
6444 */
6445 hasTouch?: boolean;
6446
6447 /**
6448 * Whether to run browser in headless mode. More details for
6449 * [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and
6450 * [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the
6451 * `devtools` option is `true`.
6452 */
6453 headless?: boolean;
6454
6455 /**
6456 * Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
6457 */
6458 httpCredentials?: {
6459 username: string;
6460
6461 password: string;
6462 };
6463
6464 /**
6465 * If `true`, Playwright does not pass its own configurations args and only uses the ones from `args`. If an array is
6466 * given, then filters out the given default arguments. Dangerous option; use with care. Defaults to `false`.
6467 */
6468 ignoreDefaultArgs?: boolean|Array<string>;
6469
6470 /**
6471 * Whether to ignore HTTPS errors during navigation. Defaults to `false`.
6472 */
6473 ignoreHTTPSErrors?: boolean;
6474
6475 /**
6476 * Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported
6477 * in Firefox.
6478 */
6479 isMobile?: boolean;
6480
6481 /**
6482 * Whether or not to enable JavaScript in the context. Defaults to `true`.
6483 */
6484 javaScriptEnabled?: boolean;
6485
6486 /**
6487 * Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language`
6488 * request header value as well as number and date formatting rules.
6489 */
6490 locale?: string;
6491
6492 /**
6493 * Logger sink for Playwright logging.
6494 */
6495 logger?: Logger;
6496
6497 /**
6498 * Whether to emulate network being offline. Defaults to `false`.
6499 */
6500 offline?: boolean;
6501
6502 /**
6503 * A list of permissions to grant to all pages in this context. See
6504 * [browserContext.grantPermissions(permissions[, options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextgrantpermissionspermissions-options)
6505 * for more details.
6506 */
6507 permissions?: Array<string>;
6508
6509 /**
6510 * Network proxy settings.
6511 */
6512 proxy?: {
6513 /**
6514 * Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or
6515 * `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
6516 */
6517 server: string;
6518
6519 /**
6520 * Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
6521 */
6522 bypass?: string;
6523
6524 /**
6525 * Optional username to use if HTTP proxy requires authentication.
6526 */
6527 username?: string;
6528
6529 /**
6530 * Optional password to use if HTTP proxy requires authentication.
6531 */
6532 password?: string;
6533 };
6534
6535 /**
6536 * Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
6537 * specified, the HAR is not recorded. Make sure to await
6538 * [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for the HAR to be
6539 * saved.
6540 */
6541 recordHar?: {
6542 /**
6543 * Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
6544 */
6545 omitContent?: boolean;
6546
6547 /**
6548 * Path on the filesystem to write the HAR file to.
6549 */
6550 path: string;
6551 };
6552
6553 /**
6554 * Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
6555 * sure to await [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for
6556 * videos to be saved.
6557 */
6558 recordVideo?: {
6559 /**
6560 * Path to the directory to put videos into.
6561 */
6562 dir: string;
6563
6564 /**
6565 * Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit
6566 * into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page
6567 * will be scaled down if necessary to fit the specified size.
6568 */
6569 size?: {
6570 /**
6571 * Video frame width.
6572 */
6573 width: number;
6574
6575 /**
6576 * Video frame height.
6577 */
6578 height: number;
6579 };
6580 };
6581
6582 /**
6583 * Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
6584 * Defaults to 0.
6585 */
6586 slowMo?: number;
6587
6588 /**
6589 * Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to
6590 * disable timeout.
6591 */
6592 timeout?: number;
6593
6594 /**
6595 * Changes the timezone of the context. See
6596 * [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
6597 * for a list of supported timezone IDs.
6598 */
6599 timezoneId?: string;
6600
6601 /**
6602 * Specific user agent to use in this context.
6603 */
6604 userAgent?: string;
6605
6606 /**
6607 * **DEPRECATED** Use `recordVideo` instead.
6608 * @deprecated
6609 */
6610 videoSize?: {
6611 /**
6612 * Video frame width.
6613 */
6614 width: number;
6615
6616 /**
6617 * Video frame height.
6618 */
6619 height: number;
6620 };
6621
6622 /**
6623 * **DEPRECATED** Use `recordVideo` instead.
6624 * @deprecated
6625 */
6626 videosPath?: string;
6627
6628 /**
6629 * Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.
6630 */
6631 viewport?: null|{
6632 /**
6633 * page width in pixels.
6634 */
6635 width: number;
6636
6637 /**
6638 * page height in pixels.
6639 */
6640 height: number;
6641 };
6642 }): Promise<BrowserContext>;
6643
6644 /**
6645 * Returns the browser app instance.
6646 *
6647 * Launches browser server that client can connect to. An example of launching a browser executable and connecting to it
6648 * later:
6649 *
6650 * ```js
6651 * const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.
6652 *
6653 * (async () => {
6654 * const browserServer = await chromium.launchServer();
6655 * const wsEndpoint = browserServer.wsEndpoint();
6656 * // Use web socket endpoint later to establish a connection.
6657 * const browser = await chromium.connect({ wsEndpoint });
6658 * // Close browser instance.
6659 * await browserServer.close();
6660 * })();
6661 * ```
6662 *
6663 * @param options
6664 */
6665 launchServer(options?: {
6666 /**
6667 * Additional arguments to pass to the browser instance. The list of Chromium flags can be found
6668 * [here](http://peter.sh/experiments/chromium-command-line-switches/).
6669 */
6670 args?: Array<string>;
6671
6672 /**
6673 * Enable Chromium sandboxing. Defaults to `true`.
6674 */
6675 chromiumSandbox?: boolean;
6676
6677 /**
6678 * **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless`
6679 * option will be set `false`.
6680 */
6681 devtools?: boolean;
6682
6683 /**
6684 * If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
6685 * deleted when browser is closed.
6686 */
6687 downloadsPath?: string;
6688
6689 /**
6690 * Specify environment variables that will be visible to the browser. Defaults to `process.env`.
6691 */
6692 env?: { [key: string]: string|number|boolean; };
6693
6694 /**
6695 * Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
6696 * resolved relative to the current working directory. **BEWARE**: Playwright is only guaranteed to work with the bundled
6697 * Chromium, Firefox or WebKit, use at your own risk.
6698 */
6699 executablePath?: string;
6700
6701 /**
6702 * Firefox user preferences. Learn more about the Firefox user preferences at
6703 * [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
6704 */
6705 firefoxUserPrefs?: { [key: string]: string|number|boolean; };
6706
6707 /**
6708 * Close the browser process on SIGHUP. Defaults to `true`.
6709 */
6710 handleSIGHUP?: boolean;
6711
6712 /**
6713 * Close the browser process on Ctrl-C. Defaults to `true`.
6714 */
6715 handleSIGINT?: boolean;
6716
6717 /**
6718 * Close the browser process on SIGTERM. Defaults to `true`.
6719 */
6720 handleSIGTERM?: boolean;
6721
6722 /**
6723 * Whether to run browser in headless mode. More details for
6724 * [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and
6725 * [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the
6726 * `devtools` option is `true`.
6727 */
6728 headless?: boolean;
6729
6730 /**
6731 * If `true`, Playwright does not pass its own configurations args and only uses the ones from `args`. If an array is
6732 * given, then filters out the given default arguments. Dangerous option; use with care. Defaults to `false`.
6733 */
6734 ignoreDefaultArgs?: boolean|Array<string>;
6735
6736 /**
6737 * Logger sink for Playwright logging.
6738 */
6739 logger?: Logger;
6740
6741 /**
6742 * Port to use for the web socket. Defaults to 0 that picks any available port.
6743 */
6744 port?: number;
6745
6746 /**
6747 * Network proxy settings.
6748 */
6749 proxy?: {
6750 /**
6751 * Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or
6752 * `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
6753 */
6754 server: string;
6755
6756 /**
6757 * Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
6758 */
6759 bypass?: string;
6760
6761 /**
6762 * Optional username to use if HTTP proxy requires authentication.
6763 */
6764 username?: string;
6765
6766 /**
6767 * Optional password to use if HTTP proxy requires authentication.
6768 */
6769 password?: string;
6770 };
6771
6772 /**
6773 * Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to
6774 * disable timeout.
6775 */
6776 timeout?: number;
6777 }): Promise<BrowserServer>;
6778
6779 /**
6780 * Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
6781 */
6782 name(): string;}
6783
6784/**
6785 * - extends: [Browser]
6786 *
6787 * Chromium-specific features including Tracing, service worker support, etc. You can use
6788 * [chromiumBrowser.startTracing([page, options])](https://playwright.dev/docs/api/class-chromiumbrowser#chromiumbrowserstarttracingpage-options)
6789 * and [chromiumBrowser.stopTracing()](https://playwright.dev/docs/api/class-chromiumbrowser#chromiumbrowserstoptracing) to
6790 * create a trace file which can be opened in Chrome DevTools or
6791 * [timeline viewer](https://chromedevtools.github.io/timeline-viewer/).
6792 *
6793 * ```js
6794 * await browser.startTracing(page, {path: 'trace.json'});
6795 * await page.goto('https://www.google.com');
6796 * await browser.stopTracing();
6797 * ```
6798 *
6799 * [ChromiumBrowser] can also be used for testing Chrome Extensions.
6800 *
6801 * > NOTE: Extensions in Chrome / Chromium currently only work in non-headless mode.
6802 *
6803 * The following is code for getting a handle to the
6804 * [background page](https://developer.chrome.com/extensions/background_pages) of an extension whose source is located in
6805 * `./my-extension`:
6806 *
6807 * ```js
6808 * const { chromium } = require('playwright');
6809 *
6810 * (async () => {
6811 * const pathToExtension = require('path').join(__dirname, 'my-extension');
6812 * const userDataDir = '/tmp/test-user-data-dir';
6813 * const browserContext = await chromium.launchPersistentContext(userDataDir,{
6814 * headless: false,
6815 * args: [
6816 * `--disable-extensions-except=${pathToExtension}`,
6817 * `--load-extension=${pathToExtension}`
6818 * ]
6819 * });
6820 * const backgroundPage = browserContext.backgroundPages()[0];
6821 * // Test the background page as you would any other page.
6822 * await browserContext.close();
6823 * })();
6824 * ```
6825 *
6826 */
6827export interface ChromiumBrowser extends Browser {
6828 /**
6829 * Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
6830 *
6831 * ```js
6832 * const browser = await pw.webkit.launch();
6833 * console.log(browser.contexts().length); // prints `0`
6834 *
6835 * const context = await browser.newContext();
6836 * console.log(browser.contexts().length); // prints `1`
6837 * ```
6838 *
6839 */
6840 contexts(): Array<ChromiumBrowserContext>;
6841 /**
6842 * Creates a new browser context. It won't share cookies/cache with other browser contexts.
6843 *
6844 * ```js
6845 * (async () => {
6846 * const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.
6847 * // Create a new incognito browser context.
6848 * const context = await browser.newContext();
6849 * // Create a new page in a pristine context.
6850 * const page = await context.newPage();
6851 * await page.goto('https://example.com');
6852 * })();
6853 * ```
6854 *
6855 * @param options
6856 */
6857 newContext(options?: BrowserContextOptions): Promise<ChromiumBrowserContext>;
6858 /**
6859 * Returns the newly created browser session.
6860 */
6861 newBrowserCDPSession(): Promise<CDPSession>;
6862
6863 /**
6864 * Only one trace can be active at a time per browser.
6865 * @param page Optional, if specified, tracing includes screenshots of the given page.
6866 * @param options
6867 */
6868 startTracing(page?: Page, options?: {
6869 /**
6870 * specify custom categories to use instead of default.
6871 */
6872 categories?: Array<string>;
6873
6874 /**
6875 * A path to write the trace file to.
6876 */
6877 path?: string;
6878
6879 /**
6880 * captures screenshots in the trace.
6881 */
6882 screenshots?: boolean;
6883 }): Promise<void>;
6884
6885 /**
6886 * Returns the buffer with trace data.
6887 */
6888 stopTracing(): Promise<Buffer>;}
6889
6890/**
6891 * - extends: [EventEmitter]
6892 *
6893 * The `CDPSession` instances are used to talk raw Chrome Devtools Protocol:
6894 * - protocol methods can be called with `session.send` method.
6895 * - protocol events can be subscribed to with `session.on` method.
6896 *
6897 * Useful links:
6898 * - Documentation on DevTools Protocol can be found here:
6899 * [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/).
6900 * - Getting Started with DevTools Protocol:
6901 * https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
6902 *
6903 * ```js
6904 * const client = await page.context().newCDPSession(page);
6905 * await client.send('Animation.enable');
6906 * client.on('Animation.animationCreated', () => console.log('Animation created!'));
6907 * const response = await client.send('Animation.getPlaybackRate');
6908 * console.log('playback rate is ' + response.playbackRate);
6909 * await client.send('Animation.setPlaybackRate', {
6910 * playbackRate: response.playbackRate / 2
6911 * });
6912 * ```
6913 *
6914 */
6915export interface CDPSession {
6916 on: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
6917 addListener: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
6918 off: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
6919 removeListener: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
6920 once: <T extends keyof Protocol.Events | symbol>(event: T, listener: (payload: T extends symbol ? any : Protocol.Events[T extends keyof Protocol.Events ? T : never]) => void) => this;
6921 /**
6922 * @param method protocol method name
6923 * @param params Optional method parameters
6924 */
6925 send<T extends keyof Protocol.CommandParameters>(
6926 method: T,
6927 params?: Protocol.CommandParameters[T]
6928 ): Promise<Protocol.CommandReturnValues[T]>;
6929 /**
6930 * Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
6931 * send messages.
6932 */
6933 detach(): Promise<void>;}
6934
6935type DeviceDescriptor = {
6936 viewport: ViewportSize;
6937 userAgent: string;
6938 deviceScaleFactor: number;
6939 isMobile: boolean;
6940 hasTouch: boolean;
6941 defaultBrowserType: 'chromium' | 'firefox' | 'webkit';
6942};
6943
6944export namespace errors {
6945
6946/**
6947 * - extends: [Error]
6948 *
6949 * TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g.
6950 * [page.waitForSelector(selector[, options])](https://playwright.dev/docs/api/class-page#pagewaitforselectorselector-options)
6951 * or [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchoptions).
6952 */
6953class TimeoutError extends Error {}
6954
6955}
6956
6957/**
6958 * The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
6959 * assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
6960 * [switches](https://en.wikipedia.org/wiki/Switch_access).
6961 *
6962 * Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might
6963 * have wildly different output.
6964 *
6965 * Rendering engines of Chromium, Firefox and Webkit have a concept of "accessibility tree", which is then translated into
6966 * different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
6967 *
6968 * Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific
6969 * AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing
6970 * only the "interesting" nodes of the tree.
6971 */
6972export interface Accessibility {
6973 /**
6974 * Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
6975 * page.
6976 *
6977 * > NOTE: The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers.
6978 * Playwright will discard them as well for an easier to process tree, unless `interestingOnly` is set to `false`.
6979 *
6980 * An example of dumping the entire accessibility tree:
6981 *
6982 * ```js
6983 * const snapshot = await page.accessibility.snapshot();
6984 * console.log(snapshot);
6985 * ```
6986 *
6987 * An example of logging the focused node's name:
6988 *
6989 * ```js
6990 * const snapshot = await page.accessibility.snapshot();
6991 * const node = findFocusedNode(snapshot);
6992 * console.log(node && node.name);
6993 *
6994 * function findFocusedNode(node) {
6995 * if (node.focused)
6996 * return node;
6997 * for (const child of node.children || []) {
6998 * const foundNode = findFocusedNode(child);
6999 * return foundNode;
7000 * }
7001 * return null;
7002 * }
7003 * ```
7004 *
7005 * @param options
7006 */
7007 snapshot(options?: {
7008 /**
7009 * Prune uninteresting nodes from the tree. Defaults to `true`.
7010 */
7011 interestingOnly?: boolean;
7012
7013 /**
7014 * The root DOM element for the snapshot. Defaults to the whole page.
7015 */
7016 root?: ElementHandle;
7017 }): Promise<null|AccessibilityNode>;
7018}
7019
7020type AccessibilityNode = {
7021 role: string;
7022 name: string;
7023 value?: string|number;
7024 description?: string;
7025 keyshortcuts?: string;
7026 roledescription?: string;
7027 valuetext?: string;
7028 disabled?: boolean;
7029 expanded?: boolean;
7030 focused?: boolean;
7031 modal?: boolean;
7032 multiline?: boolean;
7033 multiselectable?: boolean;
7034 readonly?: boolean;
7035 required?: boolean;
7036 selected?: boolean;
7037 checked?: boolean|"mixed";
7038 pressed?: boolean|"mixed";
7039 level?: number;
7040 valuemin?: number;
7041 valuemax?: number;
7042 autocomplete?: string;
7043 haspopup?: string;
7044 invalid?: string;
7045 orientation?: string;
7046 children?: AccessibilityNode[];
7047}
7048
7049export const selectors: Selectors;
7050export const devices: Devices & DeviceDescriptor[];
7051
7052//@ts-ignore this will be any if electron is not installed
7053type ElectronType = typeof import('electron');
7054
7055/**
7056 * Electron application representation. You can use
7057 * [electron.launch([options])](https://playwright.dev/docs/api/class-electron#electronlaunchoptions) to obtain the
7058 * application instance. This instance you can control main electron process as well as work with Electron windows:
7059 *
7060 * ```js
7061 * const { _electron: electron } = require('playwright');
7062 *
7063 * (async () => {
7064 * // Launch Electron app.
7065 * const electronApp = await electron.launch({ args: ['main.js'] });
7066 *
7067 * // Evaluation expression in the Electron context.
7068 * const appPath = await electronApp.evaluate(async (electron) => {
7069 * // This runs in the main Electron process, |electron| parameter
7070 * // here is always the result of the require('electron') in the main
7071 * // app script.
7072 * return electron.getAppPath();
7073 * });
7074 *
7075 * // Get the first window that the app opens, wait if necessary.
7076 * const window = await electronApp.firstWindow();
7077 * // Print the title.
7078 * console.log(await window.title());
7079 * // Capture a screenshot.
7080 * await window.screenshot({ path: 'intro.png' });
7081 * // Direct Electron console to Node terminal.
7082 * window.on('console', console.log);
7083 * // Click button.
7084 * await window.click('text=Click me');
7085 * })();
7086 * ```
7087 *
7088 */
7089export interface ElectronApplication {
7090 /**
7091 * Returns the return value of `pageFunction`.
7092 *
7093 * If the function passed to the
7094 * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatepagefunction-arg)
7095 * returns a [Promise], then
7096 * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatepagefunction-arg)
7097 * would wait for the promise to resolve and return its value.
7098 *
7099 * If the function passed to the
7100 * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatepagefunction-arg)
7101 * returns a non-[Serializable] value, then
7102 * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatepagefunction-arg)
7103 * returns `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`:
7104 * `-0`, `NaN`, `Infinity`, `-Infinity`.
7105 * @param pageFunction Function to be evaluated in the worker context.
7106 * @param arg Optional argument to pass to `pageFunction`.
7107 */
7108 evaluate<R, Arg>(pageFunction: PageFunctionOn<ElectronType, Arg, R>, arg: Arg): Promise<R>;
7109 evaluate<R>(pageFunction: PageFunctionOn<ElectronType, void, R>, arg?: any): Promise<R>;
7110
7111 /**
7112 * Returns the return value of `pageFunction` as a [JSHandle].
7113 *
7114 * The only difference between
7115 * [electronApplication.evaluate(pageFunction[, arg])](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatepagefunction-arg)
7116 * and
7117 * [electronApplication.evaluateHandle(pageFunction, arg)](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatehandlepagefunction-arg)
7118 * is that
7119 * [electronApplication.evaluateHandle(pageFunction, arg)](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatehandlepagefunction-arg)
7120 * returns [JSHandle].
7121 *
7122 * If the function passed to the
7123 * [electronApplication.evaluateHandle(pageFunction, arg)](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatehandlepagefunction-arg)
7124 * returns a [Promise], then
7125 * [electronApplication.evaluateHandle(pageFunction, arg)](https://playwright.dev/docs/api/class-electronapplication#electronapplicationevaluatehandlepagefunction-arg)
7126 * would wait for the promise to resolve and return its value.
7127 * @param pageFunction Function to be evaluated in the worker context.
7128 * @param arg
7129 */
7130 evaluateHandle<R, Arg>(pageFunction: PageFunctionOn<ElectronType, Arg, R>, arg: Arg): Promise<SmartHandle<R>>;
7131 evaluateHandle<R>(pageFunction: PageFunctionOn<ElectronType, void, R>, arg?: any): Promise<SmartHandle<R>>;
7132 /**
7133 * This event is issued when the application closes.
7134 */
7135 on(event: 'close', listener: () => void): this;
7136
7137 /**
7138 * This event is issued for every window that is created **and loaded** in Electron. It contains a [Page] that can be used
7139 * for Playwright automation.
7140 */
7141 on(event: 'window', listener: (page: Page) => void): this;
7142
7143 /**
7144 * This event is issued when the application closes.
7145 */
7146 once(event: 'close', listener: () => void): this;
7147
7148 /**
7149 * This event is issued for every window that is created **and loaded** in Electron. It contains a [Page] that can be used
7150 * for Playwright automation.
7151 */
7152 once(event: 'window', listener: (page: Page) => void): this;
7153
7154 /**
7155 * This event is issued when the application closes.
7156 */
7157 addListener(event: 'close', listener: () => void): this;
7158
7159 /**
7160 * This event is issued for every window that is created **and loaded** in Electron. It contains a [Page] that can be used
7161 * for Playwright automation.
7162 */
7163 addListener(event: 'window', listener: (page: Page) => void): this;
7164
7165 /**
7166 * This event is issued when the application closes.
7167 */
7168 removeListener(event: 'close', listener: () => void): this;
7169
7170 /**
7171 * This event is issued for every window that is created **and loaded** in Electron. It contains a [Page] that can be used
7172 * for Playwright automation.
7173 */
7174 removeListener(event: 'window', listener: (page: Page) => void): this;
7175
7176 /**
7177 * This event is issued when the application closes.
7178 */
7179 off(event: 'close', listener: () => void): this;
7180
7181 /**
7182 * This event is issued for every window that is created **and loaded** in Electron. It contains a [Page] that can be used
7183 * for Playwright automation.
7184 */
7185 off(event: 'window', listener: (page: Page) => void): this;
7186
7187 /**
7188 * Closes Electron application.
7189 */
7190 close(): Promise<void>;
7191
7192 /**
7193 * This method returns browser context that can be used for setting up context-wide routing, etc.
7194 */
7195 context(): BrowserContext;
7196
7197 /**
7198 * Convenience method that waits for the first application window to be opened. Typically your script will start with:
7199 *
7200 * ```js
7201 * const electronApp = await electron.launch({
7202 * args: ['main.js']
7203 * });
7204 * const window = await electronApp.firstWindow();
7205 * // ...
7206 * ```
7207 *
7208 */
7209 firstWindow(): Promise<Page>;
7210
7211 /**
7212 * This event is issued when the application closes.
7213 */
7214 waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: () => boolean, timeout?: number } | (() => boolean)): Promise<void>;
7215
7216 /**
7217 * This event is issued for every window that is created **and loaded** in Electron. It contains a [Page] that can be used
7218 * for Playwright automation.
7219 */
7220 waitForEvent(event: 'window', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
7221
7222
7223 /**
7224 * Convenience method that returns all the opened windows.
7225 */
7226 windows(): Array<Page>;}
7227
7228export type AndroidElementInfo = {
7229 clazz: string;
7230 desc: string;
7231 res: string;
7232 pkg: string;
7233 text: string;
7234 bounds: { x: number, y: number, width: number, height: number };
7235 checkable: boolean;
7236 checked: boolean;
7237 clickable: boolean;
7238 enabled: boolean;
7239 focusable: boolean;
7240 focused: boolean;
7241 longClickable: boolean;
7242 scrollable: boolean;
7243 selected: boolean;
7244};
7245
7246export type AndroidSelector = {
7247 checkable?: boolean,
7248 checked?: boolean,
7249 clazz?: string | RegExp,
7250 clickable?: boolean,
7251 depth?: number,
7252 desc?: string | RegExp,
7253 enabled?: boolean,
7254 focusable?: boolean,
7255 focused?: boolean,
7256 hasChild?: { selector: AndroidSelector },
7257 hasDescendant?: { selector: AndroidSelector, maxDepth?: number },
7258 longClickable?: boolean,
7259 pkg?: string | RegExp,
7260 res?: string | RegExp,
7261 scrollable?: boolean,
7262 selected?: boolean,
7263 text?: string | RegExp,
7264};
7265
7266export type AndroidKey =
7267 'Unknown' |
7268 'SoftLeft' | 'SoftRight' |
7269 'Home' |
7270 'Back' |
7271 'Call' | 'EndCall' |
7272 '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
7273 'Star' | 'Pound' | '*' | '#' |
7274 'DialUp' | 'DialDown' | 'DialLeft' | 'DialRight' | 'DialCenter' |
7275 'VolumeUp' | 'VolumeDown' |
7276 'Power' |
7277 'Camera' |
7278 'Clear' |
7279 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' |
7280 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' |
7281 'Comma' | ',' |
7282 'Period' | '.' |
7283 'AltLeft' | 'AltRight' |
7284 'ShiftLeft' | 'ShiftRight' |
7285 'Tab' | '\t' |
7286 'Space' | ' ' |
7287 'Sym' |
7288 'Explorer' |
7289 'Envelop' |
7290 'Enter' | '\n' |
7291 'Del' |
7292 'Grave' |
7293 'Minus' | '-' |
7294 'Equals' | '=' |
7295 'LeftBracket' | '(' |
7296 'RightBracket' | ')' |
7297 'Backslash' | '\\' |
7298 'Semicolon' | ';' |
7299 'Apostrophe' | '`' |
7300 'Slash' | '/' |
7301 'At' | '@' |
7302 'Num' |
7303 'HeadsetHook' |
7304 'Focus' |
7305 'Plus' | '+' |
7306 'Menu' |
7307 'Notification' |
7308 'Search' |
7309 'RecentApps' |
7310 'AppSwitch' |
7311 'Assist' |
7312 'Cut' |
7313 'Copy' |
7314 'Paste';
7315
7316// This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459
7317export {};
7318
7319
7320/**
7321 * Playwright has **experimental** support for Android automation. You can access android namespace via:
7322 *
7323 * ```js
7324 * const { _android: android } = require('playwright');
7325 * ```
7326 *
7327 * An example of the Android automation script would be:
7328 *
7329 * ```js
7330 * const { _android: android } = require('playwright');
7331 *
7332 * (async () => {
7333 * // Connect to the device.
7334 * const [device] = await android.devices();
7335 * console.log(`Model: ${device.model()}`);
7336 * console.log(`Serial: ${device.serial()}`);
7337 * // Take screenshot of the whole device.
7338 * await device.screenshot({ path: 'device.png' });
7339 *
7340 * {
7341 * // --------------------- WebView -----------------------
7342 *
7343 * // Launch an application with WebView.
7344 * await device.shell('am force-stop org.chromium.webview_shell');
7345 * await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
7346 * // Get the WebView.
7347 * const webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
7348 *
7349 * // Fill the input box.
7350 * await device.fill({ res: 'org.chromium.webview_shell:id/url_field' }, 'github.com/microsoft/playwright');
7351 * await device.press({ res: 'org.chromium.webview_shell:id/url_field' }, 'Enter');
7352 *
7353 * // Work with WebView's page as usual.
7354 * const page = await webview.page();
7355 * await page.waitForNavigation({ url: /.*microsoft\/playwright.*\/ });
7356 * console.log(await page.title());
7357 * }
7358 *
7359 * {
7360 * // --------------------- Browser -----------------------
7361 *
7362 * // Launch Chrome browser.
7363 * await device.shell('am force-stop com.android.chrome');
7364 * const context = await device.launchBrowser();
7365 *
7366 * // Use BrowserContext as usual.
7367 * const page = await context.newPage();
7368 * await page.goto('https://webkit.org/');
7369 * console.log(await page.evaluate(() => window.location.href));
7370 * await page.screenshot({ path: 'page.png' });
7371 *
7372 * await context.close();
7373 * }
7374 *
7375 * // Close the device.
7376 * await device.close();
7377 * })();
7378 * ```
7379 *
7380 * Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
7381 * via setting the following environment variable when installing Playwright:
7382 *
7383 * ```sh js
7384 * $ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
7385 * ```
7386 *
7387 */
7388export interface Android {
7389 /**
7390 * Returns the list of detected Android devices.
7391 */
7392 devices(): Promise<Array<AndroidDevice>>;
7393
7394 /**
7395 * This setting will change the default maximum time for all the methods accepting `timeout` option.
7396 * @param timeout Maximum time in milliseconds
7397 */
7398 setDefaultTimeout(timeout: number): void;
7399}
7400
7401/**
7402 * [AndroidDevice] represents a connected device, either real hardware or emulated. Devices can be obtained using
7403 * [android.devices()](https://playwright.dev/docs/api/class-android#androiddevices).
7404 */
7405export interface AndroidDevice {
7406 /**
7407 * Emitted when a new WebView instance is detected.
7408 */
7409 on(event: 'webview', listener: (androidWebView: AndroidWebView) => void): this;
7410
7411 /**
7412 * Emitted when a new WebView instance is detected.
7413 */
7414 once(event: 'webview', listener: (androidWebView: AndroidWebView) => void): this;
7415
7416 /**
7417 * Emitted when a new WebView instance is detected.
7418 */
7419 addListener(event: 'webview', listener: (androidWebView: AndroidWebView) => void): this;
7420
7421 /**
7422 * Emitted when a new WebView instance is detected.
7423 */
7424 removeListener(event: 'webview', listener: (androidWebView: AndroidWebView) => void): this;
7425
7426 /**
7427 * Emitted when a new WebView instance is detected.
7428 */
7429 off(event: 'webview', listener: (androidWebView: AndroidWebView) => void): this;
7430
7431 /**
7432 * Disconnects from the device.
7433 */
7434 close(): Promise<void>;
7435
7436 /**
7437 * Drags the widget defined by `selector` towards `dest` point.
7438 * @param selector Selector to drag.
7439 * @param dest Point to drag to.
7440 * @param options
7441 */
7442 drag(selector: AndroidSelector, dest: {
7443 x: number;
7444
7445 y: number;
7446 }, options?: {
7447 /**
7448 * Optional speed of the drag in pixels per second.
7449 */
7450 speed?: number;
7451
7452 /**
7453 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7454 * using the
7455 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7456 * method.
7457 */
7458 timeout?: number;
7459 }): Promise<void>;
7460
7461 /**
7462 * Fills the specific `selector` input box with `text`.
7463 * @param selector Selector to fill.
7464 * @param text Text to be filled in the input box.
7465 * @param options
7466 */
7467 fill(selector: AndroidSelector, text: string, options?: {
7468 /**
7469 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7470 * using the
7471 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7472 * method.
7473 */
7474 timeout?: number;
7475 }): Promise<void>;
7476
7477 /**
7478 * Flings the widget defined by `selector` in the specified `direction`.
7479 * @param selector Selector to fling.
7480 * @param direction Fling direction.
7481 * @param options
7482 */
7483 fling(selector: AndroidSelector, direction: "down"|"up"|"left"|"right", options?: {
7484 /**
7485 * Optional speed of the fling in pixels per second.
7486 */
7487 speed?: number;
7488
7489 /**
7490 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7491 * using the
7492 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7493 * method.
7494 */
7495 timeout?: number;
7496 }): Promise<void>;
7497
7498 /**
7499 * Returns information about a widget defined by `selector`.
7500 * @param selector Selector to return information about.
7501 */
7502 info(selector: AndroidSelector): Promise<AndroidElementInfo>;
7503
7504 input: AndroidInput;
7505
7506 /**
7507 * Installs an apk on the device.
7508 * @param file Either a path to the apk file, or apk file content.
7509 * @param options
7510 */
7511 installApk(file: string|Buffer, options?: {
7512 /**
7513 * Optional arguments to pass to the `shell:cmd package install` call. Defaults to `-r -t -S`.
7514 */
7515 args?: Array<string>;
7516 }): Promise<void>;
7517
7518 /**
7519 * Launches Chrome browser on the device, and returns its persistent context.
7520 * @param options
7521 */
7522 launchBrowser(options?: {
7523 /**
7524 * Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
7525 */
7526 acceptDownloads?: boolean;
7527
7528 /**
7529 * Toggles bypassing page's Content-Security-Policy.
7530 */
7531 bypassCSP?: boolean;
7532
7533 /**
7534 * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
7535 * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
7536 * Defaults to `'light'`.
7537 */
7538 colorScheme?: "light"|"dark"|"no-preference";
7539
7540 /**
7541 * Optional package name to launch instead of default Chrome for Android.
7542 */
7543 command?: string;
7544
7545 /**
7546 * Specify device scale factor (can be thought of as dpr). Defaults to `1`.
7547 */
7548 deviceScaleFactor?: number;
7549
7550 /**
7551 * An object containing additional HTTP headers to be sent with every request. All header values must be strings.
7552 */
7553 extraHTTPHeaders?: { [key: string]: string; };
7554
7555 geolocation?: {
7556 /**
7557 * Latitude between -90 and 90.
7558 */
7559 latitude: number;
7560
7561 /**
7562 * Longitude between -180 and 180.
7563 */
7564 longitude: number;
7565
7566 /**
7567 * Non-negative accuracy value. Defaults to `0`.
7568 */
7569 accuracy?: number;
7570 };
7571
7572 /**
7573 * Specifies if viewport supports touch events. Defaults to false.
7574 */
7575 hasTouch?: boolean;
7576
7577 /**
7578 * Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
7579 */
7580 httpCredentials?: {
7581 username: string;
7582
7583 password: string;
7584 };
7585
7586 /**
7587 * Whether to ignore HTTPS errors during navigation. Defaults to `false`.
7588 */
7589 ignoreHTTPSErrors?: boolean;
7590
7591 /**
7592 * Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported
7593 * in Firefox.
7594 */
7595 isMobile?: boolean;
7596
7597 /**
7598 * Whether or not to enable JavaScript in the context. Defaults to `true`.
7599 */
7600 javaScriptEnabled?: boolean;
7601
7602 /**
7603 * Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language`
7604 * request header value as well as number and date formatting rules.
7605 */
7606 locale?: string;
7607
7608 /**
7609 * Logger sink for Playwright logging.
7610 */
7611 logger?: Logger;
7612
7613 /**
7614 * Whether to emulate network being offline. Defaults to `false`.
7615 */
7616 offline?: boolean;
7617
7618 /**
7619 * A list of permissions to grant to all pages in this context. See
7620 * [browserContext.grantPermissions(permissions[, options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextgrantpermissionspermissions-options)
7621 * for more details.
7622 */
7623 permissions?: Array<string>;
7624
7625 /**
7626 * Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
7627 * specified, the HAR is not recorded. Make sure to await
7628 * [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for the HAR to be
7629 * saved.
7630 */
7631 recordHar?: {
7632 /**
7633 * Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
7634 */
7635 omitContent?: boolean;
7636
7637 /**
7638 * Path on the filesystem to write the HAR file to.
7639 */
7640 path: string;
7641 };
7642
7643 /**
7644 * Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
7645 * sure to await [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for
7646 * videos to be saved.
7647 */
7648 recordVideo?: {
7649 /**
7650 * Path to the directory to put videos into.
7651 */
7652 dir: string;
7653
7654 /**
7655 * Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit
7656 * into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page
7657 * will be scaled down if necessary to fit the specified size.
7658 */
7659 size?: {
7660 /**
7661 * Video frame width.
7662 */
7663 width: number;
7664
7665 /**
7666 * Video frame height.
7667 */
7668 height: number;
7669 };
7670 };
7671
7672 /**
7673 * Changes the timezone of the context. See
7674 * [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
7675 * for a list of supported timezone IDs.
7676 */
7677 timezoneId?: string;
7678
7679 /**
7680 * Specific user agent to use in this context.
7681 */
7682 userAgent?: string;
7683
7684 /**
7685 * **DEPRECATED** Use `recordVideo` instead.
7686 * @deprecated
7687 */
7688 videoSize?: {
7689 /**
7690 * Video frame width.
7691 */
7692 width: number;
7693
7694 /**
7695 * Video frame height.
7696 */
7697 height: number;
7698 };
7699
7700 /**
7701 * **DEPRECATED** Use `recordVideo` instead.
7702 * @deprecated
7703 */
7704 videosPath?: string;
7705
7706 /**
7707 * Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.
7708 */
7709 viewport?: null|{
7710 /**
7711 * page width in pixels.
7712 */
7713 width: number;
7714
7715 /**
7716 * page height in pixels.
7717 */
7718 height: number;
7719 };
7720 }): Promise<ChromiumBrowserContext>;
7721
7722 /**
7723 * Performs a long tap on the widget defined by `selector`.
7724 * @param selector Selector to tap on.
7725 * @param options
7726 */
7727 longTap(selector: AndroidSelector, options?: {
7728 /**
7729 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7730 * using the
7731 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7732 * method.
7733 */
7734 timeout?: number;
7735 }): Promise<void>;
7736
7737 /**
7738 * Device model.
7739 */
7740 model(): string;
7741
7742 /**
7743 * Launches a process in the shell on the device and returns a socket to communicate with the launched process.
7744 * @param command
7745 */
7746 open(command: string): Promise<AndroidSocket>;
7747
7748 /**
7749 * Pinches the widget defined by `selector` in the closing direction.
7750 * @param selector Selector to pinch close.
7751 * @param percent The size of the pinch as a percentage of the widget's size.
7752 * @param options
7753 */
7754 pinchClose(selector: AndroidSelector, percent: number, options?: {
7755 /**
7756 * Optional speed of the pinch in pixels per second.
7757 */
7758 speed?: number;
7759
7760 /**
7761 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7762 * using the
7763 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7764 * method.
7765 */
7766 timeout?: number;
7767 }): Promise<void>;
7768
7769 /**
7770 * Pinches the widget defined by `selector` in the open direction.
7771 * @param selector Selector to pinch open.
7772 * @param percent The size of the pinch as a percentage of the widget's size.
7773 * @param options
7774 */
7775 pinchOpen(selector: AndroidSelector, percent: number, options?: {
7776 /**
7777 * Optional speed of the pinch in pixels per second.
7778 */
7779 speed?: number;
7780
7781 /**
7782 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7783 * using the
7784 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7785 * method.
7786 */
7787 timeout?: number;
7788 }): Promise<void>;
7789
7790 /**
7791 * Presses the specific `key` in the widget defined by `selector`.
7792 * @param selector Selector to press the key in.
7793 * @param key The key to press.
7794 * @param options
7795 */
7796 press(selector: AndroidSelector, key: AndroidKey, options?: {
7797 /**
7798 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7799 * using the
7800 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7801 * method.
7802 */
7803 timeout?: number;
7804 }): Promise<void>;
7805
7806 /**
7807 * Copies a file to the device.
7808 * @param file Either a path to the file, or file content.
7809 * @param path Path to the file on the device.
7810 * @param options
7811 */
7812 push(file: string|Buffer, path: string, options?: {
7813 /**
7814 * Optional file mode, defaults to `644` (`rw-r--r--`).
7815 */
7816 mode?: number;
7817 }): Promise<void>;
7818
7819 /**
7820 * Returns the buffer with the captured screenshot of the device.
7821 * @param options
7822 */
7823 screenshot(options?: {
7824 /**
7825 * The file path to save the image to. If `path` is a relative path, then it is resolved relative to the current working
7826 * directory. If no path is provided, the image won't be saved to the disk.
7827 */
7828 path?: string;
7829 }): Promise<Buffer>;
7830
7831 /**
7832 * Scrolls the widget defined by `selector` in the specified `direction`.
7833 * @param selector Selector to scroll.
7834 * @param direction Scroll direction.
7835 * @param percent Distance to scroll as a percentage of the widget's size.
7836 * @param options
7837 */
7838 scroll(selector: AndroidSelector, direction: "down"|"up"|"left"|"right", percent: number, options?: {
7839 /**
7840 * Optional speed of the scroll in pixels per second.
7841 */
7842 speed?: number;
7843
7844 /**
7845 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7846 * using the
7847 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7848 * method.
7849 */
7850 timeout?: number;
7851 }): Promise<void>;
7852
7853 /**
7854 * Device serial number.
7855 */
7856 serial(): string;
7857
7858 /**
7859 * This setting will change the default maximum time for all the methods accepting `timeout` option.
7860 * @param timeout Maximum time in milliseconds
7861 */
7862 setDefaultTimeout(timeout: number): void;
7863
7864 /**
7865 * Executes a shell command on the device and returns its output.
7866 * @param command Shell command to execute.
7867 */
7868 shell(command: string): Promise<Buffer>;
7869
7870 /**
7871 * Swipes the widget defined by `selector` in the specified `direction`.
7872 * @param selector Selector to swipe.
7873 * @param direction Swipe direction.
7874 * @param percent Distance to swipe as a percentage of the widget's size.
7875 * @param options
7876 */
7877 swipe(selector: AndroidSelector, direction: "down"|"up"|"left"|"right", percent: number, options?: {
7878 /**
7879 * Optional speed of the swipe in pixels per second.
7880 */
7881 speed?: number;
7882
7883 /**
7884 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7885 * using the
7886 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7887 * method.
7888 */
7889 timeout?: number;
7890 }): Promise<void>;
7891
7892 /**
7893 * Taps on the widget defined by `selector`.
7894 * @param selector Selector to tap on.
7895 * @param options
7896 */
7897 tap(selector: AndroidSelector, options?: {
7898 /**
7899 * Optional duration of the tap in milliseconds.
7900 */
7901 duration?: number;
7902
7903 /**
7904 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7905 * using the
7906 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7907 * method.
7908 */
7909 timeout?: number;
7910 }): Promise<void>;
7911
7912 /**
7913 * Waits for the specific `selector` to either appear or disappear, depending on the `state`.
7914 * @param selector Selector to wait for.
7915 * @param options
7916 */
7917 wait(selector: AndroidSelector, options?: {
7918 /**
7919 * Optional state. Can be either:
7920 * - default - wait for element to be present.
7921 * - `'gone'` - wait for element to not be present.
7922 */
7923 state?: "gone";
7924
7925 /**
7926 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7927 * using the
7928 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7929 * method.
7930 */
7931 timeout?: number;
7932 }): Promise<void>;
7933
7934 /**
7935 * Emitted when a new WebView instance is detected.
7936 */
7937 waitForEvent(event: 'webview', optionsOrPredicate?: { predicate?: (androidWebView: AndroidWebView) => boolean, timeout?: number } | ((androidWebView: AndroidWebView) => boolean)): Promise<AndroidWebView>;
7938
7939
7940 /**
7941 * This method waits until [AndroidWebView] matching the `selector` is opened and returns it. If there is already an open
7942 * [AndroidWebView] matching the `selector`, returns immediately.
7943 * @param selector
7944 * @param options
7945 */
7946 webView(selector: {
7947 /**
7948 * Package identifier.
7949 */
7950 pkg: string;
7951 }, options?: {
7952 /**
7953 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
7954 * using the
7955 * [androidDevice.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-androiddevice#androiddevicesetdefaulttimeouttimeout)
7956 * method.
7957 */
7958 timeout?: number;
7959 }): Promise<AndroidWebView>;
7960
7961 /**
7962 * Currently open WebViews.
7963 */
7964 webViews(): Array<AndroidWebView>;
7965}
7966
7967export interface AndroidInput {
7968 /**
7969 * Performs a drag between `from` and `to` points.
7970 * @param from The start point of the drag.
7971 * @param to The end point of the drag.
7972 * @param steps The number of steps in the drag. Each step takes 5 milliseconds to complete.
7973 */
7974 drag(from: {
7975 x: number;
7976
7977 y: number;
7978 }, to: {
7979 x: number;
7980
7981 y: number;
7982 }, steps: number): Promise<void>;
7983
7984 /**
7985 * Presses the `key`.
7986 * @param key Key to press.
7987 */
7988 press(key: AndroidKey): Promise<void>;
7989
7990 /**
7991 * Swipes following the path defined by `segments`.
7992 * @param from The point to start swiping from.
7993 * @param segments Points following the `from` point in the swipe gesture.
7994 * @param steps The number of steps for each segment. Each step takes 5 milliseconds to complete, so 100 steps means half a second per each segment.
7995 */
7996 swipe(from: {
7997 x: number;
7998
7999 y: number;
8000 }, segments: Array<{
8001 x: number;
8002
8003 y: number;
8004 }>, steps: number): Promise<void>;
8005
8006 /**
8007 * Taps at the specified `point`.
8008 * @param point The point to tap at.
8009 */
8010 tap(point: {
8011 x: number;
8012
8013 y: number;
8014 }): Promise<void>;
8015
8016 /**
8017 * Types `text` into currently focused widget.
8018 * @param text Text to type.
8019 */
8020 type(text: string): Promise<void>;
8021}
8022
8023/**
8024 * [AndroidSocket] is a way to communicate with a process launched on the [AndroidDevice]. Use
8025 * [androidDevice.open(command)](https://playwright.dev/docs/api/class-androiddevice#androiddeviceopencommand) to open a
8026 * socket.
8027 */
8028export interface AndroidSocket {
8029 /**
8030 * Emitted when the socket is closed.
8031 */
8032 on(event: 'close', listener: () => void): this;
8033
8034 /**
8035 * Emitted when data is available to read from the socket.
8036 */
8037 on(event: 'data', listener: (buffer: Buffer) => void): this;
8038
8039 /**
8040 * Emitted when the socket is closed.
8041 */
8042 once(event: 'close', listener: () => void): this;
8043
8044 /**
8045 * Emitted when data is available to read from the socket.
8046 */
8047 once(event: 'data', listener: (buffer: Buffer) => void): this;
8048
8049 /**
8050 * Emitted when the socket is closed.
8051 */
8052 addListener(event: 'close', listener: () => void): this;
8053
8054 /**
8055 * Emitted when data is available to read from the socket.
8056 */
8057 addListener(event: 'data', listener: (buffer: Buffer) => void): this;
8058
8059 /**
8060 * Emitted when the socket is closed.
8061 */
8062 removeListener(event: 'close', listener: () => void): this;
8063
8064 /**
8065 * Emitted when data is available to read from the socket.
8066 */
8067 removeListener(event: 'data', listener: (buffer: Buffer) => void): this;
8068
8069 /**
8070 * Emitted when the socket is closed.
8071 */
8072 off(event: 'close', listener: () => void): this;
8073
8074 /**
8075 * Emitted when data is available to read from the socket.
8076 */
8077 off(event: 'data', listener: (buffer: Buffer) => void): this;
8078
8079 /**
8080 * Closes the socket.
8081 */
8082 close(): Promise<void>;
8083
8084 /**
8085 * Writes some `data` to the socket.
8086 * @param data Data to write.
8087 */
8088 write(data: Buffer): Promise<void>;
8089}
8090
8091/**
8092 * [AndroidWebView] represents a WebView open on the [AndroidDevice]. WebView is usually obtained using
8093 * [androidDevice.webView(selector[, options])](https://playwright.dev/docs/api/class-androiddevice#androiddevicewebviewselector-options).
8094 */
8095export interface AndroidWebView {
8096 /**
8097 * Emitted when the WebView is closed.
8098 */
8099 on(event: 'close', listener: () => void): this;
8100
8101 /**
8102 * Emitted when the WebView is closed.
8103 */
8104 once(event: 'close', listener: () => void): this;
8105
8106 /**
8107 * Emitted when the WebView is closed.
8108 */
8109 addListener(event: 'close', listener: () => void): this;
8110
8111 /**
8112 * Emitted when the WebView is closed.
8113 */
8114 removeListener(event: 'close', listener: () => void): this;
8115
8116 /**
8117 * Emitted when the WebView is closed.
8118 */
8119 off(event: 'close', listener: () => void): this;
8120
8121 /**
8122 * Connects to the WebView and returns a regular Playwright [Page] to interact with.
8123 */
8124 page(): Promise<Page>;
8125
8126 /**
8127 * WebView process PID.
8128 */
8129 pid(): number;
8130
8131 /**
8132 * WebView package identifier.
8133 */
8134 pkg(): string;
8135}
8136
8137/**
8138 * - extends: [EventEmitter]
8139 *
8140 * A Browser is created via
8141 * [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchoptions). An example
8142 * of using a [Browser] to create a [Page]:
8143 *
8144 * ```js
8145 * const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
8146 *
8147 * (async () => {
8148 * const browser = await firefox.launch();
8149 * const page = await browser.newPage();
8150 * await page.goto('https://example.com');
8151 * await browser.close();
8152 * })();
8153 * ```
8154 *
8155 */
8156export interface Browser extends EventEmitter {
8157 /**
8158 * Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
8159 * - Browser application is closed or crashed.
8160 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8161 */
8162 on(event: 'disconnected', listener: (browser: Browser) => void): this;
8163
8164 /**
8165 * Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
8166 * - Browser application is closed or crashed.
8167 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8168 */
8169 once(event: 'disconnected', listener: (browser: Browser) => void): this;
8170
8171 /**
8172 * Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
8173 * - Browser application is closed or crashed.
8174 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8175 */
8176 addListener(event: 'disconnected', listener: (browser: Browser) => void): this;
8177
8178 /**
8179 * Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
8180 * - Browser application is closed or crashed.
8181 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8182 */
8183 removeListener(event: 'disconnected', listener: (browser: Browser) => void): this;
8184
8185 /**
8186 * Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:
8187 * - Browser application is closed or crashed.
8188 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8189 */
8190 off(event: 'disconnected', listener: (browser: Browser) => void): this;
8191
8192 /**
8193 * In case this browser is obtained using
8194 * [browserType.launch([options])](https://playwright.dev/docs/api/class-browsertype#browsertypelaunchoptions), closes the
8195 * browser and all of its pages (if any were opened).
8196 *
8197 * In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
8198 * browser server.
8199 *
8200 * The [Browser] object itself is considered to be disposed and cannot be used anymore.
8201 */
8202 close(): Promise<void>;
8203
8204 /**
8205 * Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
8206 *
8207 * ```js
8208 * const browser = await pw.webkit.launch();
8209 * console.log(browser.contexts().length); // prints `0`
8210 *
8211 * const context = await browser.newContext();
8212 * console.log(browser.contexts().length); // prints `1`
8213 * ```
8214 *
8215 */
8216 contexts(): Array<BrowserContext>;
8217
8218 /**
8219 * Indicates that the browser is connected.
8220 */
8221 isConnected(): boolean;
8222
8223 /**
8224 * Creates a new browser context. It won't share cookies/cache with other browser contexts.
8225 *
8226 * ```js
8227 * (async () => {
8228 * const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.
8229 * // Create a new incognito browser context.
8230 * const context = await browser.newContext();
8231 * // Create a new page in a pristine context.
8232 * const page = await context.newPage();
8233 * await page.goto('https://example.com');
8234 * })();
8235 * ```
8236 *
8237 * @param options
8238 */
8239 newContext(options?: BrowserContextOptions): Promise<BrowserContext>;
8240
8241 /**
8242 * Creates a new page in a new browser context. Closing this page will close the context as well.
8243 *
8244 * This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
8245 * testing frameworks should explicitly create
8246 * [browser.newContext([options])](https://playwright.dev/docs/api/class-browser#browsernewcontextoptions) followed by the
8247 * [browserContext.newPage()](https://playwright.dev/docs/api/class-browsercontext#browsercontextnewpage) to control their
8248 * exact life times.
8249 * @param options
8250 */
8251 newPage(options?: {
8252 /**
8253 * Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
8254 */
8255 acceptDownloads?: boolean;
8256
8257 /**
8258 * Toggles bypassing page's Content-Security-Policy.
8259 */
8260 bypassCSP?: boolean;
8261
8262 /**
8263 * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
8264 * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
8265 * Defaults to `'light'`.
8266 */
8267 colorScheme?: "light"|"dark"|"no-preference";
8268
8269 /**
8270 * Specify device scale factor (can be thought of as dpr). Defaults to `1`.
8271 */
8272 deviceScaleFactor?: number;
8273
8274 /**
8275 * An object containing additional HTTP headers to be sent with every request. All header values must be strings.
8276 */
8277 extraHTTPHeaders?: { [key: string]: string; };
8278
8279 geolocation?: {
8280 /**
8281 * Latitude between -90 and 90.
8282 */
8283 latitude: number;
8284
8285 /**
8286 * Longitude between -180 and 180.
8287 */
8288 longitude: number;
8289
8290 /**
8291 * Non-negative accuracy value. Defaults to `0`.
8292 */
8293 accuracy?: number;
8294 };
8295
8296 /**
8297 * Specifies if viewport supports touch events. Defaults to false.
8298 */
8299 hasTouch?: boolean;
8300
8301 /**
8302 * Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
8303 */
8304 httpCredentials?: {
8305 username: string;
8306
8307 password: string;
8308 };
8309
8310 /**
8311 * Whether to ignore HTTPS errors during navigation. Defaults to `false`.
8312 */
8313 ignoreHTTPSErrors?: boolean;
8314
8315 /**
8316 * Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported
8317 * in Firefox.
8318 */
8319 isMobile?: boolean;
8320
8321 /**
8322 * Whether or not to enable JavaScript in the context. Defaults to `true`.
8323 */
8324 javaScriptEnabled?: boolean;
8325
8326 /**
8327 * Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language`
8328 * request header value as well as number and date formatting rules.
8329 */
8330 locale?: string;
8331
8332 /**
8333 * Logger sink for Playwright logging.
8334 */
8335 logger?: Logger;
8336
8337 /**
8338 * Whether to emulate network being offline. Defaults to `false`.
8339 */
8340 offline?: boolean;
8341
8342 /**
8343 * A list of permissions to grant to all pages in this context. See
8344 * [browserContext.grantPermissions(permissions[, options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextgrantpermissionspermissions-options)
8345 * for more details.
8346 */
8347 permissions?: Array<string>;
8348
8349 /**
8350 * Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this
8351 * option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
8352 * `launch({ proxy: { server: 'per-context' } })`.
8353 */
8354 proxy?: {
8355 /**
8356 * Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or
8357 * `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
8358 */
8359 server: string;
8360
8361 /**
8362 * Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
8363 */
8364 bypass?: string;
8365
8366 /**
8367 * Optional username to use if HTTP proxy requires authentication.
8368 */
8369 username?: string;
8370
8371 /**
8372 * Optional password to use if HTTP proxy requires authentication.
8373 */
8374 password?: string;
8375 };
8376
8377 /**
8378 * Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
8379 * specified, the HAR is not recorded. Make sure to await
8380 * [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for the HAR to be
8381 * saved.
8382 */
8383 recordHar?: {
8384 /**
8385 * Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
8386 */
8387 omitContent?: boolean;
8388
8389 /**
8390 * Path on the filesystem to write the HAR file to.
8391 */
8392 path: string;
8393 };
8394
8395 /**
8396 * Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
8397 * sure to await [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for
8398 * videos to be saved.
8399 */
8400 recordVideo?: {
8401 /**
8402 * Path to the directory to put videos into.
8403 */
8404 dir: string;
8405
8406 /**
8407 * Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit
8408 * into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page
8409 * will be scaled down if necessary to fit the specified size.
8410 */
8411 size?: {
8412 /**
8413 * Video frame width.
8414 */
8415 width: number;
8416
8417 /**
8418 * Video frame height.
8419 */
8420 height: number;
8421 };
8422 };
8423
8424 /**
8425 * Populates context with given storage state. This option can be used to initialize context with logged-in information
8426 * obtained via
8427 * [browserContext.storageState([options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextstoragestateoptions).
8428 * Either a path to the file with saved storage, or an object with the following fields:
8429 */
8430 storageState?: string|{
8431 /**
8432 * Optional cookies to set for context
8433 */
8434 cookies?: Array<{
8435 name: string;
8436
8437 value: string;
8438
8439 /**
8440 * Optional either url or domain / path are required
8441 */
8442 url?: string;
8443
8444 /**
8445 * Optional either url or domain / path are required
8446 */
8447 domain?: string;
8448
8449 /**
8450 * Optional either url or domain / path are required
8451 */
8452 path?: string;
8453
8454 /**
8455 * Optional Unix time in seconds.
8456 */
8457 expires?: number;
8458
8459 /**
8460 * Optional httpOnly flag
8461 */
8462 httpOnly?: boolean;
8463
8464 /**
8465 * Optional secure flag
8466 */
8467 secure?: boolean;
8468
8469 /**
8470 * Optional sameSite flag
8471 */
8472 sameSite?: "Strict"|"Lax"|"None";
8473 }>;
8474
8475 /**
8476 * Optional localStorage to set for context
8477 */
8478 origins?: Array<{
8479 origin: string;
8480
8481 localStorage: Array<{
8482 name: string;
8483
8484 value: string;
8485 }>;
8486 }>;
8487 };
8488
8489 /**
8490 * Changes the timezone of the context. See
8491 * [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
8492 * for a list of supported timezone IDs.
8493 */
8494 timezoneId?: string;
8495
8496 /**
8497 * Specific user agent to use in this context.
8498 */
8499 userAgent?: string;
8500
8501 /**
8502 * **DEPRECATED** Use `recordVideo` instead.
8503 * @deprecated
8504 */
8505 videoSize?: {
8506 /**
8507 * Video frame width.
8508 */
8509 width: number;
8510
8511 /**
8512 * Video frame height.
8513 */
8514 height: number;
8515 };
8516
8517 /**
8518 * **DEPRECATED** Use `recordVideo` instead.
8519 * @deprecated
8520 */
8521 videosPath?: string;
8522
8523 /**
8524 * Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.
8525 */
8526 viewport?: null|{
8527 /**
8528 * page width in pixels.
8529 */
8530 width: number;
8531
8532 /**
8533 * page height in pixels.
8534 */
8535 height: number;
8536 };
8537 }): Promise<Page>;
8538
8539 /**
8540 * Returns the browser version.
8541 */
8542 version(): string;
8543}
8544
8545export interface BrowserServer {
8546 /**
8547 * Emitted when the browser server closes.
8548 */
8549 on(event: 'close', listener: () => void): this;
8550
8551 /**
8552 * Emitted when the browser server closes.
8553 */
8554 once(event: 'close', listener: () => void): this;
8555
8556 /**
8557 * Emitted when the browser server closes.
8558 */
8559 addListener(event: 'close', listener: () => void): this;
8560
8561 /**
8562 * Emitted when the browser server closes.
8563 */
8564 removeListener(event: 'close', listener: () => void): this;
8565
8566 /**
8567 * Emitted when the browser server closes.
8568 */
8569 off(event: 'close', listener: () => void): this;
8570
8571 /**
8572 * Closes the browser gracefully and makes sure the process is terminated.
8573 */
8574 close(): Promise<void>;
8575
8576 /**
8577 * Kills the browser process and waits for the process to exit.
8578 */
8579 kill(): Promise<void>;
8580
8581 /**
8582 * Spawned browser application process.
8583 */
8584 process(): ChildProcess;
8585
8586 /**
8587 * Browser websocket url.
8588 *
8589 * Browser websocket endpoint which can be used as an argument to
8590 * [browserType.connect(params)](https://playwright.dev/docs/api/class-browsertype#browsertypeconnectparams) to establish
8591 * connection to the browser.
8592 */
8593 wsEndpoint(): string;
8594}
8595
8596/**
8597 * - extends: [BrowserContext]
8598 *
8599 * Chromium-specific features including background pages, service worker support, etc.
8600 *
8601 * ```js
8602 * const backgroundPage = await context.waitForEvent('backgroundpage');
8603 * ```
8604 *
8605 */
8606export interface ChromiumBrowserContext extends BrowserContext {
8607 /**
8608 * Emitted when new background page is created in the context.
8609 *
8610 * > NOTE: Only works with persistent context.
8611 */
8612 on(event: 'backgroundpage', listener: (page: Page) => void): this;
8613
8614 /**
8615 * Emitted when new service worker is created in the context.
8616 */
8617 on(event: 'serviceworker', listener: (worker: Worker) => void): this;
8618
8619 /**
8620 * Emitted when Browser context gets closed. This might happen because of one of the following:
8621 * - Browser context is closed.
8622 * - Browser application is closed or crashed.
8623 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8624 */
8625 on(event: 'close', listener: (browserContext: BrowserContext) => void): this;
8626
8627 /**
8628 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
8629 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
8630 * receive events about popups relevant to a specific page.
8631 *
8632 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
8633 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
8634 * done and its response has started loading in the popup.
8635 *
8636 * ```js
8637 * const [newPage] = await Promise.all([
8638 * context.waitForEvent('page'),
8639 * page.click('a[target=_blank]'),
8640 * ]);
8641 * console.log(await newPage.evaluate('location.href'));
8642 * ```
8643 *
8644 * > NOTE: Use
8645 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
8646 * to wait until the page gets to a particular state (you should not need it in most cases).
8647 */
8648 on(event: 'page', listener: (page: Page) => void): this;
8649
8650 /**
8651 * Emitted when new background page is created in the context.
8652 *
8653 * > NOTE: Only works with persistent context.
8654 */
8655 once(event: 'backgroundpage', listener: (page: Page) => void): this;
8656
8657 /**
8658 * Emitted when new service worker is created in the context.
8659 */
8660 once(event: 'serviceworker', listener: (worker: Worker) => void): this;
8661
8662 /**
8663 * Emitted when Browser context gets closed. This might happen because of one of the following:
8664 * - Browser context is closed.
8665 * - Browser application is closed or crashed.
8666 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8667 */
8668 once(event: 'close', listener: (browserContext: BrowserContext) => void): this;
8669
8670 /**
8671 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
8672 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
8673 * receive events about popups relevant to a specific page.
8674 *
8675 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
8676 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
8677 * done and its response has started loading in the popup.
8678 *
8679 * ```js
8680 * const [newPage] = await Promise.all([
8681 * context.waitForEvent('page'),
8682 * page.click('a[target=_blank]'),
8683 * ]);
8684 * console.log(await newPage.evaluate('location.href'));
8685 * ```
8686 *
8687 * > NOTE: Use
8688 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
8689 * to wait until the page gets to a particular state (you should not need it in most cases).
8690 */
8691 once(event: 'page', listener: (page: Page) => void): this;
8692
8693 /**
8694 * Emitted when new background page is created in the context.
8695 *
8696 * > NOTE: Only works with persistent context.
8697 */
8698 addListener(event: 'backgroundpage', listener: (page: Page) => void): this;
8699
8700 /**
8701 * Emitted when new service worker is created in the context.
8702 */
8703 addListener(event: 'serviceworker', listener: (worker: Worker) => void): this;
8704
8705 /**
8706 * Emitted when Browser context gets closed. This might happen because of one of the following:
8707 * - Browser context is closed.
8708 * - Browser application is closed or crashed.
8709 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8710 */
8711 addListener(event: 'close', listener: (browserContext: BrowserContext) => void): this;
8712
8713 /**
8714 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
8715 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
8716 * receive events about popups relevant to a specific page.
8717 *
8718 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
8719 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
8720 * done and its response has started loading in the popup.
8721 *
8722 * ```js
8723 * const [newPage] = await Promise.all([
8724 * context.waitForEvent('page'),
8725 * page.click('a[target=_blank]'),
8726 * ]);
8727 * console.log(await newPage.evaluate('location.href'));
8728 * ```
8729 *
8730 * > NOTE: Use
8731 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
8732 * to wait until the page gets to a particular state (you should not need it in most cases).
8733 */
8734 addListener(event: 'page', listener: (page: Page) => void): this;
8735
8736 /**
8737 * Emitted when new background page is created in the context.
8738 *
8739 * > NOTE: Only works with persistent context.
8740 */
8741 removeListener(event: 'backgroundpage', listener: (page: Page) => void): this;
8742
8743 /**
8744 * Emitted when new service worker is created in the context.
8745 */
8746 removeListener(event: 'serviceworker', listener: (worker: Worker) => void): this;
8747
8748 /**
8749 * Emitted when Browser context gets closed. This might happen because of one of the following:
8750 * - Browser context is closed.
8751 * - Browser application is closed or crashed.
8752 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8753 */
8754 removeListener(event: 'close', listener: (browserContext: BrowserContext) => void): this;
8755
8756 /**
8757 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
8758 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
8759 * receive events about popups relevant to a specific page.
8760 *
8761 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
8762 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
8763 * done and its response has started loading in the popup.
8764 *
8765 * ```js
8766 * const [newPage] = await Promise.all([
8767 * context.waitForEvent('page'),
8768 * page.click('a[target=_blank]'),
8769 * ]);
8770 * console.log(await newPage.evaluate('location.href'));
8771 * ```
8772 *
8773 * > NOTE: Use
8774 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
8775 * to wait until the page gets to a particular state (you should not need it in most cases).
8776 */
8777 removeListener(event: 'page', listener: (page: Page) => void): this;
8778
8779 /**
8780 * Emitted when new background page is created in the context.
8781 *
8782 * > NOTE: Only works with persistent context.
8783 */
8784 off(event: 'backgroundpage', listener: (page: Page) => void): this;
8785
8786 /**
8787 * Emitted when new service worker is created in the context.
8788 */
8789 off(event: 'serviceworker', listener: (worker: Worker) => void): this;
8790
8791 /**
8792 * Emitted when Browser context gets closed. This might happen because of one of the following:
8793 * - Browser context is closed.
8794 * - Browser application is closed or crashed.
8795 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8796 */
8797 off(event: 'close', listener: (browserContext: BrowserContext) => void): this;
8798
8799 /**
8800 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
8801 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
8802 * receive events about popups relevant to a specific page.
8803 *
8804 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
8805 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
8806 * done and its response has started loading in the popup.
8807 *
8808 * ```js
8809 * const [newPage] = await Promise.all([
8810 * context.waitForEvent('page'),
8811 * page.click('a[target=_blank]'),
8812 * ]);
8813 * console.log(await newPage.evaluate('location.href'));
8814 * ```
8815 *
8816 * > NOTE: Use
8817 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
8818 * to wait until the page gets to a particular state (you should not need it in most cases).
8819 */
8820 off(event: 'page', listener: (page: Page) => void): this;
8821
8822 /**
8823 * All existing background pages in the context.
8824 */
8825 backgroundPages(): Array<Page>;
8826
8827 /**
8828 * Returns the newly created session.
8829 * @param page Page to create new session for.
8830 */
8831 newCDPSession(page: Page): Promise<CDPSession>;
8832
8833 /**
8834 * All existing service workers in the context.
8835 */
8836 serviceWorkers(): Array<Worker>;
8837
8838 /**
8839 * Emitted when new background page is created in the context.
8840 *
8841 * > NOTE: Only works with persistent context.
8842 */
8843 waitForEvent(event: 'backgroundpage', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
8844
8845 /**
8846 * Emitted when new service worker is created in the context.
8847 */
8848 waitForEvent(event: 'serviceworker', optionsOrPredicate?: { predicate?: (worker: Worker) => boolean, timeout?: number } | ((worker: Worker) => boolean)): Promise<Worker>;
8849
8850 /**
8851 * Emitted when Browser context gets closed. This might happen because of one of the following:
8852 * - Browser context is closed.
8853 * - Browser application is closed or crashed.
8854 * - The [browser.close()](https://playwright.dev/docs/api/class-browser#browserclose) method was called.
8855 */
8856 waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (browserContext: BrowserContext) => boolean, timeout?: number } | ((browserContext: BrowserContext) => boolean)): Promise<BrowserContext>;
8857
8858 /**
8859 * The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event will
8860 * also fire for popup pages. See also [page.on('popup')](https://playwright.dev/docs/api/class-page#pageonpopup) to
8861 * receive events about popups relevant to a specific page.
8862 *
8863 * The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a
8864 * popup with `window.open('http://example.com')`, this event will fire when the network request to "http://example.com" is
8865 * done and its response has started loading in the popup.
8866 *
8867 * ```js
8868 * const [newPage] = await Promise.all([
8869 * context.waitForEvent('page'),
8870 * page.click('a[target=_blank]'),
8871 * ]);
8872 * console.log(await newPage.evaluate('location.href'));
8873 * ```
8874 *
8875 * > NOTE: Use
8876 * [page.waitForLoadState([state, options])](https://playwright.dev/docs/api/class-page#pagewaitforloadstatestate-options)
8877 * to wait until the page gets to a particular state (you should not need it in most cases).
8878 */
8879 waitForEvent(event: 'page', optionsOrPredicate?: { predicate?: (page: Page) => boolean, timeout?: number } | ((page: Page) => boolean)): Promise<Page>;
8880
8881}
8882
8883/**
8884 * Coverage gathers information about parts of JavaScript and CSS that were used by the page.
8885 *
8886 * An example of using JavaScript coverage to produce Istambul report for page load:
8887 *
8888 * ```js
8889 * const { chromium } = require('playwright');
8890 * const v8toIstanbul = require('v8-to-istanbul');
8891 *
8892 * (async() => {
8893 * const browser = await chromium.launch();
8894 * const page = await browser.newPage();
8895 * await page.coverage.startJSCoverage();
8896 * await page.goto('https://chromium.org');
8897 * const coverage = await page.coverage.stopJSCoverage();
8898 * for (const entry of coverage) {
8899 * const converter = new v8toIstanbul('', 0, { source: entry.source });
8900 * await converter.load();
8901 * converter.applyCoverage(entry.functions);
8902 * console.log(JSON.stringify(converter.toIstanbul()));
8903 * }
8904 * await browser.close();
8905 * })();
8906 * ```
8907 *
8908 */
8909export interface ChromiumCoverage {
8910 /**
8911 * Returns coverage is started
8912 * @param options
8913 */
8914 startCSSCoverage(options?: {
8915 /**
8916 * Whether to reset coverage on every navigation. Defaults to `true`.
8917 */
8918 resetOnNavigation?: boolean;
8919 }): Promise<void>;
8920
8921 /**
8922 * Returns coverage is started
8923 *
8924 * > NOTE: Anonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on
8925 * the page using `eval` or `new Function`. If `reportAnonymousScripts` is set to `true`, anonymous scripts will have
8926 * `__playwright_evaluation_script__` as their URL.
8927 * @param options
8928 */
8929 startJSCoverage(options?: {
8930 /**
8931 * Whether anonymous scripts generated by the page should be reported. Defaults to `false`.
8932 */
8933 reportAnonymousScripts?: boolean;
8934
8935 /**
8936 * Whether to reset coverage on every navigation. Defaults to `true`.
8937 */
8938 resetOnNavigation?: boolean;
8939 }): Promise<void>;
8940
8941 /**
8942 * Returns the array of coverage reports for all stylesheets
8943 *
8944 * > NOTE: CSS Coverage doesn't include dynamically injected style tags without sourceURLs.
8945 */
8946 stopCSSCoverage(): Promise<Array<{
8947 /**
8948 * StyleSheet URL
8949 */
8950 url: string;
8951
8952 /**
8953 * StyleSheet content, if available.
8954 */
8955 text?: string;
8956
8957 /**
8958 * StyleSheet ranges that were used. Ranges are sorted and non-overlapping.
8959 */
8960 ranges: Array<{
8961 /**
8962 * A start offset in text, inclusive
8963 */
8964 start: number;
8965
8966 /**
8967 * An end offset in text, exclusive
8968 */
8969 end: number;
8970 }>;
8971 }>>;
8972
8973 /**
8974 * Returns the array of coverage reports for all scripts
8975 *
8976 * > NOTE: JavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are reported.
8977 */
8978 stopJSCoverage(): Promise<Array<{
8979 /**
8980 * Script URL
8981 */
8982 url: string;
8983
8984 /**
8985 * Script ID
8986 */
8987 scriptId: string;
8988
8989 /**
8990 * Script content, if applicable.
8991 */
8992 source?: string;
8993
8994 /**
8995 * V8-specific coverage format.
8996 */
8997 functions: Array<{
8998 functionName: string;
8999
9000 isBlockCoverage: boolean;
9001
9002 ranges: Array<{
9003 count: number;
9004
9005 startOffset: number;
9006
9007 endOffset: number;
9008 }>;
9009 }>;
9010 }>>;
9011}
9012
9013/**
9014 * [ConsoleMessage] objects are dispatched by page via the
9015 * [page.on('console')](https://playwright.dev/docs/api/class-page#pageonconsole) event.
9016 */
9017export interface ConsoleMessage {
9018 args(): Array<JSHandle>;
9019
9020 location(): {
9021 /**
9022 * URL of the resource.
9023 */
9024 url: string;
9025
9026 /**
9027 * 0-based line number in the resource.
9028 */
9029 lineNumber: number;
9030
9031 /**
9032 * 0-based column number in the resource.
9033 */
9034 columnNumber: number;
9035 };
9036
9037 text(): string;
9038
9039 /**
9040 * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
9041 * `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
9042 * `'count'`, `'timeEnd'`.
9043 */
9044 type(): string;
9045}
9046
9047/**
9048 * [Dialog] objects are dispatched by page via the
9049 * [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) event.
9050 *
9051 * An example of using `Dialog` class:
9052 *
9053 * ```js
9054 * const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
9055 *
9056 * (async () => {
9057 * const browser = await chromium.launch();
9058 * const page = await browser.newPage();
9059 * page.on('dialog', async dialog => {
9060 * console.log(dialog.message());
9061 * await dialog.dismiss();
9062 * });
9063 * await page.evaluate(() => alert('1'));
9064 * await browser.close();
9065 * })();
9066 * ```
9067 *
9068 * > NOTE: Dialogs are dismissed automatically, unless there is a
9069 * [page.on('dialog')](https://playwright.dev/docs/api/class-page#pageondialog) listener. When listener is present, it
9070 * **must** either [dialog.accept([promptText])](https://playwright.dev/docs/api/class-dialog#dialogacceptprompttext) or
9071 * [dialog.dismiss()](https://playwright.dev/docs/api/class-dialog#dialogdismiss) the dialog - otherwise the page will
9072 * [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
9073 * actions like click will never finish.
9074 */
9075export interface Dialog {
9076 /**
9077 * Returns when the dialog has been accepted.
9078 * @param promptText A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt. Optional.
9079 */
9080 accept(promptText?: string): Promise<void>;
9081
9082 /**
9083 * If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
9084 */
9085 defaultValue(): string;
9086
9087 /**
9088 * Returns when the dialog has been dismissed.
9089 */
9090 dismiss(): Promise<void>;
9091
9092 /**
9093 * A message displayed in the dialog.
9094 */
9095 message(): string;
9096
9097 /**
9098 * Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
9099 */
9100 type(): string;
9101}
9102
9103/**
9104 * [Download] objects are dispatched by page via the
9105 * [page.on('download')](https://playwright.dev/docs/api/class-page#pageondownload) event.
9106 *
9107 * All the downloaded files belonging to the browser context are deleted when the browser context is closed. All downloaded
9108 * files are deleted when the browser closes.
9109 *
9110 * Download event is emitted once the download starts. Download path becomes available once download completes:
9111 *
9112 * ```js
9113 * const [ download ] = await Promise.all([
9114 * page.waitForEvent('download'), // wait for download to start
9115 * page.click('a')
9116 * ]);
9117 * // wait for download to complete
9118 * const path = await download.path();
9119 * ```
9120 *
9121 * > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
9122 * downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
9123 * performed and user has no access to the downloaded files.
9124 */
9125export interface Download {
9126 /**
9127 * Returns readable stream for current download or `null` if download failed.
9128 */
9129 createReadStream(): Promise<null|Readable>;
9130
9131 /**
9132 * Deletes the downloaded file. Will wait for the download to finish if necessary.
9133 */
9134 delete(): Promise<void>;
9135
9136 /**
9137 * Returns download error if any. Will wait for the download to finish if necessary.
9138 */
9139 failure(): Promise<null|string>;
9140
9141 /**
9142 * Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if
9143 * necessary.
9144 */
9145 path(): Promise<null|string>;
9146
9147 /**
9148 * Saves the download to a user-specified path. It is safe to call this method while the download is still in progress.
9149 * @param path Path where the download should be saved.
9150 */
9151 saveAs(path: string): Promise<void>;
9152
9153 /**
9154 * Returns suggested filename for this download. It is typically computed by the browser from the
9155 * [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header
9156 * or the `download` attribute. See the spec on [whatwg](https://html.spec.whatwg.org/#downloading-resources). Different
9157 * browsers can use different logic for computing it.
9158 */
9159 suggestedFilename(): string;
9160
9161 /**
9162 * Returns downloaded url.
9163 */
9164 url(): string;
9165}
9166
9167/**
9168 * Playwright has **experimental** support for Electron automation. You can access electron namespace via:
9169 *
9170 * ```js
9171 * const { _electron } = require('playwright');
9172 * ```
9173 *
9174 * An example of the Electron automation script would be:
9175 *
9176 * ```js
9177 * const { _electron: electron } = require('playwright');
9178 *
9179 * (async () => {
9180 * // Launch Electron app.
9181 * const electronApp = await electron.launch({ args: ['main.js'] });
9182 *
9183 * // Evaluation expression in the Electron context.
9184 * const appPath = await electronApp.evaluate(async (electron) => {
9185 * // This runs in the main Electron process, |electron| parameter
9186 * // here is always the result of the require('electron') in the main
9187 * // app script.
9188 * return electron.getAppPath();
9189 * });
9190 *
9191 * // Get the first window that the app opens, wait if necessary.
9192 * const window = await electronApp.firstWindow();
9193 * // Print the title.
9194 * console.log(await window.title());
9195 * // Capture a screenshot.
9196 * await window.screenshot({ path: 'intro.png' });
9197 * // Direct Electron console to Node terminal.
9198 * window.on('console', console.log);
9199 * // Click button.
9200 * await window.click('text=Click me');
9201 * })();
9202 * ```
9203 *
9204 * Note that since you don't need Playwright to install web browsers when testing Electron, you can omit browser download
9205 * via setting the following environment variable when installing Playwright:
9206 *
9207 * ```sh js
9208 * $ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
9209 * ```
9210 *
9211 */
9212export interface Electron {
9213 /**
9214 * Launches electron application specified with the `executablePath`.
9215 * @param options
9216 */
9217 launch(options?: {
9218 /**
9219 * Additional arguments to pass to the application when launching. You typically pass the main script name here.
9220 */
9221 args?: Array<string>;
9222
9223 /**
9224 * Current working directory to launch application from.
9225 */
9226 cwd?: string;
9227
9228 /**
9229 * Specifies environment variables that will be visible to Electron. Defaults to `process.env`.
9230 */
9231 env?: { [key: string]: string; };
9232
9233 /**
9234 * Launches given Electron application. If not specified, launches the default Electron executable installed in this
9235 * package, located at `node_modules/.bin/electron`.
9236 */
9237 executablePath?: string;
9238 }): Promise<ElectronApplication>;
9239}
9240
9241/**
9242 * [FileChooser] objects are dispatched by the page in the
9243 * [page.on('filechooser')](https://playwright.dev/docs/api/class-page#pageonfilechooser) event.
9244 *
9245 * ```js
9246 * const [fileChooser] = await Promise.all([
9247 * page.waitForEvent('filechooser'),
9248 * page.click('upload')
9249 * ]);
9250 * await fileChooser.setFiles('myfile.pdf');
9251 * ```
9252 *
9253 */
9254export interface FileChooser {
9255 /**
9256 * Returns input element associated with this file chooser.
9257 */
9258 element(): ElementHandle;
9259
9260 /**
9261 * Returns whether this file chooser accepts multiple files.
9262 */
9263 isMultiple(): boolean;
9264
9265 /**
9266 * Returns page this file chooser belongs to.
9267 */
9268 page(): Page;
9269
9270 /**
9271 * Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, then
9272 * they are resolved relative to the the current working directory. For empty array, clears the selected files.
9273 * @param files
9274 * @param options
9275 */
9276 setFiles(files: string|Array<string>|{
9277 /**
9278 * File name
9279 */
9280 name: string;
9281
9282 /**
9283 * File type
9284 */
9285 mimeType: string;
9286
9287 /**
9288 * File content
9289 */
9290 buffer: Buffer;
9291 }|Array<{
9292 /**
9293 * File name
9294 */
9295 name: string;
9296
9297 /**
9298 * File type
9299 */
9300 mimeType: string;
9301
9302 /**
9303 * File content
9304 */
9305 buffer: Buffer;
9306 }>, options?: {
9307 /**
9308 * Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can
9309 * opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to
9310 * inaccessible pages. Defaults to `false`.
9311 */
9312 noWaitAfter?: boolean;
9313
9314 /**
9315 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
9316 * using the
9317 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
9318 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
9319 */
9320 timeout?: number;
9321 }): Promise<void>;
9322}
9323
9324/**
9325 * - extends: [Browser]
9326 *
9327 * Firefox browser instance does not expose Firefox-specific features.
9328 */
9329export interface FirefoxBrowser extends Browser {
9330
9331}
9332
9333/**
9334 * Keyboard provides an api for managing a virtual keyboard. The high level api is
9335 * [keyboard.type(text[, options])](https://playwright.dev/docs/api/class-keyboard#keyboardtypetext-options), which takes
9336 * raw characters and generates proper keydown, keypress/input, and keyup events on your page.
9337 *
9338 * For finer control, you can use [keyboard.down(key)](https://playwright.dev/docs/api/class-keyboard#keyboarddownkey),
9339 * [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboardupkey), and
9340 * [keyboard.insertText(text)](https://playwright.dev/docs/api/class-keyboard#keyboardinserttexttext) to manually fire
9341 * events as if they were generated from a real keyboard.
9342 *
9343 * An example of holding down `Shift` in order to select and delete some text:
9344 *
9345 * ```js
9346 * await page.keyboard.type('Hello World!');
9347 * await page.keyboard.press('ArrowLeft');
9348 *
9349 * await page.keyboard.down('Shift');
9350 * for (let i = 0; i < ' World'.length; i++)
9351 * await page.keyboard.press('ArrowLeft');
9352 * await page.keyboard.up('Shift');
9353 *
9354 * await page.keyboard.press('Backspace');
9355 * // Result text will end up saying 'Hello!'
9356 * ```
9357 *
9358 * An example of pressing uppercase `A`
9359 *
9360 * ```js
9361 * await page.keyboard.press('Shift+KeyA');
9362 * // or
9363 * await page.keyboard.press('Shift+A');
9364 * ```
9365 *
9366 * An example to trigger select-all with the keyboard
9367 *
9368 * ```js
9369 * // on Windows and Linux
9370 * await page.keyboard.press('Control+A');
9371 * // on macOS
9372 * await page.keyboard.press('Meta+A');
9373 * ```
9374 *
9375 */
9376export interface Keyboard {
9377 /**
9378 * Dispatches a `keydown` event.
9379 *
9380 * `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
9381 * value or a single character to generate the text for. A superset of the `key` values can be found
9382 * [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
9383 *
9384 * `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
9385 * `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
9386 *
9387 * Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
9388 *
9389 * Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
9390 *
9391 * If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
9392 * texts.
9393 *
9394 * If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier
9395 * active. To release the modifier key, use
9396 * [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboardupkey).
9397 *
9398 * After the key is pressed once, subsequent calls to
9399 * [keyboard.down(key)](https://playwright.dev/docs/api/class-keyboard#keyboarddownkey) will have
9400 * [repeat](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat) set to true. To release the key, use
9401 * [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboardupkey).
9402 *
9403 * > NOTE: Modifier keys DO influence `keyboard.down`. Holding down `Shift` will type the text in upper case.
9404 * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
9405 */
9406 down(key: string): Promise<void>;
9407
9408 /**
9409 * Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.
9410 *
9411 * ```js
9412 * page.keyboard.insertText('嗨');
9413 * ```
9414 *
9415 * > NOTE: Modifier keys DO NOT effect `keyboard.insertText`. Holding down `Shift` will not type the text in upper case.
9416 * @param text Sets input to the specified text value.
9417 */
9418 insertText(text: string): Promise<void>;
9419
9420 /**
9421 * `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
9422 * value or a single character to generate the text for. A superset of the `key` values can be found
9423 * [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
9424 *
9425 * `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
9426 * `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
9427 *
9428 * Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
9429 *
9430 * Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
9431 *
9432 * If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
9433 * texts.
9434 *
9435 * Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
9436 * modifier, modifier is pressed and being held while the subsequent key is being pressed.
9437 *
9438 * ```js
9439 * const page = await browser.newPage();
9440 * await page.goto('https://keycode.info');
9441 * await page.keyboard.press('A');
9442 * await page.screenshot({ path: 'A.png' });
9443 * await page.keyboard.press('ArrowLeft');
9444 * await page.screenshot({ path: 'ArrowLeft.png' });
9445 * await page.keyboard.press('Shift+O');
9446 * await page.screenshot({ path: 'O.png' });
9447 * await browser.close();
9448 * ```
9449 *
9450 * Shortcut for [keyboard.down(key)](https://playwright.dev/docs/api/class-keyboard#keyboarddownkey) and
9451 * [keyboard.up(key)](https://playwright.dev/docs/api/class-keyboard#keyboardupkey).
9452 * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
9453 * @param options
9454 */
9455 press(key: string, options?: {
9456 /**
9457 * Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
9458 */
9459 delay?: number;
9460 }): Promise<void>;
9461
9462 /**
9463 * Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
9464 *
9465 * To press a special key, like `Control` or `ArrowDown`, use
9466 * [keyboard.press(key[, options])](https://playwright.dev/docs/api/class-keyboard#keyboardpresskey-options).
9467 *
9468 * ```js
9469 * await page.keyboard.type('Hello'); // Types instantly
9470 * await page.keyboard.type('World', {delay: 100}); // Types slower, like a user
9471 * ```
9472 *
9473 * > NOTE: Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
9474 * @param text A text to type into a focused element.
9475 * @param options
9476 */
9477 type(text: string, options?: {
9478 /**
9479 * Time to wait between key presses in milliseconds. Defaults to 0.
9480 */
9481 delay?: number;
9482 }): Promise<void>;
9483
9484 /**
9485 * Dispatches a `keyup` event.
9486 * @param key Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
9487 */
9488 up(key: string): Promise<void>;
9489}
9490
9491/**
9492 * Playwright generates a lot of logs and they are accessible via the pluggable logger sink.
9493 *
9494 * ```js
9495 * const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
9496 *
9497 * (async () => {
9498 * const browser = await chromium.launch({
9499 * logger: {
9500 * isEnabled: (name, severity) => name === 'browser',
9501 * log: (name, severity, message, args) => console.log(`${name} ${message}`)
9502 * }
9503 * });
9504 * ...
9505 * })();
9506 * ```
9507 *
9508 */
9509export interface Logger {
9510 /**
9511 * Determines whether sink is interested in the logger with the given name and severity.
9512 * @param name logger name
9513 * @param severity
9514 */
9515 isEnabled(name: string, severity: "verbose"|"info"|"warning"|"error"): boolean;
9516
9517 /**
9518 * @param name logger name
9519 * @param severity
9520 * @param message log message format
9521 * @param args message arguments
9522 * @param hints optional formatting hints
9523 */
9524 log(name: string, severity: "verbose"|"info"|"warning"|"error", message: string|Error, args: Array<Object>, hints: {
9525 /**
9526 * Optional preferred logger color.
9527 */
9528 color?: string;
9529 }): void;
9530}
9531
9532/**
9533 * The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
9534 *
9535 * Every `page` object has its own Mouse, accessible with
9536 * [page.mouse](https://playwright.dev/docs/api/class-page#pagemouse).
9537 *
9538 * ```js
9539 * // Using ‘page.mouse’ to trace a 100x100 square.
9540 * await page.mouse.move(0, 0);
9541 * await page.mouse.down();
9542 * await page.mouse.move(0, 100);
9543 * await page.mouse.move(100, 100);
9544 * await page.mouse.move(100, 0);
9545 * await page.mouse.move(0, 0);
9546 * await page.mouse.up();
9547 * ```
9548 *
9549 */
9550export interface Mouse {
9551 /**
9552 * Shortcut for [mouse.move(x, y[, options])](https://playwright.dev/docs/api/class-mouse#mousemovex-y-options),
9553 * [mouse.down([options])](https://playwright.dev/docs/api/class-mouse#mousedownoptions),
9554 * [mouse.up([options])](https://playwright.dev/docs/api/class-mouse#mouseupoptions).
9555 * @param x
9556 * @param y
9557 * @param options
9558 */
9559 click(x: number, y: number, options?: {
9560 /**
9561 * Defaults to `left`.
9562 */
9563 button?: "left"|"right"|"middle";
9564
9565 /**
9566 * defaults to 1. See [UIEvent.detail].
9567 */
9568 clickCount?: number;
9569
9570 /**
9571 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
9572 */
9573 delay?: number;
9574 }): Promise<void>;
9575
9576 /**
9577 * Shortcut for [mouse.move(x, y[, options])](https://playwright.dev/docs/api/class-mouse#mousemovex-y-options),
9578 * [mouse.down([options])](https://playwright.dev/docs/api/class-mouse#mousedownoptions),
9579 * [mouse.up([options])](https://playwright.dev/docs/api/class-mouse#mouseupoptions),
9580 * [mouse.down([options])](https://playwright.dev/docs/api/class-mouse#mousedownoptions) and
9581 * [mouse.up([options])](https://playwright.dev/docs/api/class-mouse#mouseupoptions).
9582 * @param x
9583 * @param y
9584 * @param options
9585 */
9586 dblclick(x: number, y: number, options?: {
9587 /**
9588 * Defaults to `left`.
9589 */
9590 button?: "left"|"right"|"middle";
9591
9592 /**
9593 * Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
9594 */
9595 delay?: number;
9596 }): Promise<void>;
9597
9598 /**
9599 * Dispatches a `mousedown` event.
9600 * @param options
9601 */
9602 down(options?: {
9603 /**
9604 * Defaults to `left`.
9605 */
9606 button?: "left"|"right"|"middle";
9607
9608 /**
9609 * defaults to 1. See [UIEvent.detail].
9610 */
9611 clickCount?: number;
9612 }): Promise<void>;
9613
9614 /**
9615 * Dispatches a `mousemove` event.
9616 * @param x
9617 * @param y
9618 * @param options
9619 */
9620 move(x: number, y: number, options?: {
9621 /**
9622 * defaults to 1. Sends intermediate `mousemove` events.
9623 */
9624 steps?: number;
9625 }): Promise<void>;
9626
9627 /**
9628 * Dispatches a `mouseup` event.
9629 * @param options
9630 */
9631 up(options?: {
9632 /**
9633 * Defaults to `left`.
9634 */
9635 button?: "left"|"right"|"middle";
9636
9637 /**
9638 * defaults to 1. See [UIEvent.detail].
9639 */
9640 clickCount?: number;
9641 }): Promise<void>;
9642}
9643
9644/**
9645 * Whenever the page sends a request for a network resource the following sequence of events are emitted by [Page]:
9646 * - [page.on('request')](https://playwright.dev/docs/api/class-page#pageonrequest) emitted when the request is issued by
9647 * the page.
9648 * - [page.on('response')](https://playwright.dev/docs/api/class-page#pageonresponse) emitted when/if the response status
9649 * and headers are received for the request.
9650 * - [page.on('requestfinished')](https://playwright.dev/docs/api/class-page#pageonrequestfinished) emitted when the
9651 * response body is downloaded and the request is complete.
9652 *
9653 * If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
9654 * the [page.on('requestfailed')](https://playwright.dev/docs/api/class-page#pageonrequestfailed) event is emitted.
9655 *
9656 * > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
9657 * complete with `'requestfinished'` event.
9658 *
9659 * If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
9660 * request is issued to a redirected url.
9661 */
9662export interface Request {
9663 /**
9664 * The method returns `null` unless this request has failed, as reported by `requestfailed` event.
9665 *
9666 * Example of logging of all the failed requests:
9667 *
9668 * ```js
9669 * page.on('requestfailed', request => {
9670 * console.log(request.url() + ' ' + request.failure().errorText);
9671 * });
9672 * ```
9673 *
9674 */
9675 failure(): null|{
9676 /**
9677 * Human-readable error message, e.g. `'net::ERR_FAILED'`.
9678 */
9679 errorText: string;
9680 };
9681
9682 /**
9683 * Returns the [Frame] that initiated this request.
9684 */
9685 frame(): Frame;
9686
9687 /**
9688 * An object with HTTP headers associated with the request. All header names are lower-case.
9689 */
9690 headers(): { [key: string]: string; };
9691
9692 /**
9693 * Whether this request is driving frame's navigation.
9694 */
9695 isNavigationRequest(): boolean;
9696
9697 /**
9698 * Request's method (GET, POST, etc.)
9699 */
9700 method(): string;
9701
9702 /**
9703 * Request's post body, if any.
9704 */
9705 postData(): null|string;
9706
9707 /**
9708 * Request's post body in a binary form, if any.
9709 */
9710 postDataBuffer(): null|Buffer;
9711
9712 /**
9713 * Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
9714 *
9715 * When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
9716 * Otherwise it will be parsed as JSON.
9717 */
9718 postDataJSON(): null|any;
9719
9720 /**
9721 * Request that was redirected by the server to this one, if any.
9722 *
9723 * When the server responds with a redirect, Playwright creates a new [Request] object. The two requests are connected by
9724 * `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
9725 * construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
9726 *
9727 * For example, if the website `http://example.com` redirects to `https://example.com`:
9728 *
9729 * ```js
9730 * const response = await page.goto('http://example.com');
9731 * console.log(response.request().redirectedFrom().url()); // 'http://example.com'
9732 * ```
9733 *
9734 * If the website `https://google.com` has no redirects:
9735 *
9736 * ```js
9737 * const response = await page.goto('https://google.com');
9738 * console.log(response.request().redirectedFrom()); // null
9739 * ```
9740 *
9741 */
9742 redirectedFrom(): null|Request;
9743
9744 /**
9745 * New request issued by the browser if the server responded with redirect.
9746 *
9747 * This method is the opposite of
9748 * [request.redirectedFrom()](https://playwright.dev/docs/api/class-request#requestredirectedfrom):
9749 *
9750 * ```js
9751 * console.log(request.redirectedFrom().redirectedTo() === request); // true
9752 * ```
9753 *
9754 */
9755 redirectedTo(): null|Request;
9756
9757 /**
9758 * Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
9759 * following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
9760 * `websocket`, `manifest`, `other`.
9761 */
9762 resourceType(): string;
9763
9764 /**
9765 * Returns the matching [Response] object, or `null` if the response was not received due to error.
9766 */
9767 response(): Promise<null|Response>;
9768
9769 /**
9770 * Returns resource timing information for given request. Most of the timing values become available upon the response,
9771 * `responseEnd` becomes available when request finishes. Find more information at
9772 * [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
9773 *
9774 * ```js
9775 * const [request] = await Promise.all([
9776 * page.waitForEvent('requestfinished'),
9777 * page.goto('http://example.com')
9778 * ]);
9779 * console.log(request.timing());
9780 * ```
9781 *
9782 */
9783 timing(): {
9784 /**
9785 * Request start time in milliseconds elapsed since January 1, 1970 00:00:00 UTC
9786 */
9787 startTime: number;
9788
9789 /**
9790 * Time immediately before the browser starts the domain name lookup for the resource. The value is given in milliseconds
9791 * relative to `startTime`, -1 if not available.
9792 */
9793 domainLookupStart: number;
9794
9795 /**
9796 * Time immediately after the browser starts the domain name lookup for the resource. The value is given in milliseconds
9797 * relative to `startTime`, -1 if not available.
9798 */
9799 domainLookupEnd: number;
9800
9801 /**
9802 * Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. The
9803 * value is given in milliseconds relative to `startTime`, -1 if not available.
9804 */
9805 connectStart: number;
9806
9807 /**
9808 * Time immediately before the browser starts the handshake process to secure the current connection. The value is given in
9809 * milliseconds relative to `startTime`, -1 if not available.
9810 */
9811 secureConnectionStart: number;
9812
9813 /**
9814 * Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. The
9815 * value is given in milliseconds relative to `startTime`, -1 if not available.
9816 */
9817 connectEnd: number;
9818
9819 /**
9820 * Time immediately before the browser starts requesting the resource from the server, cache, or local resource. The value
9821 * is given in milliseconds relative to `startTime`, -1 if not available.
9822 */
9823 requestStart: number;
9824
9825 /**
9826 * Time immediately after the browser starts requesting the resource from the server, cache, or local resource. The value
9827 * is given in milliseconds relative to `startTime`, -1 if not available.
9828 */
9829 responseStart: number;
9830
9831 /**
9832 * Time immediately after the browser receives the last byte of the resource or immediately before the transport connection
9833 * is closed, whichever comes first. The value is given in milliseconds relative to `startTime`, -1 if not available.
9834 */
9835 responseEnd: number;
9836 };
9837
9838 /**
9839 * URL of the request.
9840 */
9841 url(): string;
9842}
9843
9844/**
9845 * [Response] class represents responses which are received by page.
9846 */
9847export interface Response {
9848 /**
9849 * Returns the buffer with response body.
9850 */
9851 body(): Promise<Buffer>;
9852
9853 /**
9854 * Waits for this response to finish, returns failure error if request failed.
9855 */
9856 finished(): Promise<null|Error>;
9857
9858 /**
9859 * Returns the [Frame] that initiated this response.
9860 */
9861 frame(): Frame;
9862
9863 /**
9864 * Returns the object with HTTP headers associated with the response. All header names are lower-case.
9865 */
9866 headers(): { [key: string]: string; };
9867
9868 /**
9869 * Returns the JSON representation of response body.
9870 *
9871 * This method will throw if the response body is not parsable via `JSON.parse`.
9872 */
9873 json(): Promise<Serializable>;
9874
9875 /**
9876 * Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
9877 */
9878 ok(): boolean;
9879
9880 /**
9881 * Returns the matching [Request] object.
9882 */
9883 request(): Request;
9884
9885 /**
9886 * Contains the status code of the response (e.g., 200 for a success).
9887 */
9888 status(): number;
9889
9890 /**
9891 * Contains the status text of the response (e.g. usually an "OK" for a success).
9892 */
9893 statusText(): string;
9894
9895 /**
9896 * Returns the text representation of response body.
9897 */
9898 text(): Promise<string>;
9899
9900 /**
9901 * Contains the URL of the response.
9902 */
9903 url(): string;
9904}
9905
9906/**
9907 * Whenever a network route is set up with
9908 * [page.route(url, handler)](https://playwright.dev/docs/api/class-page#pagerouteurl-handler) or
9909 * [browserContext.route(url, handler)](https://playwright.dev/docs/api/class-browsercontext#browsercontextrouteurl-handler),
9910 * the `Route` object allows to handle the route.
9911 */
9912export interface Route {
9913 /**
9914 * Aborts the route's request.
9915 * @param errorCode Optional error code. Defaults to `failed`, could be one of the following: - `'aborted'` - An operation was aborted (due to user action)
9916 * - `'accessdenied'` - Permission to access a resource, other than the network, was denied
9917 * - `'addressunreachable'` - The IP address is unreachable. This usually means that there is no route to the specified
9918 * host or network.
9919 * - `'blockedbyclient'` - The client chose to block the request.
9920 * - `'blockedbyresponse'` - The request failed because the response was delivered along with requirements which are not
9921 * met ('X-Frame-Options' and 'Content-Security-Policy' ancestor checks, for instance).
9922 * - `'connectionaborted'` - A connection timed out as a result of not receiving an ACK for data sent.
9923 * - `'connectionclosed'` - A connection was closed (corresponding to a TCP FIN).
9924 * - `'connectionfailed'` - A connection attempt failed.
9925 * - `'connectionrefused'` - A connection attempt was refused.
9926 * - `'connectionreset'` - A connection was reset (corresponding to a TCP RST).
9927 * - `'internetdisconnected'` - The Internet connection has been lost.
9928 * - `'namenotresolved'` - The host name could not be resolved.
9929 * - `'timedout'` - An operation timed out.
9930 * - `'failed'` - A generic failure occurred.
9931 */
9932 abort(errorCode?: string): Promise<void>;
9933
9934 /**
9935 * Continues route's request with optional overrides.
9936 *
9937 * ```js
9938 * await page.route('**\/*', (route, request) => {
9939 * // Override headers
9940 * const headers = {
9941 * ...request.headers(),
9942 * foo: 'bar', // set "foo" header
9943 * origin: undefined, // remove "origin" header
9944 * };
9945 * route.continue({headers});
9946 * });
9947 * ```
9948 *
9949 * @param options
9950 */
9951 continue(options?: {
9952 /**
9953 * If set changes the request HTTP headers. Header values will be converted to a string.
9954 */
9955 headers?: { [key: string]: string; };
9956
9957 /**
9958 * If set changes the request method (e.g. GET or POST)
9959 */
9960 method?: string;
9961
9962 /**
9963 * If set changes the post data of request
9964 */
9965 postData?: string|Buffer;
9966
9967 /**
9968 * If set changes the request URL. New URL must have same protocol as original one.
9969 */
9970 url?: string;
9971 }): Promise<void>;
9972
9973 /**
9974 * Fulfills route's request with given response.
9975 *
9976 * An example of fulfilling all requests with 404 responses:
9977 *
9978 * ```js
9979 * await page.route('**\/*', route => {
9980 * route.fulfill({
9981 * status: 404,
9982 * contentType: 'text/plain',
9983 * body: 'Not Found!'
9984 * });
9985 * });
9986 * ```
9987 *
9988 * An example of serving static file:
9989 *
9990 * ```js
9991 * await page.route('**\/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
9992 * ```
9993 *
9994 * @param options
9995 */
9996 fulfill(options?: {
9997 /**
9998 * Response body.
9999 */
10000 body?: string|Buffer;
10001
10002 /**
10003 * If set, equals to setting `Content-Type` response header.
10004 */
10005 contentType?: string;
10006
10007 /**
10008 * Response headers. Header values will be converted to a string.
10009 */
10010 headers?: { [key: string]: string; };
10011
10012 /**
10013 * File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it
10014 * is resolved relative to the current working directory.
10015 */
10016 path?: string;
10017
10018 /**
10019 * Response status code, defaults to `200`.
10020 */
10021 status?: number;
10022 }): Promise<void>;
10023
10024 /**
10025 * A request to be routed.
10026 */
10027 request(): Request;
10028}
10029
10030/**
10031 * Selectors can be used to install custom selector engines. See [Working with selectors](https://playwright.dev/docs/selectors) for more
10032 * information.
10033 */
10034export interface Selectors {
10035 /**
10036 * An example of registering selector engine that queries elements based on a tag name:
10037 *
10038 * ```js
10039 * const { selectors, firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
10040 *
10041 * (async () => {
10042 * // Must be a function that evaluates to a selector engine instance.
10043 * const createTagNameEngine = () => ({
10044 * // Returns the first element matching given selector in the root's subtree.
10045 * query(root, selector) {
10046 * return root.querySelector(selector);
10047 * },
10048 *
10049 * // Returns all elements matching given selector in the root's subtree.
10050 * queryAll(root, selector) {
10051 * return Array.from(root.querySelectorAll(selector));
10052 * }
10053 * });
10054 *
10055 * // Register the engine. Selectors will be prefixed with "tag=".
10056 * await selectors.register('tag', createTagNameEngine);
10057 *
10058 * const browser = await firefox.launch();
10059 * const page = await browser.newPage();
10060 * await page.setContent(`<div><button>Click me</button></div>`);
10061 *
10062 * // Use the selector prefixed with its name.
10063 * const button = await page.$('tag=button');
10064 * // Combine it with other selector engines.
10065 * await page.click('tag=div >> text="Click me"');
10066 * // Can use it in any methods supporting selectors.
10067 * const buttonCount = await page.$$eval('tag=button', buttons => buttons.length);
10068 *
10069 * await browser.close();
10070 * })();
10071 * ```
10072 *
10073 * @param name Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only contain `[a-zA-Z0-9_]` characters.
10074 * @param script Script that evaluates to a selector engine instance.
10075 * @param options
10076 */
10077 register(name: string, script: Function|string|{
10078 /**
10079 * Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working
10080 * directory. Optional.
10081 */
10082 path?: string;
10083
10084 /**
10085 * Raw script content. Optional.
10086 */
10087 content?: string;
10088 }, options?: {
10089 /**
10090 * Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but
10091 * not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content script is not
10092 * guaranteed when this engine is used together with other registered engines.
10093 */
10094 contentScript?: boolean;
10095 }): Promise<void>;
10096}
10097
10098/**
10099 * The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the
10100 * touchscreen can only be used in browser contexts that have been intialized with `hasTouch` set to true.
10101 */
10102export interface Touchscreen {
10103 /**
10104 * Dispatches a `touchstart` and `touchend` event with a single touch at the position (`x`,`y`).
10105 * @param x
10106 * @param y
10107 */
10108 tap(x: number, y: number): Promise<void>;
10109}
10110
10111/**
10112 * When browser context is created with the `videosPath` option, each page has a video object associated with it.
10113 *
10114 * ```js
10115 * console.log(await page.video().path());
10116 * ```
10117 *
10118 */
10119export interface Video {
10120 /**
10121 * Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem
10122 * upon closing the browser context.
10123 */
10124 path(): Promise<string>;
10125}
10126
10127/**
10128 * - extends: [Browser]
10129 *
10130 * WebKit browser instance does not expose WebKit-specific features.
10131 */
10132export interface WebKitBrowser extends Browser {
10133
10134}
10135
10136/**
10137 * The [WebSocket] class represents websocket connections in the page.
10138 */
10139export interface WebSocket {
10140 /**
10141 * Fired when the websocket closes.
10142 */
10143 on(event: 'close', listener: (webSocket: WebSocket) => void): this;
10144
10145 /**
10146 * Fired when the websocket recieves a frame.
10147 */
10148 on(event: 'framereceived', listener: (data: {
10149 /**
10150 * frame payload
10151 */
10152 payload: string|Buffer;
10153}) => void): this;
10154
10155 /**
10156 * Fired when the websocket sends a frame.
10157 */
10158 on(event: 'framesent', listener: (data: {
10159 /**
10160 * frame payload
10161 */
10162 payload: string|Buffer;
10163}) => void): this;
10164
10165 /**
10166 * Fired when the websocket has an error.
10167 */
10168 on(event: 'socketerror', listener: (string: String) => void): this;
10169
10170 /**
10171 * Fired when the websocket closes.
10172 */
10173 once(event: 'close', listener: (webSocket: WebSocket) => void): this;
10174
10175 /**
10176 * Fired when the websocket recieves a frame.
10177 */
10178 once(event: 'framereceived', listener: (data: {
10179 /**
10180 * frame payload
10181 */
10182 payload: string|Buffer;
10183}) => void): this;
10184
10185 /**
10186 * Fired when the websocket sends a frame.
10187 */
10188 once(event: 'framesent', listener: (data: {
10189 /**
10190 * frame payload
10191 */
10192 payload: string|Buffer;
10193}) => void): this;
10194
10195 /**
10196 * Fired when the websocket has an error.
10197 */
10198 once(event: 'socketerror', listener: (string: String) => void): this;
10199
10200 /**
10201 * Fired when the websocket closes.
10202 */
10203 addListener(event: 'close', listener: (webSocket: WebSocket) => void): this;
10204
10205 /**
10206 * Fired when the websocket recieves a frame.
10207 */
10208 addListener(event: 'framereceived', listener: (data: {
10209 /**
10210 * frame payload
10211 */
10212 payload: string|Buffer;
10213}) => void): this;
10214
10215 /**
10216 * Fired when the websocket sends a frame.
10217 */
10218 addListener(event: 'framesent', listener: (data: {
10219 /**
10220 * frame payload
10221 */
10222 payload: string|Buffer;
10223}) => void): this;
10224
10225 /**
10226 * Fired when the websocket has an error.
10227 */
10228 addListener(event: 'socketerror', listener: (string: String) => void): this;
10229
10230 /**
10231 * Fired when the websocket closes.
10232 */
10233 removeListener(event: 'close', listener: (webSocket: WebSocket) => void): this;
10234
10235 /**
10236 * Fired when the websocket recieves a frame.
10237 */
10238 removeListener(event: 'framereceived', listener: (data: {
10239 /**
10240 * frame payload
10241 */
10242 payload: string|Buffer;
10243}) => void): this;
10244
10245 /**
10246 * Fired when the websocket sends a frame.
10247 */
10248 removeListener(event: 'framesent', listener: (data: {
10249 /**
10250 * frame payload
10251 */
10252 payload: string|Buffer;
10253}) => void): this;
10254
10255 /**
10256 * Fired when the websocket has an error.
10257 */
10258 removeListener(event: 'socketerror', listener: (string: String) => void): this;
10259
10260 /**
10261 * Fired when the websocket closes.
10262 */
10263 off(event: 'close', listener: (webSocket: WebSocket) => void): this;
10264
10265 /**
10266 * Fired when the websocket recieves a frame.
10267 */
10268 off(event: 'framereceived', listener: (data: {
10269 /**
10270 * frame payload
10271 */
10272 payload: string|Buffer;
10273}) => void): this;
10274
10275 /**
10276 * Fired when the websocket sends a frame.
10277 */
10278 off(event: 'framesent', listener: (data: {
10279 /**
10280 * frame payload
10281 */
10282 payload: string|Buffer;
10283}) => void): this;
10284
10285 /**
10286 * Fired when the websocket has an error.
10287 */
10288 off(event: 'socketerror', listener: (string: String) => void): this;
10289
10290 /**
10291 * Indicates that the web socket has been closed.
10292 */
10293 isClosed(): boolean;
10294
10295 /**
10296 * Contains the URL of the WebSocket.
10297 */
10298 url(): string;
10299
10300 /**
10301 * Fired when the websocket closes.
10302 */
10303 waitForEvent(event: 'close', optionsOrPredicate?: { predicate?: (webSocket: WebSocket) => boolean, timeout?: number } | ((webSocket: WebSocket) => boolean)): Promise<WebSocket>;
10304
10305 /**
10306 * Fired when the websocket recieves a frame.
10307 */
10308 waitForEvent(event: 'framereceived', optionsOrPredicate?: { predicate?: (data: {
10309 /**
10310 * frame payload
10311 */
10312 payload: string|Buffer;
10313}) => boolean, timeout?: number } | ((data: {
10314 /**
10315 * frame payload
10316 */
10317 payload: string|Buffer;
10318}) => boolean)): Promise<{
10319 /**
10320 * frame payload
10321 */
10322 payload: string|Buffer;
10323}>;
10324
10325 /**
10326 * Fired when the websocket sends a frame.
10327 */
10328 waitForEvent(event: 'framesent', optionsOrPredicate?: { predicate?: (data: {
10329 /**
10330 * frame payload
10331 */
10332 payload: string|Buffer;
10333}) => boolean, timeout?: number } | ((data: {
10334 /**
10335 * frame payload
10336 */
10337 payload: string|Buffer;
10338}) => boolean)): Promise<{
10339 /**
10340 * frame payload
10341 */
10342 payload: string|Buffer;
10343}>;
10344
10345 /**
10346 * Fired when the websocket has an error.
10347 */
10348 waitForEvent(event: 'socketerror', optionsOrPredicate?: { predicate?: (string: String) => boolean, timeout?: number } | ((string: String) => boolean)): Promise<String>;
10349
10350}
10351
10352export interface BrowserContextOptions {
10353 /**
10354 * Whether to automatically download all the attachments. Defaults to `false` where all the downloads are canceled.
10355 */
10356 acceptDownloads?: boolean;
10357
10358 /**
10359 * Toggles bypassing page's Content-Security-Policy.
10360 */
10361 bypassCSP?: boolean;
10362
10363 /**
10364 * Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. See
10365 * [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#pageemulatemediaoptions) for more details.
10366 * Defaults to `'light'`.
10367 */
10368 colorScheme?: "light"|"dark"|"no-preference";
10369
10370 /**
10371 * Specify device scale factor (can be thought of as dpr). Defaults to `1`.
10372 */
10373 deviceScaleFactor?: number;
10374
10375 /**
10376 * An object containing additional HTTP headers to be sent with every request. All header values must be strings.
10377 */
10378 extraHTTPHeaders?: { [key: string]: string; };
10379
10380 geolocation?: Geolocation;
10381
10382 /**
10383 * Specifies if viewport supports touch events. Defaults to false.
10384 */
10385 hasTouch?: boolean;
10386
10387 /**
10388 * Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
10389 */
10390 httpCredentials?: HTTPCredentials;
10391
10392 /**
10393 * Whether to ignore HTTPS errors during navigation. Defaults to `false`.
10394 */
10395 ignoreHTTPSErrors?: boolean;
10396
10397 /**
10398 * Whether the `meta viewport` tag is taken into account and touch events are enabled. Defaults to `false`. Not supported
10399 * in Firefox.
10400 */
10401 isMobile?: boolean;
10402
10403 /**
10404 * Whether or not to enable JavaScript in the context. Defaults to `true`.
10405 */
10406 javaScriptEnabled?: boolean;
10407
10408 /**
10409 * Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language`
10410 * request header value as well as number and date formatting rules.
10411 */
10412 locale?: string;
10413
10414 /**
10415 * Logger sink for Playwright logging.
10416 */
10417 logger?: Logger;
10418
10419 /**
10420 * Whether to emulate network being offline. Defaults to `false`.
10421 */
10422 offline?: boolean;
10423
10424 /**
10425 * A list of permissions to grant to all pages in this context. See
10426 * [browserContext.grantPermissions(permissions[, options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextgrantpermissionspermissions-options)
10427 * for more details.
10428 */
10429 permissions?: Array<string>;
10430
10431 /**
10432 * Network proxy settings to use with this context. Note that browser needs to be launched with the global proxy for this
10433 * option to work. If all contexts override the proxy, global proxy will be never used and can be any string, for example
10434 * `launch({ proxy: { server: 'per-context' } })`.
10435 */
10436 proxy?: {
10437 /**
10438 * Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or
10439 * `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
10440 */
10441 server: string;
10442
10443 /**
10444 * Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
10445 */
10446 bypass?: string;
10447
10448 /**
10449 * Optional username to use if HTTP proxy requires authentication.
10450 */
10451 username?: string;
10452
10453 /**
10454 * Optional password to use if HTTP proxy requires authentication.
10455 */
10456 password?: string;
10457 };
10458
10459 /**
10460 * Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
10461 * specified, the HAR is not recorded. Make sure to await
10462 * [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for the HAR to be
10463 * saved.
10464 */
10465 recordHar?: {
10466 /**
10467 * Optional setting to control whether to omit request content from the HAR. Defaults to `false`.
10468 */
10469 omitContent?: boolean;
10470
10471 /**
10472 * Path on the filesystem to write the HAR file to.
10473 */
10474 path: string;
10475 };
10476
10477 /**
10478 * Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
10479 * sure to await [browserContext.close()](https://playwright.dev/docs/api/class-browsercontext#browsercontextclose) for
10480 * videos to be saved.
10481 */
10482 recordVideo?: {
10483 /**
10484 * Path to the directory to put videos into.
10485 */
10486 dir: string;
10487
10488 /**
10489 * Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to fit
10490 * into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of each page
10491 * will be scaled down if necessary to fit the specified size.
10492 */
10493 size?: {
10494 /**
10495 * Video frame width.
10496 */
10497 width: number;
10498
10499 /**
10500 * Video frame height.
10501 */
10502 height: number;
10503 };
10504 };
10505
10506 /**
10507 * Populates context with given storage state. This option can be used to initialize context with logged-in information
10508 * obtained via
10509 * [browserContext.storageState([options])](https://playwright.dev/docs/api/class-browsercontext#browsercontextstoragestateoptions).
10510 * Either a path to the file with saved storage, or an object with the following fields:
10511 */
10512 storageState?: string|{
10513 /**
10514 * Optional cookies to set for context
10515 */
10516 cookies?: Array<{
10517 name: string;
10518
10519 value: string;
10520
10521 /**
10522 * Optional either url or domain / path are required
10523 */
10524 url?: string;
10525
10526 /**
10527 * Optional either url or domain / path are required
10528 */
10529 domain?: string;
10530
10531 /**
10532 * Optional either url or domain / path are required
10533 */
10534 path?: string;
10535
10536 /**
10537 * Optional Unix time in seconds.
10538 */
10539 expires?: number;
10540
10541 /**
10542 * Optional httpOnly flag
10543 */
10544 httpOnly?: boolean;
10545
10546 /**
10547 * Optional secure flag
10548 */
10549 secure?: boolean;
10550
10551 /**
10552 * Optional sameSite flag
10553 */
10554 sameSite?: "Strict"|"Lax"|"None";
10555 }>;
10556
10557 /**
10558 * Optional localStorage to set for context
10559 */
10560 origins?: Array<{
10561 origin: string;
10562
10563 localStorage: Array<{
10564 name: string;
10565
10566 value: string;
10567 }>;
10568 }>;
10569 };
10570
10571 /**
10572 * Changes the timezone of the context. See
10573 * [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
10574 * for a list of supported timezone IDs.
10575 */
10576 timezoneId?: string;
10577
10578 /**
10579 * Specific user agent to use in this context.
10580 */
10581 userAgent?: string;
10582
10583 /**
10584 * **DEPRECATED** Use `recordVideo` instead.
10585 * @deprecated
10586 */
10587 videoSize?: {
10588 /**
10589 * Video frame width.
10590 */
10591 width: number;
10592
10593 /**
10594 * Video frame height.
10595 */
10596 height: number;
10597 };
10598
10599 /**
10600 * **DEPRECATED** Use `recordVideo` instead.
10601 * @deprecated
10602 */
10603 videosPath?: string;
10604
10605 /**
10606 * Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `null` disables the default viewport.
10607 */
10608 viewport?: null|ViewportSize;
10609}
10610
10611export interface ViewportSize {
10612 /**
10613 * page width in pixels.
10614 */
10615 width: number;
10616
10617 /**
10618 * page height in pixels.
10619 */
10620 height: number;
10621}
10622
10623export interface HTTPCredentials {
10624 username: string;
10625
10626 password: string;
10627}
10628
10629export interface Geolocation {
10630 /**
10631 * Latitude between -90 and 90.
10632 */
10633 latitude: number;
10634
10635 /**
10636 * Longitude between -180 and 180.
10637 */
10638 longitude: number;
10639
10640 /**
10641 * Non-negative accuracy value. Defaults to `0`.
10642 */
10643 accuracy?: number;
10644}
10645
10646export interface LaunchOptions {
10647 /**
10648 * Additional arguments to pass to the browser instance. The list of Chromium flags can be found
10649 * [here](http://peter.sh/experiments/chromium-command-line-switches/).
10650 */
10651 args?: Array<string>;
10652
10653 /**
10654 * Browser distribution channel.
10655 */
10656 channel?: "chrome"|"chrome-beta"|"chrome-dev"|"chrome-canary"|"msedge"|"msedge-beta"|"msedge-dev"|"msedge-canary";
10657
10658 /**
10659 * Enable Chromium sandboxing. Defaults to `false`.
10660 */
10661 chromiumSandbox?: boolean;
10662
10663 /**
10664 * **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the `headless`
10665 * option will be set `false`.
10666 */
10667 devtools?: boolean;
10668
10669 /**
10670 * If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is
10671 * deleted when browser is closed.
10672 */
10673 downloadsPath?: string;
10674
10675 /**
10676 * Specify environment variables that will be visible to the browser. Defaults to `process.env`.
10677 */
10678 env?: { [key: string]: string|number|boolean; };
10679
10680 /**
10681 * Path to a browser executable to run instead of the bundled one. If `executablePath` is a relative path, then it is
10682 * resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, Firefox
10683 * or WebKit, use at your own risk.
10684 */
10685 executablePath?: string;
10686
10687 /**
10688 * Firefox user preferences. Learn more about the Firefox user preferences at
10689 * [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
10690 */
10691 firefoxUserPrefs?: { [key: string]: string|number|boolean; };
10692
10693 /**
10694 * Close the browser process on SIGHUP. Defaults to `true`.
10695 */
10696 handleSIGHUP?: boolean;
10697
10698 /**
10699 * Close the browser process on Ctrl-C. Defaults to `true`.
10700 */
10701 handleSIGINT?: boolean;
10702
10703 /**
10704 * Close the browser process on SIGTERM. Defaults to `true`.
10705 */
10706 handleSIGTERM?: boolean;
10707
10708 /**
10709 * Whether to run browser in headless mode. More details for
10710 * [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and
10711 * [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode). Defaults to `true` unless the
10712 * `devtools` option is `true`.
10713 */
10714 headless?: boolean;
10715
10716 /**
10717 * If `true`, Playwright does not pass its own configurations args and only uses the ones from `args`. If an array is
10718 * given, then filters out the given default arguments. Dangerous option; use with care. Defaults to `false`.
10719 */
10720 ignoreDefaultArgs?: boolean|Array<string>;
10721
10722 /**
10723 * Logger sink for Playwright logging.
10724 */
10725 logger?: Logger;
10726
10727 /**
10728 * Network proxy settings.
10729 */
10730 proxy?: {
10731 /**
10732 * Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or
10733 * `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
10734 */
10735 server: string;
10736
10737 /**
10738 * Optional coma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
10739 */
10740 bypass?: string;
10741
10742 /**
10743 * Optional username to use if HTTP proxy requires authentication.
10744 */
10745 username?: string;
10746
10747 /**
10748 * Optional password to use if HTTP proxy requires authentication.
10749 */
10750 password?: string;
10751 };
10752
10753 /**
10754 * Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
10755 */
10756 slowMo?: number;
10757
10758 /**
10759 * Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to
10760 * disable timeout.
10761 */
10762 timeout?: number;
10763}
10764
10765export interface ConnectOptions {
10766 /**
10767 * A browser websocket endpoint to connect to.
10768 */
10769 wsEndpoint: string;
10770
10771 /**
10772 * Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on.
10773 * Defaults to 0.
10774 */
10775 slowMo?: number;
10776
10777 /**
10778 * Logger sink for Playwright logging. Optional.
10779 */
10780 logger?: Logger;
10781
10782 /**
10783 * Maximum time in milliseconds to wait for the connection to be established. Defaults to `30000` (30 seconds). Pass `0` to
10784 * disable timeout.
10785 */
10786 timeout?: number;
10787}
10788
10789interface ElementHandleWaitForSelectorOptions {
10790 /**
10791 * Defaults to `'visible'`. Can be either:
10792 * - `'attached'` - wait for element to be present in DOM.
10793 * - `'detached'` - wait for element to not be present in DOM.
10794 * - `'visible'` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element without
10795 * any content or with `display:none` has an empty bounding box and is not considered visible.
10796 * - `'hidden'` - wait for element to be either detached from DOM, or have an empty bounding box or `visibility:hidden`.
10797 * This is opposite to the `'visible'` option.
10798 */
10799 state?: "attached"|"detached"|"visible"|"hidden";
10800
10801 /**
10802 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
10803 * using the
10804 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
10805 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
10806 */
10807 timeout?: number;
10808}
10809
10810export interface Cookie {
10811 name: string;
10812
10813 value: string;
10814
10815 domain: string;
10816
10817 path: string;
10818
10819 /**
10820 * Unix time in seconds.
10821 */
10822 expires: number;
10823
10824 httpOnly: boolean;
10825
10826 secure: boolean;
10827
10828 sameSite: "Strict"|"Lax"|"None";
10829}
10830
10831interface PageWaitForSelectorOptions {
10832 /**
10833 * Defaults to `'visible'`. Can be either:
10834 * - `'attached'` - wait for element to be present in DOM.
10835 * - `'detached'` - wait for element to not be present in DOM.
10836 * - `'visible'` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element without
10837 * any content or with `display:none` has an empty bounding box and is not considered visible.
10838 * - `'hidden'` - wait for element to be either detached from DOM, or have an empty bounding box or `visibility:hidden`.
10839 * This is opposite to the `'visible'` option.
10840 */
10841 state?: "attached"|"detached"|"visible"|"hidden";
10842
10843 /**
10844 * Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
10845 * using the
10846 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
10847 * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
10848 */
10849 timeout?: number;
10850}
10851
10852interface PageWaitForFunctionOptions {
10853 /**
10854 * If `polling` is `'raf'`, then `pageFunction` is constantly executed in `requestAnimationFrame` callback. If `polling` is
10855 * a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`.
10856 */
10857 polling?: number|"raf";
10858
10859 /**
10860 * maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default
10861 * value can be changed by using the
10862 * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout).
10863 */
10864 timeout?: number;
10865}
10866
10867type Devices = {
10868 "Blackberry PlayBook": DeviceDescriptor;
10869 "Blackberry PlayBook landscape": DeviceDescriptor;
10870 "BlackBerry Z30": DeviceDescriptor;
10871 "BlackBerry Z30 landscape": DeviceDescriptor;
10872 "Galaxy Note 3": DeviceDescriptor;
10873 "Galaxy Note 3 landscape": DeviceDescriptor;
10874 "Galaxy Note II": DeviceDescriptor;
10875 "Galaxy Note II landscape": DeviceDescriptor;
10876 "Galaxy S III": DeviceDescriptor;
10877 "Galaxy S III landscape": DeviceDescriptor;
10878 "Galaxy S5": DeviceDescriptor;
10879 "Galaxy S5 landscape": DeviceDescriptor;
10880 "iPad (gen 6)": DeviceDescriptor;
10881 "iPad (gen 6) landscape": DeviceDescriptor;
10882 "iPad (gen 7)": DeviceDescriptor;
10883 "iPad (gen 7) landscape": DeviceDescriptor;
10884 "iPad Mini": DeviceDescriptor;
10885 "iPad Mini landscape": DeviceDescriptor;
10886 "iPad Pro 11": DeviceDescriptor;
10887 "iPad Pro 11 landscape": DeviceDescriptor;
10888 "iPhone 6": DeviceDescriptor;
10889 "iPhone 6 landscape": DeviceDescriptor;
10890 "iPhone 6 Plus": DeviceDescriptor;
10891 "iPhone 6 Plus landscape": DeviceDescriptor;
10892 "iPhone 7": DeviceDescriptor;
10893 "iPhone 7 landscape": DeviceDescriptor;
10894 "iPhone 7 Plus": DeviceDescriptor;
10895 "iPhone 7 Plus landscape": DeviceDescriptor;
10896 "iPhone 8": DeviceDescriptor;
10897 "iPhone 8 landscape": DeviceDescriptor;
10898 "iPhone 8 Plus": DeviceDescriptor;
10899 "iPhone 8 Plus landscape": DeviceDescriptor;
10900 "iPhone SE": DeviceDescriptor;
10901 "iPhone SE landscape": DeviceDescriptor;
10902 "iPhone X": DeviceDescriptor;
10903 "iPhone X landscape": DeviceDescriptor;
10904 "iPhone XR": DeviceDescriptor;
10905 "iPhone XR landscape": DeviceDescriptor;
10906 "iPhone 11": DeviceDescriptor;
10907 "iPhone 11 landscape": DeviceDescriptor;
10908 "iPhone 11 Pro": DeviceDescriptor;
10909 "iPhone 11 Pro landscape": DeviceDescriptor;
10910 "iPhone 11 Pro Max": DeviceDescriptor;
10911 "iPhone 11 Pro Max landscape": DeviceDescriptor;
10912 "JioPhone 2": DeviceDescriptor;
10913 "JioPhone 2 landscape": DeviceDescriptor;
10914 "Kindle Fire HDX": DeviceDescriptor;
10915 "Kindle Fire HDX landscape": DeviceDescriptor;
10916 "LG Optimus L70": DeviceDescriptor;
10917 "LG Optimus L70 landscape": DeviceDescriptor;
10918 "Microsoft Lumia 550": DeviceDescriptor;
10919 "Microsoft Lumia 550 landscape": DeviceDescriptor;
10920 "Microsoft Lumia 950": DeviceDescriptor;
10921 "Microsoft Lumia 950 landscape": DeviceDescriptor;
10922 "Nexus 10": DeviceDescriptor;
10923 "Nexus 10 landscape": DeviceDescriptor;
10924 "Nexus 4": DeviceDescriptor;
10925 "Nexus 4 landscape": DeviceDescriptor;
10926 "Nexus 5": DeviceDescriptor;
10927 "Nexus 5 landscape": DeviceDescriptor;
10928 "Nexus 5X": DeviceDescriptor;
10929 "Nexus 5X landscape": DeviceDescriptor;
10930 "Nexus 6": DeviceDescriptor;
10931 "Nexus 6 landscape": DeviceDescriptor;
10932 "Nexus 6P": DeviceDescriptor;
10933 "Nexus 6P landscape": DeviceDescriptor;
10934 "Nexus 7": DeviceDescriptor;
10935 "Nexus 7 landscape": DeviceDescriptor;
10936 "Nokia Lumia 520": DeviceDescriptor;
10937 "Nokia Lumia 520 landscape": DeviceDescriptor;
10938 "Nokia N9": DeviceDescriptor;
10939 "Nokia N9 landscape": DeviceDescriptor;
10940 "Pixel 2": DeviceDescriptor;
10941 "Pixel 2 landscape": DeviceDescriptor;
10942 "Pixel 2 XL": DeviceDescriptor;
10943 "Pixel 2 XL landscape": DeviceDescriptor;
10944 [key: string]: DeviceDescriptor;
10945}
10946
\No newline at end of file