Skip to content

chore: don't let count() throw during navigation#36941

Merged
Skn0tt merged 5 commits intomicrosoft:mainfrom
Skn0tt:dont-throw-count
Aug 11, 2025
Merged

chore: don't let count() throw during navigation#36941
Skn0tt merged 5 commits intomicrosoft:mainfrom
Skn0tt:dont-throw-count

Conversation

@Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Aug 6, 2025

Closes #36851

@Skn0tt Skn0tt requested a review from dgozman August 6, 2025 07:57
@Skn0tt Skn0tt self-assigned this Aug 6, 2025
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.


async _queryCount(selector: string): Promise<number> {
return (await this._channel.queryCount({ selector })).value;
async _queryCount(selector: string, options?: any): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of any, let's make it {} everywhere to designate we do not expect anything meaningful there.


async count(): Promise<number> {
return await this._frame._queryCount(this._selector);
async count(options?: any): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment that options are here only for testing.

// Be careful, |this.frame| can be different from |resolved.frame|.
if (!resolved)
throw new Error(`Failed to find frame for selector "${selector}"`);
await options.__testHookAfterStable?.();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the current hook name unsuitable.

Suggested change
await options.__testHookAfterStable?.();
await options.__testHookBeforeQuery?.();

try {
return await this.selectors.queryCount(selector, options);
} catch {
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check isNonRetriableError() here. See how isVisibleInternal() does it. Let's add a test that count() throws on page closure.

.contentFrame().locator('#f0_mid_0')
.contentFrame().locator('text=L28').or(l('text=L29')))));
const error = await locator.count().catch(e => e);
const error = await locator.isHidden().catch(e => e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert, this one should still throw.

await page.setContent(`<div>A</div>`);
let triggered = false;
const __testHookAfterStable = () => {
if (triggered)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could this hook be called twice?

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Skn0tt Skn0tt requested a review from dgozman August 11, 2025 07:04
@github-actions
Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:206:5 › mobile viewport › view scale should reset after navigation @webkit-ubuntu-22.04-node18

45 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1079:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [firefox-library] › library/inspector/cli-codegen-aria.spec.ts:76:7 › should update aria snapshot highlight @firefox-ubuntu-22.04-node18
⚠️ [firefox-page] › page/page-add-script-tag.spec.ts:93:3 › should throw when added with content to the CSP page @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-device.spec.ts:45:5 › device › should scroll to click @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-pages.spec.ts:105:3 › should return bounding box with page scale @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:87:5 › mobile viewport › should support window.orientation emulation @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:97:5 › mobile viewport › should fire orientationchange event @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:116:5 › mobile viewport › default mobile viewports to 980 width @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:124:5 › mobile viewport › respect meta viewport tag @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:157:5 › mobile viewport › mouse should work with mobile viewports and cross process navigations @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:175:5 › mobile viewport › should scroll when emulating a mobile viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/emulation-focus.spec.ts:104:3 › should not affect screenshots @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:44:14 › page screenshot › should work with a mobile viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:55:14 › page screenshot › should work with a mobile viewport and clip @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:66:14 › page screenshot › should work with a mobile viewport and fullPage @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:205:14 › element screenshot › element screenshot should work with a mobile viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:218:14 › element screenshot › element screenshot should work with device scale factor @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/trace-viewer.spec.ts:793:1 › should handle src=blob @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/trace-viewer.spec.ts:827:1 › should preserve currentSrc @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/video.spec.ts:411:5 › screencast › should capture css transformation @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/video.spec.ts:441:5 › screencast › should work for popups @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/video.spec.ts:475:5 › screencast › should scale frames down to the requested size @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/elementhandle-bounding-box.spec.ts:30:3 › should handle nested frames @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/elementhandle-screenshot.spec.ts:199:5 › element screenshot › should wait for visible @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/elementhandle-screenshot.spec.ts:231:5 › element screenshot › should wait for element to stop moving @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/locator-misc-2.spec.ts:107:3 › should return bounding box @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-click.spec.ts:1053:3 › should click a button that is overlaid by a permission popup @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-event-popup.spec.ts:28:3 › should work with window features @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:30:5 › page screenshot › should work @smoke @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:169:5 › page screenshot › should clip elements to the viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:183:5 › page screenshot › should throw on clip outside the viewport @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:215:5 › page screenshot › should take fullPage screenshots @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:224:5 › page screenshot › should take fullPage screenshots and mask elements outside of it @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:260:5 › page screenshot › should render white background on jpeg file @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:358:5 › page screenshot › should work with iframe in shadow @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:425:5 › page screenshot › should work with Array deleted @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:451:7 › page screenshot › mask option › should work @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:468:7 › page screenshot › mask option › should work with elementhandle @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:488:7 › page screenshot › mask option › should mask inside iframe @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:518:7 › page screenshot › mask option › should remove mask after screenshot @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:556:7 › page screenshot › mask option › should work when mask color is not pink #F0F @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:565:7 › page screenshot › mask option › should hide elements based on attr @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:580:7 › page screenshot › mask option › should remove elements based on attr @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:868:5 › page screenshot animations › should wait for fonts to load @webkit-ubuntu-22.04-node18

46610 passed, 805 skipped
✔️✔️✔️

Merge workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Microsoft.Playwright.PlaywrightException : Execution context was destroyed, most likely because of a navigation

2 participants