diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.ts index 0f5370fdb7..18545e677f 100644 --- a/packages/playwright-core/src/server/dom.ts +++ b/packages/playwright-core/src/server/dom.ts @@ -413,7 +413,7 @@ export class ElementHandle extends js.JSHandle { return this._finishPointerActionDetectLayoutShift(progress, actionName, point, options, action); } - private async _finishPointerAction(progress: Progress, actionName: string, point: types.Point, options: types.PointerActionOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions, action: (point: types.Point) => Promise) { + private async _finishPointerAction(progress: Progress, actionName: string, point: types.Point, options: types.PointerActionOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions, action: (point: types.Point) => Promise): Promise<'error:notconnected' | { hitTargetDescription: string } | 'done'> { if (!options.force) { if ((options as any).__testHookBeforeHitTarget) await (options as any).__testHookBeforeHitTarget(); @@ -451,7 +451,7 @@ export class ElementHandle extends js.JSHandle { return 'done'; } - private async _finishPointerActionDetectLayoutShift(progress: Progress, actionName: string, point: types.Point, options: types.PointerActionOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions, action: (point: types.Point) => Promise) { + private async _finishPointerActionDetectLayoutShift(progress: Progress, actionName: string, point: types.Point, options: types.PointerActionOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions, action: (point: types.Point) => Promise): Promise<'error:notconnected' | { hitTargetDescription: string } | 'done'> { await progress.beforeInputAction(this); let hitTargetInterceptionHandle: js.JSHandle | undefined; diff --git a/packages/playwright-core/src/server/injected/injectedScript.ts b/packages/playwright-core/src/server/injected/injectedScript.ts index 6638388ee6..88438c2830 100644 --- a/packages/playwright-core/src/server/injected/injectedScript.ts +++ b/packages/playwright-core/src/server/injected/injectedScript.ts @@ -728,6 +728,11 @@ export class InjectedScript { if (!event.isTrusted) return; + // Element was detached during the action, for example in some event handler. + // If events before that were correctly pointing to it, consider this a valid scenario. + if (!element.isConnected) + return; + // Determine the event point. Note that Firefox does not always have window.TouchEvent. const point = (!!window.TouchEvent && (event instanceof window.TouchEvent)) ? event.touches[0] : (event as MouseEvent | PointerEvent); if (!!point && (result === undefined || result === 'done')) { @@ -745,7 +750,11 @@ export class InjectedScript { const stop = () => { if (this._hitTargetInterceptor === listener) this._hitTargetInterceptor = undefined; - return result!; + // If we did not get any events, consider things working. Possible causes: + // - JavaScript is disabled (webkit-only). + // - Some