diff --git a/docs/api.md b/docs/api.md index d102ff1ab6..e4650eb68c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -160,7 +160,7 @@ - [class: Keyboard](#class-keyboard) * [keyboard.down(key[, options])](#keyboarddownkey-options) * [keyboard.press(key[, options])](#keyboardpresskey-options) - * [keyboard.sendCharacter(char)](#keyboardsendcharacterchar) + * [keyboard.sendCharacters(text)](#keyboardsendcharacterstext) * [keyboard.type(text[, options])](#keyboardtypetext-options) * [keyboard.up(key)](#keyboardupkey) - [class: Mouse](#class-mouse) @@ -1240,7 +1240,7 @@ List of all available devices is available in the source code: [DeviceDescriptor #### page.emulateMedia(options) - `options` <[Object]> - `type` Optional. Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation. - - `colorScheme` Optional. Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. + - `colorScheme` <"dark"|"light"|"no-preference"> Optional. Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. - returns: <[Promise]> ```js @@ -2127,7 +2127,7 @@ function findFocusedNode(node) { Keyboard provides an api for managing a virtual keyboard. The high level api is [`keyboard.type`](#keyboardtypetext-options), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page. -For finer control, you can use [`keyboard.down`](#keyboarddownkey-options), [`keyboard.up`](#keyboardupkey), and [`keyboard.sendCharacter`](#keyboardsendcharacterchar) to manually fire events as if they were generated from a real keyboard. +For finer control, you can use [`keyboard.down`](#keyboarddownkey-options), [`keyboard.up`](#keyboardupkey), and [`keyboard.sendCharacters`](#keyboardsendcharacterstext) to manually fire events as if they were generated from a real keyboard. An example of holding down `Shift` in order to select and delete some text: ```js @@ -2181,17 +2181,17 @@ If `key` is a single character and no modifier keys besides `Shift` are being he Shortcut for [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#keyboardupkey). -#### keyboard.sendCharacter(char) -- `char` <[string]> Character to send into the page. +#### keyboard.sendCharacters(text) +- `text` <[string]> Characters to send into the page. - returns: <[Promise]> Dispatches a `keypress` and `input` event. This does not send a `keydown` or `keyup` event. ```js -page.keyboard.sendCharacter('嗨'); +page.keyboard.sendCharacters('嗨'); ``` -> **NOTE** Modifier keys DO NOT effect `keyboard.sendCharacter`. Holding down `Shift` will not type the text in upper case. +> **NOTE** Modifier keys DO NOT effect `keyboard.sendCharacters`. Holding down `Shift` will not type the text in upper case. #### keyboard.type(text[, options]) - `text` <[string]> A text to type into a focused element. @@ -2240,6 +2240,10 @@ await page.mouse.up(); - `button` <"left"|"right"|"middle"> Defaults to `left`. - `clickCount` <[number]> defaults to 1. See [UIEvent.detail]. - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. + - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> + - `relativePoint` <[Object]> Optional relative point + - `x` <[number]> x coordinate + - `y` <[number]> y coordinate - returns: <[Promise]> Shortcut for [`mouse.move`](#mousemovex-y-options), [`mouse.down`](#mousedownoptions) and [`mouse.up`](#mouseupoptions). @@ -2250,6 +2254,10 @@ Shortcut for [`mouse.move`](#mousemovex-y-options), [`mouse.down`](#mousedownopt - `options` <[Object]> - `button` <"left"|"right"|"middle"> Defaults to `left`. - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. + - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> + - `relativePoint` <[Object]> Optional relative point + - `x` <[number]> x coordinate + - `y` <[number]> y coordinate - returns: <[Promise]> Shortcut for [`mouse.move`](#mousemovex-y-options), [`mouse.down`](#mousedownoptions), [`mouse.up`](#mouseupoptions), [`mouse.down`](#mousedownoptions) and [`mouse.up`](#mouseupoptions). @@ -2277,6 +2285,10 @@ Dispatches a `mousemove` event. - `options` <[Object]> - `button` <"left"|"right"|"middle"> Defaults to `left`. - `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. + - `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> + - `relativePoint` <[Object]> Optional relative point + - `x` <[number]> x coordinate + - `y` <[number]> y coordinate - returns: <[Promise]> Shortcut for [`mouse.move`](#mousemovex-y-options), [`mouse.down`](#mousedownoptions), [`mouse.up`](#mouseupoptions), [`mouse.down`](#mousedownoptions), [`mouse.up`](#mouseupoptions), [`mouse.down`](#mousedownoptions) and [`mouse.up`](#mouseupoptions). @@ -3134,10 +3146,12 @@ page.on('request', request => { ``` #### interception.disable() +- returns: <[Promise]> Disables network request interception. #### interception.enable() +- returns: <[Promise]> Once request interception is enabled, every request will stall unless it's continued, responded or aborted. An example of a naïve request interceptor that aborts all image requests: diff --git a/src/chromium/JSHandle.ts b/src/chromium/JSHandle.ts index 84e22bd3be..0fbd868522 100644 --- a/src/chromium/JSHandle.ts +++ b/src/chromium/JSHandle.ts @@ -326,7 +326,7 @@ export class ElementHandle extends JSHandle { if (error) throw new Error(error); await this.focus(); - await this._page.keyboard.sendCharacter(value); + await this._page.keyboard.sendCharacters(value); } async uploadFile(...filePaths: string[]) { diff --git a/src/firefox/JSHandle.ts b/src/firefox/JSHandle.ts index eca0e58100..8b3c87069b 100644 --- a/src/firefox/JSHandle.ts +++ b/src/firefox/JSHandle.ts @@ -378,7 +378,7 @@ export class ElementHandle extends JSHandle { if (error) throw new Error(error); await this.focus(); - await this._frame._page.keyboard.sendCharacter(value); + await this._frame._page.keyboard.sendCharacters(value); } async _clickablePoint(): Promise<{ x: number; y: number; }> { diff --git a/src/input.ts b/src/input.ts index 3f23766bda..be671fe82f 100644 --- a/src/input.ts +++ b/src/input.ts @@ -123,7 +123,7 @@ export class Keyboard { await this._raw.keyup(this._pressedModifiers, description.code, description.keyCode, description.key, description.location); } - async sendCharacter(text: string) { + async sendCharacters(text: string) { await this._raw.sendText(text); } @@ -135,7 +135,7 @@ export class Keyboard { } else { if (delay) await new Promise(f => setTimeout(f, delay)); - await this.sendCharacter(char); + await this.sendCharacters(char); } } } diff --git a/src/types.ts b/src/types.ts index 5268432c81..c8cc550ab3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,12 +5,12 @@ type Boxed = { [Index in keyof Args]: Args[Index] | type PageFunction = string | ((...args: Args) => R | Promise); type PageFunctionOn = string | ((on: On, ...args: Args) => R | Promise); -export type Evaluate = (fn: PageFunction, ...args: Boxed) => Promise; -export type EvaluateHandle = (fn: PageFunction, ...args: Boxed) => Promise; -export type $Eval = (selector: string, fn: PageFunctionOn, ...args: Boxed) => Promise; -export type $$Eval = (selector: string, fn: PageFunctionOn, ...args: Boxed) => Promise; -export type EvaluateOn = (fn: PageFunctionOn, ...args: Boxed) => Promise; -export type EvaluateHandleOn = (fn: PageFunctionOn, ...args: Boxed) => Promise; +export type Evaluate = (pageFunction: PageFunction, ...args: Boxed) => Promise; +export type EvaluateHandle = (pageFunction: PageFunction, ...args: Boxed) => Promise; +export type $Eval = (selector: string, pageFunction: PageFunctionOn, ...args: Boxed) => Promise; +export type $$Eval = (selector: string, pageFunction: PageFunctionOn, ...args: Boxed) => Promise; +export type EvaluateOn = (pageFunction: PageFunctionOn, ...args: Boxed) => Promise; +export type EvaluateHandleOn = (pageFunction: PageFunctionOn, ...args: Boxed) => Promise; export interface EvaluationContext { evaluate: Evaluate; diff --git a/src/webkit/JSHandle.ts b/src/webkit/JSHandle.ts index 46e035d84c..3463881ad1 100644 --- a/src/webkit/JSHandle.ts +++ b/src/webkit/JSHandle.ts @@ -256,7 +256,7 @@ export class ElementHandle extends JSHandle { if (error) throw new Error(error); await this.focus(); - await this._page.keyboard.sendCharacter(value); + await this._page.keyboard.sendCharacters(value); } async focus() { diff --git a/test/keyboard.spec.js b/test/keyboard.spec.js index a6e85fdadc..ee4eab7df5 100644 --- a/test/keyboard.spec.js +++ b/test/keyboard.spec.js @@ -76,10 +76,10 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { it('should send a character with sendCharacter', async({page, server}) => { await page.goto(server.PREFIX + '/input/textarea.html'); await page.focus('textarea'); - await page.keyboard.sendCharacter('嗨'); + await page.keyboard.sendCharacters('嗨'); expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨'); await page.evaluate(() => window.addEventListener('keydown', e => e.preventDefault(), true)); - await page.keyboard.sendCharacter('a'); + await page.keyboard.sendCharacters('a'); expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨a'); }); it.skip(FFOX)('should report shiftKey', async({page, server}) => { diff --git a/utils/doclint/check_public_api/JSBuilder.js b/utils/doclint/check_public_api/JSBuilder.js index 6ecf54d9bf..5f812e6db0 100644 --- a/utils/doclint/check_public_api/JSBuilder.js +++ b/utils/doclint/check_public_api/JSBuilder.js @@ -116,7 +116,7 @@ function checkSources(sources) { const type = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration); const name = symbol.getName(); if (symbol.valueDeclaration.dotDotDotToken) { - const innerType = serializeType(type.typeArguments[0], circular); + const innerType = serializeType(type.typeArguments ? type.typeArguments[0] : type, circular); innerType.name = '...' + innerType.name; return Documentation.Member.createProperty('...' + name, innerType); }