Skip to content
Merged
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
13 changes: 10 additions & 3 deletions packages/playwright-core/src/server/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import * as types from './types';

type SetInputFilesFiles = channels.ElementHandleSetInputFilesParams['files'];

export class NonRecoverableDOMError extends Error {
}

export function isNonRecoverableDOMError(error: Error) {
return error instanceof NonRecoverableDOMError;
}

export class FrameExecutionContext extends js.ExecutionContext {
readonly frame: frames.Frame;
private _injectedScriptPromise?: Promise<js.JSHandle>;
Expand Down Expand Up @@ -356,13 +363,13 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
++retry;
if (result === 'error:notvisible') {
if (options.force)
throw new Error('Element is not visible');
throw new NonRecoverableDOMError('Element is not visible');
progress.log(' element is not visible');
continue;
}
if (result === 'error:notinviewport') {
if (options.force)
throw new Error('Element is outside of the viewport');
throw new NonRecoverableDOMError('Element is outside of the viewport');
progress.log(' element is outside of the viewport');
continue;
}
Expand Down Expand Up @@ -740,7 +747,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
if (options.trial)
return 'done';
if (await isChecked() !== state)
throw new Error('Clicking the checkbox did not change its state');
throw new NonRecoverableDOMError('Clicking the checkbox did not change its state');
return 'done';
}

Expand Down
16 changes: 12 additions & 4 deletions packages/playwright-core/src/server/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,10 +998,18 @@ export class Frame extends SdkObject {
// Always fail on JavaScript errors or when the main connection is closed.
if (js.isJavaScriptErrorInEvaluate(e) || isSessionClosedError(e))
throw e;
// If error has happened in the detached inner frame, ignore it, keep polling.
if (selectorInFrame?.frame !== this && selectorInFrame?.frame.isDetached())
continue;
throw e;
// Certain error opt-out of the retries, throw.
if (dom.isNonRecoverableDOMError(e))
throw e;
// If the call is made on the detached frame - throw.
if (this.isDetached())
throw e;
// If there is scope, and scope is within the frame we use to select, assume context is destroyed and
// operation is not recoverable.
if (scope && scope._context.frame === selectorInFrame?.frame)
throw e;
// Retry upon all other errors.
continue;
}
}
progress.throwIfAborted();
Expand Down
30 changes: 30 additions & 0 deletions tests/page/page-click-during-navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2018 Google Inc. All rights reserved.
* Modifications 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 { test as it } from './pageTest';

it('should not fail with internal error upon navigation', async ({ page, server }) => {
it.slow();
(async () => {
while (true) {
await page.goto(server.PREFIX + '/input/button.html').catch(() => {});
await page.waitForTimeout(100).catch(() => {});
}
})();
for (let i = 0; i < 100; ++i)
await page.click('button');
});