diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 3a24c1d91c..676e2fd333 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -249,6 +249,35 @@ export interface Page { */ evaluateHandle(pageFunction: PageFunction, arg?: any): Promise>; + /** + * Adds a script which would be evaluated in one of the following scenarios: + * - Whenever the page is navigated. + * - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly + * attached frame. + * + * The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend + * the JavaScript environment, e.g. to seed `Math.random`. + * + * An example of overriding `Math.random` before the page loads: + * + * ```js + * // preload.js + * Math.random = () => 42; + * ``` + * + * ```js + * // In your playwright script, assuming the preload.js file is in same directory + * await page.addInitScript({ path: './preload.js' }); + * ``` + * + * > NOTE: The order of evaluation of multiple scripts installed via + * [browserContext.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-browsercontext#browser-context-add-init-script) + * and [page.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-page#page-add-init-script) is not defined. + * @param script Script to be evaluated in the page. + * @param arg Optional argument to pass to `script` (only supported when passing a function). + */ + addInitScript(script: PageFunction | { path?: string, content?: string }, arg?: Arg): Promise; + /** * > NOTE: The use of [ElementHandle] is discouraged, use [Locator] objects and web-first assertions instead. * @@ -1731,46 +1760,6 @@ export interface Page { */ accessibility: Accessibility; - /** - * Adds a script which would be evaluated in one of the following scenarios: - * - Whenever the page is navigated. - * - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly - * attached frame. - * - * The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend - * the JavaScript environment, e.g. to seed `Math.random`. - * - * An example of overriding `Math.random` before the page loads: - * - * ```js - * // preload.js - * Math.random = () => 42; - * ``` - * - * ```js - * // In your playwright script, assuming the preload.js file is in same directory - * await page.addInitScript({ path: './preload.js' }); - * ``` - * - * > NOTE: The order of evaluation of multiple scripts installed via - * [browserContext.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-browsercontext#browser-context-add-init-script) - * and [page.addInitScript(script[, arg])](https://playwright.dev/docs/api/class-page#page-add-init-script) is not defined. - * @param script Script to be evaluated in the page. - * @param arg Optional argument to pass to `script` (only supported when passing a function). - */ - addInitScript(script: Function|string|{ - /** - * Path to the JavaScript file. If `path` is a relative path, then it is resolved relative to the current working - * directory. Optional. - */ - path?: string; - - /** - * Raw script content. Optional. - */ - content?: string; - }, arg?: Serializable): Promise; - /** * Adds a `