diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index 9179375f98..4da7b181e0 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -287,6 +287,15 @@ export function classifyActionError(rawCause: unknown, action: LocatorAction): E return new EngineError('NODE_STALE', text, { retryable: true, cause }); } if (DETACHED_PATTERN.test(text)) { + // A stale retry earlier in Playwright's log does not undo input sent on + // a later attempt. Replaying the action could submit the same form twice. + if (POST_DISPATCH_PATTERN.test(text)) { + return new EngineError( + 'ACTION_MAY_HAVE_COMMITTED', + `${action.kind} detached after its input was dispatched: ${text}`, + { retryable: false, cause }, + ); + } return new EngineError('NODE_STALE', text, { retryable: true, cause }); } if (/Timeout .*exceeded/i.test(text) || isPwTimeout(rawCause)) { diff --git a/packages/web/tests/unit/actions.test.ts b/packages/web/tests/unit/actions.test.ts index a77caa7728..4032ac5147 100644 --- a/packages/web/tests/unit/actions.test.ts +++ b/packages/web/tests/unit/actions.test.ts @@ -137,6 +137,31 @@ describe('classifyActionError', () => { expect(classifyActionError(error, { kind: 'press', key: 'Enter' })).toMatchObject({ code: 'ACTION_MAY_HAVE_COMMITTED' }); }); + it('does not retry a press after Playwright detached once but dispatched on a later attempt', () => { + // Playwright may first retry a detached input, then press Enter and time + // out waiting for the navigation the key began. + const dispatched = new Error( + 'locator.press: Timeout 2000ms exceeded.\nCall log:\n' + + ' - element was detached from the DOM, retrying\n' + + ' - elementHandle.press("Enter")\n', + ); + dispatched.name = 'TimeoutError'; + const result = classifyActionError(dispatched, { kind: 'press', key: 'Enter' }); + expect(result).toMatchObject({ code: 'ACTION_MAY_HAVE_COMMITTED', retryable: false, cause: dispatched }); + + // Without the later dispatch marker the detached locator is still safe + // to re-resolve and retry. + const beforeDispatch = new Error( + 'locator.press: Timeout 2000ms exceeded.\nCall log:\n' + + ' - element was detached from the DOM, retrying\n', + ); + beforeDispatch.name = 'TimeoutError'; + expect(classifyActionError(beforeDispatch, { kind: 'press', key: 'Enter' })).toMatchObject({ + code: 'NODE_STALE', + retryable: true, + }); + }); + it('keeps a bare timeout without a call log a plain actionability miss', () => { const error = new Error('Timeout 5000ms exceeded'); error.name = 'TimeoutError';