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
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ export class WKExecutionContext implements js.ExecutionContextDelegate {

async evaluateWithArguments(expression: string, returnByValue: boolean, utilityScript: js.JSHandle<any>, values: any[], handles: js.JSHandle[]): Promise<any> {
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,
Expand Down
16 changes: 1 addition & 15 deletions tests/page/page-evaluate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
Loading