mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: add touchstart, touchmove and touchend methods (#9622)
This commit is contained in:
committed by
GitHub
parent
6e226bcc22
commit
c8bb11adfc
@@ -869,7 +869,25 @@ export class ElementHandle<
|
||||
async tap(this: ElementHandle<Element>): Promise<void> {
|
||||
await this.#scrollIntoViewIfNeeded();
|
||||
const {x, y} = await this.clickablePoint();
|
||||
await this.#page.touchscreen.tap(x, y);
|
||||
await this.#page.touchscreen.touchStart(x, y);
|
||||
await this.#page.touchscreen.touchEnd();
|
||||
}
|
||||
|
||||
async touchStart(this: ElementHandle<Element>): Promise<void> {
|
||||
await this.#scrollIntoViewIfNeeded();
|
||||
const {x, y} = await this.clickablePoint();
|
||||
await this.#page.touchscreen.touchStart(x, y);
|
||||
}
|
||||
|
||||
async touchMove(this: ElementHandle<Element>): Promise<void> {
|
||||
await this.#scrollIntoViewIfNeeded();
|
||||
const {x, y} = await this.clickablePoint();
|
||||
await this.#page.touchscreen.touchMove(x, y);
|
||||
}
|
||||
|
||||
async touchEnd(this: ElementHandle<Element>): Promise<void> {
|
||||
await this.#scrollIntoViewIfNeeded();
|
||||
await this.#page.touchscreen.touchEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -670,12 +670,40 @@ export class Touchscreen {
|
||||
* @param y - Vertical position of the tap.
|
||||
*/
|
||||
async tap(x: number, y: number): Promise<void> {
|
||||
await this.touchStart(x, y);
|
||||
await this.touchEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a `touchstart` event.
|
||||
* @param x - Horizontal position of the tap.
|
||||
* @param y - Vertical position of the tap.
|
||||
*/
|
||||
async touchStart(x: number, y: number): Promise<void> {
|
||||
const touchPoints = [{x: Math.round(x), y: Math.round(y)}];
|
||||
await this.#client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchStart',
|
||||
touchPoints,
|
||||
modifiers: this.#keyboard._modifiers,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Dispatches a `touchMove` event.
|
||||
* @param x - Horizontal position of the move.
|
||||
* @param y - Vertical position of the move.
|
||||
*/
|
||||
async touchMove(x: number, y: number): Promise<void> {
|
||||
const movePoints = [{x: Math.round(x), y: Math.round(y)}];
|
||||
await this.#client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchMove',
|
||||
touchPoints: movePoints,
|
||||
modifiers: this.#keyboard._modifiers,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Dispatches a `touchend` event.
|
||||
*/
|
||||
async touchEnd(): Promise<void> {
|
||||
await this.#client.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchEnd',
|
||||
touchPoints: [],
|
||||
|
||||
Reference in New Issue
Block a user