Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/web/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
25 changes: 25 additions & 0 deletions packages/web/tests/unit/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading