From 09f980fbafa1cf7bb396b82914135a4ea96f91b0 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Fri, 13 Nov 2026 21:47:25 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(chromium):=20pass=20deep=20evalua?= =?UTF-8?q?tion=20arguments=20outside=20protocol=20JSON=20(=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit bac1f9f67e9cff2a8e7ecbac25d56ec3bb1d15c6. --- .../src/server/chromium/crExecutionContext.ts | 5 ++--- .../src/server/firefox/ffExecutionContext.ts | 5 ++--- .../src/server/webkit/wkExecutionContext.ts | 5 ++--- tests/page/page-evaluate.spec.ts | 16 +--------------- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/packages/playwright-core/src/server/chromium/crExecutionContext.ts b/packages/playwright-core/src/server/chromium/crExecutionContext.ts index eddd66bdffd7a..dbdd0e9e58a82 100644 --- a/packages/playwright-core/src/server/chromium/crExecutionContext.ts +++ b/packages/playwright-core/src/server/chromium/crExecutionContext.ts @@ -57,13 +57,12 @@ export class CRExecutionContext implements js.ExecutionContextDelegate { } async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise { - // Keep serialized values out of the protocol arguments to avoid Chromium's JSON depth limit. - const serializedValues = values.map(value => JSON.stringify(value) ?? 'undefined').join(','); const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.callFunctionOn', { - functionDeclaration: `(utilityScript, ...handles) => (${expression})(utilityScript, ...[${serializedValues}], ...handles)`, + functionDeclaration: expression, objectId: utilityScript._objectId, arguments: [ { objectId: utilityScript._objectId }, + ...values.map(value => ({ value })), ...handles.map(handle => ({ objectId: handle._objectId! })), ], returnByValue, diff --git a/packages/playwright-core/src/server/firefox/ffExecutionContext.ts b/packages/playwright-core/src/server/firefox/ffExecutionContext.ts index 470b9d865b3cc..b6bcc0a582b10 100644 --- a/packages/playwright-core/src/server/firefox/ffExecutionContext.ts +++ b/packages/playwright-core/src/server/firefox/ffExecutionContext.ts @@ -55,12 +55,11 @@ export class FFExecutionContext implements js.ExecutionContextDelegate { } async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise { - // Keep serialized values in the function source, the same as in Chromium and WebKit. - const serializedValues = values.map(value => JSON.stringify(value) ?? 'undefined').join(','); const payload = await this._session.send('Runtime.callFunction', { - functionDeclaration: `(utilityScript, ...handles) => (${expression})(utilityScript, ...[${serializedValues}], ...handles)`, + functionDeclaration: expression, args: [ { objectId: utilityScript._objectId, value: undefined }, + ...values.map(value => ({ value })), ...handles.map(handle => ({ objectId: handle._objectId!, value: undefined })), ], returnByValue, diff --git a/packages/playwright-core/src/server/webkit/wkExecutionContext.ts b/packages/playwright-core/src/server/webkit/wkExecutionContext.ts index f62ff92f4bd0d..e06f4e838ffbc 100644 --- a/packages/playwright-core/src/server/webkit/wkExecutionContext.ts +++ b/packages/playwright-core/src/server/webkit/wkExecutionContext.ts @@ -65,13 +65,12 @@ export class WKExecutionContext implements js.ExecutionContextDelegate { async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle, values: any[], handles: js.JSHandle[]): Promise { try { - // Keep serialized values out of the protocol arguments to avoid WebKit's JSON depth limit. - const serializedValues = values.map(value => JSON.stringify(value) ?? 'undefined').join(','); const response = await this._session.send('Runtime.callFunctionOn', { - functionDeclaration: `(utilityScript, ...handles) => (${expression})(utilityScript, ...[${serializedValues}], ...handles)`, + functionDeclaration: expression, objectId: utilityScript._objectId!, arguments: [ { objectId: utilityScript._objectId }, + ...values.map(value => ({ value })), ...handles.map(handle => ({ objectId: handle._objectId! })), ], returnByValue, diff --git a/tests/page/page-evaluate.spec.ts b/tests/page/page-evaluate.spec.ts index 1d4c7c982fb22..217c58ace58b0 100644 --- a/tests/page/page-evaluate.spec.ts +++ b/tests/page/page-evaluate.spec.ts @@ -269,25 +269,11 @@ it('EV-031 should include a non-error rejection value in the error message', { expect(nullError.message).toContain('null'); }); -it('EV-032 should return complex objects', { - annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/44060' } -}, async ({ page }) => { +it('EV-032 should return complex objects', async ({ page }) => { const object = { foo: 'bar!' }; const result = await page.evaluate(a => a, object); expect(result).not.toBe(object); expect(result).toEqual(object); - - let argument: unknown = 0; - // Chromium rejects protocol arguments at 60 levels, WebKit at 200. - for (let i = 0; i < 200; i++) - argument = { children: [argument] }; - expect(await page.evaluate(value => JSON.stringify(value).length, argument)).toBe(JSON.stringify(argument).length); - - // An argument that is too deep rejects and does not hang. - for (let i = 0; i < 800; i++) - argument = { children: [argument] }; - const error = await page.evaluate(value => JSON.stringify(value).length, argument).catch(e => e); - expect(error.message).toMatch(/Maximum call stack size exceeded|too much recursion/); }); it('EV-033 should return NaN', async ({ page }) => {