Skip to content

Commit 5032dbf

Browse files
Vinyzugithub-actions[bot]
authored andcommitted
[Patch-Comparison] Automatic Commit: Fix querySelector Strict ContextOption
1 parent 98ec5a6 commit 5032dbf

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

patchright.patch

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
23402340
}
23412341

23422342
private _existingMainContext(): dom.FrameExecutionContext | null {
2343-
@@ -752,107 +823,172 @@
2343+
@@ -752,107 +823,173 @@
23442344
}
23452345

23462346
utilityContext(): Promise<dom.FrameExecutionContext> {
@@ -2386,7 +2386,8 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
23862386
+ return this.querySelectorAll(progress, selector).then((handles) => {
23872387
+ if (handles.length === 0)
23882388
+ return null;
2389-
+ if (handles.length > 1 && options?.strict)
2389+
+ const strict = options?.strict ?? this._page.browserContext._options.strictSelectors;
2390+
+ if (handles.length > 1 && strict)
23902391
+ throw new Error(`Strict mode: expected one element matching selector "${selector}", found ${handles.length}`);
23912392
+ return handles[0];
23922393
+ });
@@ -2585,7 +2586,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
25852586
}
25862587

25872588
private async _evalOnSelector(selector: string, strict: boolean, expression: string, isFunction: boolean | undefined, arg: any, scope?: dom.ElementHandle): Promise<any> {
2588-
@@ -864,8 +1000,23 @@
2589+
@@ -864,8 +1001,23 @@
25892590
return result;
25902591
}
25912592

@@ -2611,7 +2612,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
26112612
}
26122613

26132614
private async _evalOnSelectorAll(selector: string, expression: string, isFunction: boolean | undefined, arg: any, scope?: dom.ElementHandle): Promise<any> {
2614-
@@ -884,17 +1035,26 @@
2615+
@@ -884,17 +1036,26 @@
26152616
}
26162617

26172618
async querySelectorAll(progress: Progress, selector: string): Promise<dom.ElementHandle<Element>[]> {
@@ -2646,7 +2647,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
26462647
}
26472648

26482649
async content(progress: Progress): Promise<string> {
2649-
@@ -920,31 +1080,23 @@
2650+
@@ -920,31 +1081,23 @@
26502651
}
26512652

26522653
async setContent(progress: Progress, html: string, options: types.NavigateOptions): Promise<void> {
@@ -2695,7 +2696,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
26952696
}
26962697

26972698
name(): string {
2698-
@@ -1158,60 +1310,69 @@
2699+
@@ -1158,60 +1311,69 @@
26992700
progress: Progress,
27002701
selector: string,
27012702
options: { strict?: boolean, noAutoWaiting?: boolean, force?: boolean, performActionPreChecks?: boolean },
@@ -2818,7 +2819,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
28182819
}
28192820

28202821
async rafrafTimeoutScreenshotElementWithProgress(progress: Progress, selector: string, timeout: number, options: ScreenshotOptions): Promise<Buffer> {
2821-
@@ -1373,20 +1534,21 @@
2822+
@@ -1373,20 +1535,21 @@
28222823
}
28232824

28242825
async isVisibleInternal(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {
@@ -2854,7 +2855,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
28542855
}
28552856

28562857
async isHidden(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {
2857-
@@ -1515,46 +1677,48 @@
2858+
@@ -1515,46 +1678,48 @@
28582859
}
28592860

28602861
private async _expectInternal(progress: Progress, selector: string | undefined, options: FrameExpectParams, lastIntermediateResult: { received?: ExpectReceived, isSet: boolean, errorMessage?: string }, noAbort: boolean) {
@@ -2940,7 +2941,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
29402941
}
29412942

29422943
async waitForFunctionExpression<R>(progress: Progress, expression: string, isFunction: boolean | undefined, arg: any, options: { pollingInterval?: number }, world: types.World = 'main'): Promise<js.SmartHandle<R>> {
2943-
@@ -1613,7 +1777,7 @@
2944+
@@ -1613,7 +1778,7 @@
29442945
return { result, abort: () => aborted = true };
29452946
}, { expression, isFunction, polling: options.pollingInterval, arg }));
29462947
try {
@@ -2949,7 +2950,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
29492950
} catch (error) {
29502951
// Note: it is important to await "abort()" to prevent any side effects
29512952
// after this method returns.
2952-
@@ -1673,42 +1837,162 @@
2953+
@@ -1673,42 +1838,162 @@
29532954
}
29542955

29552956
_onDetached() {
@@ -3145,7 +3146,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
31453146
}
31463147

31473148
private _setContext(world: types.World, context: dom.FrameExecutionContext | null) {
3148-
@@ -1765,7 +2049,7 @@
3149+
@@ -1765,7 +2050,7 @@
31493150
}
31503151

31513152
async extendInjectedScript(source: string, arg?: any) {
@@ -3154,7 +3155,7 @@ diff -ruN -x protocol.yml --minimal playwright/node_modules/playwright-core/src/
31543155
const injectedScriptHandle = await context.injectedScript();
31553156
await injectedScriptHandle.evaluate((injectedScript, { source, arg }) => {
31563157
injectedScript.extend(source, arg);
3157-
@@ -1804,6 +2088,325 @@
3158+
@@ -1804,6 +2089,325 @@
31583159
private _asLocator(selector: string) {
31593160
return asLocator(this._page.browserContext._browser.sdkLanguage(), selector);
31603161
}
@@ -7108,7 +7109,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
71087109
}
71097110

71107111
private _existingMainContext(): dom.FrameExecutionContext | null {
7111-
@@ -752,107 +823,172 @@
7112+
@@ -752,107 +823,173 @@
71127113
}
71137114

71147115
utilityContext(): Promise<dom.FrameExecutionContext> {
@@ -7154,7 +7155,8 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
71547155
+ return this.querySelectorAll(progress, selector).then((handles) => {
71557156
+ if (handles.length === 0)
71567157
+ return null;
7157-
+ if (handles.length > 1 && options?.strict)
7158+
+ const strict = options?.strict ?? this._page.browserContext._options.strictSelectors;
7159+
+ if (handles.length > 1 && strict)
71587160
+ throw new Error(`Strict mode: expected one element matching selector "${selector}", found ${handles.length}`);
71597161
+ return handles[0];
71607162
+ });
@@ -7353,7 +7355,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
73537355
}
73547356

73557357
private async _evalOnSelector(selector: string, strict: boolean, expression: string, isFunction: boolean | undefined, arg: any, scope?: dom.ElementHandle): Promise<any> {
7356-
@@ -864,8 +1000,23 @@
7358+
@@ -864,8 +1001,23 @@
73577359
return result;
73587360
}
73597361

@@ -7379,7 +7381,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
73797381
}
73807382

73817383
private async _evalOnSelectorAll(selector: string, expression: string, isFunction: boolean | undefined, arg: any, scope?: dom.ElementHandle): Promise<any> {
7382-
@@ -884,17 +1035,26 @@
7384+
@@ -884,17 +1036,26 @@
73837385
}
73847386

73857387
async querySelectorAll(progress: Progress, selector: string): Promise<dom.ElementHandle<Element>[]> {
@@ -7414,7 +7416,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
74147416
}
74157417

74167418
async content(progress: Progress): Promise<string> {
7417-
@@ -920,31 +1080,23 @@
7419+
@@ -920,31 +1081,23 @@
74187420
}
74197421

74207422
async setContent(progress: Progress, html: string, options: types.NavigateOptions): Promise<void> {
@@ -7463,7 +7465,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
74637465
}
74647466

74657467
name(): string {
7466-
@@ -1158,60 +1310,69 @@
7468+
@@ -1158,60 +1311,69 @@
74677469
progress: Progress,
74687470
selector: string,
74697471
options: { strict?: boolean, noAutoWaiting?: boolean, force?: boolean, performActionPreChecks?: boolean },
@@ -7586,7 +7588,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
75867588
}
75877589

75887590
async rafrafTimeoutScreenshotElementWithProgress(progress: Progress, selector: string, timeout: number, options: ScreenshotOptions): Promise<Buffer> {
7589-
@@ -1373,20 +1534,21 @@
7591+
@@ -1373,20 +1535,21 @@
75907592
}
75917593

75927594
async isVisibleInternal(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {
@@ -7622,7 +7624,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
76227624
}
76237625

76247626
async isHidden(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {
7625-
@@ -1515,46 +1677,48 @@
7627+
@@ -1515,46 +1678,48 @@
76267628
}
76277629

76287630
private async _expectInternal(progress: Progress, selector: string | undefined, options: FrameExpectParams, lastIntermediateResult: { received?: ExpectReceived, isSet: boolean, errorMessage?: string }, noAbort: boolean) {
@@ -7708,7 +7710,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
77087710
}
77097711

77107712
async waitForFunctionExpression<R>(progress: Progress, expression: string, isFunction: boolean | undefined, arg: any, options: { pollingInterval?: number }, world: types.World = 'main'): Promise<js.SmartHandle<R>> {
7711-
@@ -1613,7 +1777,7 @@
7713+
@@ -1613,7 +1778,7 @@
77127714
return { result, abort: () => aborted = true };
77137715
}, { expression, isFunction, polling: options.pollingInterval, arg }));
77147716
try {
@@ -7717,7 +7719,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
77177719
} catch (error) {
77187720
// Note: it is important to await "abort()" to prevent any side effects
77197721
// after this method returns.
7720-
@@ -1673,42 +1837,162 @@
7722+
@@ -1673,42 +1838,162 @@
77217723
}
77227724

77237725
_onDetached() {
@@ -7913,7 +7915,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
79137915
}
79147916

79157917
private _setContext(world: types.World, context: dom.FrameExecutionContext | null) {
7916-
@@ -1765,7 +2049,7 @@
7918+
@@ -1765,7 +2050,7 @@
79177919
}
79187920

79197921
async extendInjectedScript(source: string, arg?: any) {
@@ -7922,7 +7924,7 @@ diff -ruN -x protocol.yml --minimal playwright/packages/playwright-core/src/serv
79227924
const injectedScriptHandle = await context.injectedScript();
79237925
await injectedScriptHandle.evaluate((injectedScript, { source, arg }) => {
79247926
injectedScript.extend(source, arg);
7925-
@@ -1804,6 +2088,325 @@
7927+
@@ -1804,6 +2089,325 @@
79267928
private _asLocator(selector: string) {
79277929
return asLocator(this._page.browserContext._browser.sdkLanguage(), selector);
79287930
}

0 commit comments

Comments
 (0)