"use strict"; /** * Copyright 2017 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an 'AS IS' BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Touchscreen = exports.Mouse = exports.MouseButton = exports.Keyboard = void 0; /** * Keyboard provides an api for managing a virtual keyboard. * The high level api is {@link Keyboard."type"}, * which takes raw characters and generates proper keydown, keypress/input, * and keyup events on your page. * * @remarks * For finer control, you can use {@link Keyboard.down}, * {@link Keyboard.up}, and {@link Keyboard.sendCharacter} * to manually fire events as if they were generated from a real keyboard. * * On macOS, keyboard shortcuts like `⌘ A` -\> Select All do not work. * See {@link https://github.com/puppeteer/puppeteer/issues/1313 | #1313}. * * @example * An example of holding down `Shift` in order to select and delete some text: * * ```ts * await page.keyboard.type('Hello World!'); * await page.keyboard.press('ArrowLeft'); * * await page.keyboard.down('Shift'); * for (let i = 0; i < ' World'.length; i++) * await page.keyboard.press('ArrowLeft'); * await page.keyboard.up('Shift'); * * await page.keyboard.press('Backspace'); * // Result text will end up saying 'Hello!' * ``` * * @example * An example of pressing `A` * * ```ts * await page.keyboard.down('Shift'); * await page.keyboard.press('KeyA'); * await page.keyboard.up('Shift'); * ``` * * @public */ class Keyboard { /** * @internal */ constructor() { } } exports.Keyboard = Keyboard; /** * Enum of valid mouse buttons. * * @public */ exports.MouseButton = Object.freeze({ Left: 'left', Right: 'right', Middle: 'middle', Back: 'back', Forward: 'forward', }); /** * The Mouse class operates in main-frame CSS pixels * relative to the top-left corner of the viewport. * @remarks * Every `page` object has its own Mouse, accessible with [`page.mouse`](#pagemouse). * * @example * * ```ts * // Using ‘page.mouse’ to trace a 100x100 square. * await page.mouse.move(0, 0); * await page.mouse.down(); * await page.mouse.move(0, 100); * await page.mouse.move(100, 100); * await page.mouse.move(100, 0); * await page.mouse.move(0, 0); * await page.mouse.up(); * ``` * * **Note**: The mouse events trigger synthetic `MouseEvent`s. * This means that it does not fully replicate the functionality of what a normal user * would be able to do with their mouse. * * For example, dragging and selecting text is not possible using `page.mouse`. * Instead, you can use the {@link https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/getSelection | `DocumentOrShadowRoot.getSelection()`} functionality implemented in the platform. * * @example * For example, if you want to select all content between nodes: * * ```ts * await page.evaluate( * (from, to) => { * const selection = from.getRootNode().getSelection(); * const range = document.createRange(); * range.setStartBefore(from); * range.setEndAfter(to); * selection.removeAllRanges(); * selection.addRange(range); * }, * fromJSHandle, * toJSHandle * ); * ``` * * If you then would want to copy-paste your selection, you can use the clipboard api: * * ```ts * // The clipboard api does not allow you to copy, unless the tab is focused. * await page.bringToFront(); * await page.evaluate(() => { * // Copy the selected content to the clipboard * document.execCommand('copy'); * // Obtain the content of the clipboard as a string * return navigator.clipboard.readText(); * }); * ``` * * **Note**: If you want access to the clipboard API, * you have to give it permission to do so: * * ```ts * await browser * .defaultBrowserContext() * .overridePermissions('', [ * 'clipboard-read', * 'clipboard-write', * ]); * ``` * * @public */ class Mouse { /** * @internal */ constructor() { } /** * Resets the mouse to the default state: No buttons pressed; position at * (0,0). */ async reset() { throw new Error('Not implemented'); } async move() { throw new Error('Not implemented'); } async down() { throw new Error('Not implemented'); } async up() { throw new Error('Not implemented'); } async click() { throw new Error('Not implemented'); } async wheel() { throw new Error('Not implemented'); } async drag() { throw new Error('Not implemented'); } async dragEnter() { throw new Error('Not implemented'); } async dragOver() { throw new Error('Not implemented'); } async drop() { throw new Error('Not implemented'); } async dragAndDrop() { throw new Error('Not implemented'); } } exports.Mouse = Mouse; /** * The Touchscreen class exposes touchscreen events. * @public */ class Touchscreen { /** * @internal */ constructor() { } async tap() { throw new Error('Not implemented'); } async touchStart() { throw new Error('Not implemented'); } async touchMove() { throw new Error('Not implemented'); } async touchEnd() { throw new Error('Not implemented'); } } exports.Touchscreen = Touchscreen; //# sourceMappingURL=Input.js.map