Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

Revert "feat: introduce touchscreen.touch() for dispatching raw touch… (#31823)

Yury Semikhatsky383e4b3c7385
diff --git a/docs/src/api/class-touchscreen.md b/docs/src/api/class-touchscreen.md
index ac5405f30d..f37a12102c 100644
--- a/docs/src/api/class-touchscreen.md
+++ b/docs/src/api/class-touchscreen.md
@@ -24,23 +24,3 @@ X coordinate relative to the main frame's viewport in CSS pixels.
- `y` <[float]>
Y coordinate relative to the main frame's viewport in CSS pixels.
-
-## async method: Touchscreen.touch
-* since: v1.46
-
-Synthesizes a touch event.
-
-### param: Touchscreen.touch.type
-* since: v1.46
-- `type` <[TouchType]<"touchstart"|"touchend"|"touchmove"|"touchcancel">>
-
-Type of the touch event.
-
-### param: Touchscreen.touch.touches
-* since: v1.46
-- `touchPoints` <[Array]<[Object]>>
- - `x` <[float]> x coordinate of the event in CSS pixels.
- - `y` <[float]> y coordinate of the event in CSS pixels.
- - `id` ?<[int]> Identifier used to track the touch point between events, must be unique within an event. Optional.
-
-List of touch points for this event. `id` is a unique identifier of a touch point that helps identify it between touch events for the duration of its movement around the surface.
\ No newline at end of file
diff --git a/packages/playwright-core/src/client/input.ts b/packages/playwright-core/src/client/input.ts
index 0cc841619f..e06b0e3e4a 100644
--- a/packages/playwright-core/src/client/input.ts
+++ b/packages/playwright-core/src/client/input.ts
@@ -89,8 +89,4 @@ export class Touchscreen implements api.Touchscreen {
async tap(x: number, y: number) {
await this._page._channel.touchscreenTap({ x, y });
}
-
- async touch(type: 'touchstart'|'touchmove'|'touchend'|'touchcancel', touchPoints: { x: number, y: number, id?: number }[]) {
- await this._page._channel.touchscreenTouch({ type, touchPoints });
- }
}
diff --git a/packages/playwright-core/src/protocol/debug.ts b/packages/playwright-core/src/protocol/debug.ts
index f8e1f6c4b2..4f44f5941e 100644
--- a/packages/playwright-core/src/protocol/debug.ts
+++ b/packages/playwright-core/src/protocol/debug.ts
@@ -31,7 +31,6 @@ export const slowMoActions = new Set([
'Page.mouseClick',
'Page.mouseWheel',
'Page.touchscreenTap',
- 'Page.touchscreenTouch',
'Frame.blur',
'Frame.check',
'Frame.click',
@@ -90,7 +89,6 @@ export const commandsWithTracingSnapshots = new Set([
'Page.mouseClick',
'Page.mouseWheel',
'Page.touchscreenTap',
- 'Page.touchscreenTouch',
'Frame.evalOnSelector',
'Frame.evalOnSelectorAll',
'Frame.addScriptTag',
diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts
index 8814727389..9fa68b7bb9 100644
--- a/packages/playwright-core/src/protocol/validator.ts
+++ b/packages/playwright-core/src/protocol/validator.ts
@@ -1278,15 +1278,6 @@ scheme.PageTouchscreenTapParams = tObject({
y: tNumber,
});
scheme.PageTouchscreenTapResult = tOptional(tObject({}));
-scheme.PageTouchscreenTouchParams = tObject({
- type: tEnum(['touchstart', 'touchend', 'touchmove', 'touchcancel']),
- touchPoints: tArray(tObject({
- x: tNumber,
- y: tNumber,
- id: tOptional(tNumber),
- })),
-});
-scheme.PageTouchscreenTouchResult = tOptional(tObject({}));
scheme.PageAccessibilitySnapshotParams = tObject({
interestingOnly: tOptional(tBoolean),
root: tOptional(tChannel(['ElementHandle'])),
diff --git a/packages/playwright-core/src/server/chromium/crInput.ts b/packages/playwright-core/src/server/chromium/crInput.ts
index 47e7cc53e9..bbfd973d10 100644
--- a/packages/playwright-core/src/server/chromium/crInput.ts
+++ b/packages/playwright-core/src/server/chromium/crInput.ts
@@ -179,19 +179,4 @@ export class RawTouchscreenImpl implements input.RawTouchscreen {
}),
]);
}
- async touch(eventType: 'touchstart'|'touchmove'|'touchend'|'touchcancel', touchPoints: { x: number, y: number, id?: number }[], modifiers: Set<types.KeyboardModifier>) {
- let type: 'touchStart' | 'touchMove' | 'touchEnd' | 'touchCancel';
- switch (eventType) {
- case 'touchstart': type = 'touchStart'; break;
- case 'touchmove': type = 'touchMove'; break;
- case 'touchend': type = 'touchEnd'; break;
- case 'touchcancel': type = 'touchCancel'; break;
- default: throw new Error('Invalid eventType: ' + eventType);
- }
- await this._client.send('Input.dispatchTouchEvent', {
- type,
- touchPoints,
- modifiers: toModifiersMask(modifiers)
- });
- }
}
diff --git a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
index 9acc7378b2..3101cd051d 100644
--- a/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/pageDispatcher.ts
@@ -265,10 +265,6 @@ export class PageDispatcher extends Dispatcher<Page, channels.PageChannel, Brows
await this._page.touchscreen.tap(params.x, params.y, metadata);
}
- async touchscreenTouch(params: channels.PageTouchscreenTouchParams, metadata: CallMetadata) {
- await this._page.touchscreen.touch(params.type, params.touchPoints, metadata);
- }
-
async accessibilitySnapshot(params: channels.PageAccessibilitySnapshotParams, metadata: CallMetadata): Promise<channels.PageAccessibilitySnapshotResult> {
const rootAXNode = await this._page.accessibility.snapshot({
interestingOnly: params.interestingOnly,
diff --git a/packages/playwright-core/src/server/firefox/ffInput.ts b/packages/playwright-core/src/server/firefox/ffInput.ts
index fcf53ee9fc..66f35399a5 100644
--- a/packages/playwright-core/src/server/firefox/ffInput.ts
+++ b/packages/playwright-core/src/server/firefox/ffInput.ts
@@ -166,8 +166,4 @@ export class RawTouchscreenImpl implements input.RawTouchscreen {
modifiers: toModifiersMask(modifiers),
});
}
-
- async touch(eventType: 'touchstart'|'touchmove'|'touchend'|'touchcancel', touchPoints: { x: number, y: number, id?: number }[], modifiers: Set<types.KeyboardModifier>) {
- throw new Error('Not implemented yet.');
- }
}
diff --git a/packages/playwright-core/src/server/input.ts b/packages/playwright-core/src/server/input.ts
index 501874322c..f09f91b86f 100644
--- a/packages/playwright-core/src/server/input.ts
+++ b/packages/playwright-core/src/server/input.ts
@@ -308,7 +308,6 @@ function buildLayoutClosure(layout: keyboardLayout.KeyboardLayout): Map<string,
export interface RawTouchscreen {
tap(x: number, y: number, modifiers: Set<types.KeyboardModifier>): Promise<void>;
- touch(type: 'touchstart'|'touchmove'|'touchend'|'touchcancel', touchPoints: { x: number, y: number, id?: number }[], modifiers: Set<types.KeyboardModifier>): Promise<void>;
}
export class Touchscreen {
@@ -327,19 +326,4 @@ export class Touchscreen {
throw new Error('hasTouch must be enabled on the browser context before using the touchscreen.');
await this._raw.tap(x, y, this._page.keyboard._modifiers());
}
- async touch(type: 'touchstart'|'touchmove'|'touchend'|'touchcancel', touchPoints: { x: number, y: number, id?: number }[], metadata?: CallMetadata) {
- if (metadata && touchPoints.length === 1)
- metadata.point = { x: touchPoints[0].x, y: touchPoints[0].y };
- if (!this._page._browserContext._options.hasTouch)
- throw new Error('hasTouch must be enabled on the browser context before using the touchscreen.');
- const ids = new Set<number>();
- for (const point of touchPoints) {
- if (point.id !== undefined) {
- if (ids.has(point.id))
- throw new Error(`Duplicate touch point id: ${point.id}`);
- ids.add(point.id);
- }
- }
- await this._raw.touch(type, touchPoints, this._page.keyboard._modifiers());
- }
}
diff --git a/packages/playwright-core/src/server/webkit/wkInput.ts b/packages/playwright-core/src/server/webkit/wkInput.ts
index 88afa774c8..0732f246d1 100644
--- a/packages/playwright-core/src/server/webkit/wkInput.ts
+++ b/packages/playwright-core/src/server/webkit/wkInput.ts
@@ -182,20 +182,4 @@ export class RawTouchscreenImpl implements input.RawTouchscreen {
modifiers: toModifiersMask(modifiers),
});
}
-
- async touch(eventType: 'touchstart'|'touchmove'|'touchend'|'touchcancel', touchPoints: { x: number, y: number, id?: number }[], modifiers: Set<types.KeyboardModifier>) {
- let type: 'touchStart' | 'touchMove' | 'touchEnd' | 'touchCancel';
- switch (eventType) {
- case 'touchstart': type = 'touchStart'; break;
- case 'touchmove': type = 'touchMove'; break;
- case 'touchend': type = 'touchEnd'; break;
- case 'touchcancel': type = 'touchCancel'; break;
- default: throw new Error('Invalid eventType: ' + eventType);
- }
- await this._pageProxySession.send('Input.dispatchTouchEvent', {
- type,
- touchPoints: touchPoints.map(p => ({ ...p, id: p.id || 0 })),
- modifiers: toModifiersMask(modifiers)
- });
- }
}
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index de0ecc6715..2d9b0e6a6d 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -19755,29 +19755,6 @@ export interface Touchscreen {
* @param y Y coordinate relative to the main frame's viewport in CSS pixels.
*/
tap(x: number, y: number): Promise<void>;
-
- /**
- * Synthesizes a touch event.
- * @param type Type of the touch event.
- * @param touchPoints List of touch points for this event. `id` is a unique identifier of a touch point that helps identify it between
- * touch events for the duration of its movement around the surface.
- */
- touch(type: "touchstart"|"touchend"|"touchmove"|"touchcancel", touchPoints: ReadonlyArray<{
- /**
- * x coordinate of the event in CSS pixels.
- */
- x: number;
-
- /**
- * y coordinate of the event in CSS pixels.
- */
- y: number;
-
- /**
- * Identifier used to track the touch point between events, must be unique within an event. Optional.
- */
- id?: number;
- }>): Promise<void>;
}
/**
diff --git a/packages/protocol/src/channels.ts b/packages/protocol/src/channels.ts
index 2efa1c8065..f36b711b5b 100644
--- a/packages/protocol/src/channels.ts
+++ b/packages/protocol/src/channels.ts
@@ -1967,7 +1967,6 @@ export interface PageChannel extends PageEventTarget, EventTargetChannel {
mouseClick(params: PageMouseClickParams, metadata?: CallMetadata): Promise<PageMouseClickResult>;
mouseWheel(params: PageMouseWheelParams, metadata?: CallMetadata): Promise<PageMouseWheelResult>;
touchscreenTap(params: PageTouchscreenTapParams, metadata?: CallMetadata): Promise<PageTouchscreenTapResult>;
- touchscreenTouch(params: PageTouchscreenTouchParams, metadata?: CallMetadata): Promise<PageTouchscreenTouchResult>;
accessibilitySnapshot(params: PageAccessibilitySnapshotParams, metadata?: CallMetadata): Promise<PageAccessibilitySnapshotResult>;
pdf(params: PagePdfParams, metadata?: CallMetadata): Promise<PagePdfResult>;
startJSCoverage(params: PageStartJSCoverageParams, metadata?: CallMetadata): Promise<PageStartJSCoverageResult>;
@@ -2335,18 +2334,6 @@ export type PageTouchscreenTapOptions = {
};
export type PageTouchscreenTapResult = void;
-export type PageTouchscreenTouchParams = {
- type: 'touchstart' | 'touchend' | 'touchmove' | 'touchcancel',
- touchPoints: {
- x: number,
- y: number,
- id?: number,
- }[],
-};
-export type PageTouchscreenTouchOptions = {
-
-};
-export type PageTouchscreenTouchResult = void;
export type PageAccessibilitySnapshotParams = {
interestingOnly?: boolean,
root?: ElementHandleChannel,
diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.yml
index b67c8f357e..a6b91ce3c0 100644
--- a/packages/protocol/src/protocol.yml
+++ b/packages/protocol/src/protocol.yml
@@ -1640,27 +1640,6 @@ Page:
slowMo: true
snapshot: true
- touchscreenTouch:
- parameters:
- type:
- type: enum
- literals:
- - touchstart
- - touchend
- - touchmove
- - touchcancel
- touchPoints:
- type: array
- items:
- type: object
- properties:
- x: number
- y: number
- id: number?
- flags:
- slowMo: true
- snapshot: true
-
accessibilitySnapshot:
parameters:
interestingOnly: boolean?
diff --git a/tests/library/touch.spec.ts b/tests/library/touch.spec.ts
deleted file mode 100644
index f842beb207..0000000000
--- a/tests/library/touch.spec.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * 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.
- */
-
-import { contextTest as it, expect } from '../config/browserTest';
-import type { Locator } from 'playwright-core';
-
-it.use({ hasTouch: true });
-
-it.fixme(({ browserName }) => browserName === 'firefox');
-
-it('slow swipe events @smoke', async ({ page }) => {
- it.fixme();
- await page.setContent(`<div id="a" style="background: lightblue; width: 200px; height: 200px">a</div>`);
- const eventsHandle = await trackEvents(await page.locator('#a'));
- const center = await centerPoint(page.locator('#a'));
- await page.touchscreen.touch('touchstart', [{ ...center, id: 1 }]);
- expect.soft(await eventsHandle.jsonValue()).toEqual([
- 'pointerover',
- 'pointerenter',
- 'pointerdown',
- 'touchstart',
- ]);
-
- await eventsHandle.evaluate(events => events.length = 0);
- await page.touchscreen.touch('touchmove', [{ x: center.x + 10, y: center.y + 10, id: 1 }]);
- await page.touchscreen.touch('touchmove', [{ x: center.x + 20, y: center.y + 20, id: 1 }]);
- expect.soft(await eventsHandle.jsonValue()).toEqual([
- 'pointermove',
- 'touchmove',
- 'pointermove',
- 'touchmove',
- ]);
-
- await eventsHandle.evaluate(events => events.length = 0);
- await page.touchscreen.touch('touchend', [{ x: center.x + 20, y: center.y + 20, id: 1 }]);
- expect.soft(await eventsHandle.jsonValue()).toEqual([
- 'pointerup',
- 'pointerout',
- 'pointerleave',
- 'touchend',
- ]);
-});
-
-
-async function trackEvents(target: Locator) {
- const eventsHandle = await target.evaluateHandle(target => {
- const events: string[] = [];
- for (const event of [
- 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'click',
- 'pointercancel', 'pointerdown', 'pointerenter', 'pointerleave', 'pointermove', 'pointerout', 'pointerover', 'pointerup',
- 'touchstart', 'touchend', 'touchmove', 'touchcancel',])
- target.addEventListener(event, () => events.push(event), { passive: false });
- return events;
- });
- return eventsHandle;
-}
-
-async function centerPoint(e: Locator) {
- const box = await e.boundingBox();
- if (!box)
- throw new Error('Element is not visible');
- return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
-}
\ No newline at end of file