From 2951f4b06552cdcacc75c87b136311c54932eba7 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Tue, 1 Jun 2021 08:36:16 -0700 Subject: [PATCH] chore(evaluate): remove private _evaluateInUtility methods (#6815) --- src/client/frame.ts | 20 -------------------- src/dispatchers/frameDispatcher.ts | 4 ++-- src/protocol/channels.ts | 4 ---- src/protocol/protocol.yml | 10 ---------- src/protocol/validator.ts | 2 -- tests/page/frame-evaluate.spec.ts | 20 -------------------- 6 files changed, 2 insertions(+), 58 deletions(-) diff --git a/src/client/frame.ts b/src/client/frame.ts index 7face16fac..bb6f1697d4 100644 --- a/src/client/frame.ts +++ b/src/client/frame.ts @@ -181,16 +181,6 @@ export class Frame extends ChannelOwner(pageFunction: structs.PageFunction, arg: Arg): Promise>; - async _evaluateHandleInUtility(pageFunction: structs.PageFunction, arg?: any): Promise>; - async _evaluateHandleInUtility(pageFunction: structs.PageFunction, arg?: Arg): Promise> { - assertMaxArguments(arguments.length, 2); - return this._wrapApiCall(this._apiName('_evaluateHandleInUtility'), async (channel: channels.FrameChannel) => { - const result = await channel.evaluateExpressionHandle({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: 'utility' }); - return JSHandle.from(result.handle) as any as structs.SmartHandle; - }); - } - async evaluate(pageFunction: structs.PageFunction, arg?: Arg): Promise { assertMaxArguments(arguments.length, 2); return this._wrapApiCall(this._apiName('evaluate'), async (channel: channels.FrameChannel) => { @@ -199,16 +189,6 @@ export class Frame extends ChannelOwner(pageFunction: structs.PageFunction, arg: Arg): Promise; - async _evaluateInUtility(pageFunction: structs.PageFunction, arg?: any): Promise; - async _evaluateInUtility(pageFunction: structs.PageFunction, arg?: Arg): Promise { - assertMaxArguments(arguments.length, 2); - return this._wrapApiCall(this._apiName('evaluate'), async (channel: channels.FrameChannel) => { - const result = await channel.evaluateExpression({ expression: String(pageFunction), isFunction: typeof pageFunction === 'function', arg: serializeArgument(arg), world: 'utility' }); - return parseResult(result.value); - }); - } - async $(selector: string): Promise | null> { return this._wrapApiCall(this._apiName('$'), async (channel: channels.FrameChannel) => { const result = await channel.querySelector({ selector }); diff --git a/src/dispatchers/frameDispatcher.ts b/src/dispatchers/frameDispatcher.ts index b68ad1edfa..b9220b9a08 100644 --- a/src/dispatchers/frameDispatcher.ts +++ b/src/dispatchers/frameDispatcher.ts @@ -61,11 +61,11 @@ export class FrameDispatcher extends Dispatcher { - return { value: serializeResult(await this._frame.evaluateExpressionAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), params.world)) }; + return { value: serializeResult(await this._frame.evaluateExpressionAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), 'main')) }; } async evaluateExpressionHandle(params: channels.FrameEvaluateExpressionHandleParams, metadata: CallMetadata): Promise { - return { handle: ElementHandleDispatcher.fromJSHandle(this._scope, await this._frame.evaluateExpressionHandleAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), params.world)) }; + return { handle: ElementHandleDispatcher.fromJSHandle(this._scope, await this._frame.evaluateExpressionHandleAndWaitForSignals(params.expression, params.isFunction, parseArgument(params.arg), 'main')) }; } async waitForSelector(params: channels.FrameWaitForSelectorParams, metadata: CallMetadata): Promise { diff --git a/src/protocol/channels.ts b/src/protocol/channels.ts index e40f063a02..c986b2659a 100644 --- a/src/protocol/channels.ts +++ b/src/protocol/channels.ts @@ -1458,11 +1458,9 @@ export type FrameEvaluateExpressionParams = { expression: string, isFunction?: boolean, arg: SerializedArgument, - world?: 'main' | 'utility', }; export type FrameEvaluateExpressionOptions = { isFunction?: boolean, - world?: 'main' | 'utility', }; export type FrameEvaluateExpressionResult = { value: SerializedValue, @@ -1471,11 +1469,9 @@ export type FrameEvaluateExpressionHandleParams = { expression: string, isFunction?: boolean, arg: SerializedArgument, - world?: 'main' | 'utility', }; export type FrameEvaluateExpressionHandleOptions = { isFunction?: boolean, - world?: 'main' | 'utility', }; export type FrameEvaluateExpressionHandleResult = { handle: JSHandleChannel, diff --git a/src/protocol/protocol.yml b/src/protocol/protocol.yml index 80caacd2a9..55d6831794 100644 --- a/src/protocol/protocol.yml +++ b/src/protocol/protocol.yml @@ -1148,11 +1148,6 @@ Frame: expression: string isFunction: boolean? arg: SerializedArgument - world: - type: enum? - literals: - - main - - utility returns: value: SerializedValue @@ -1161,11 +1156,6 @@ Frame: expression: string isFunction: boolean? arg: SerializedArgument - world: - type: enum? - literals: - - main - - utility returns: handle: JSHandle diff --git a/src/protocol/validator.ts b/src/protocol/validator.ts index b0ee7f30ce..241fdeb503 100644 --- a/src/protocol/validator.ts +++ b/src/protocol/validator.ts @@ -590,13 +590,11 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme { expression: tString, isFunction: tOptional(tBoolean), arg: tType('SerializedArgument'), - world: tOptional(tEnum(['main', 'utility'])), }); scheme.FrameEvaluateExpressionHandleParams = tObject({ expression: tString, isFunction: tOptional(tBoolean), arg: tType('SerializedArgument'), - world: tOptional(tEnum(['main', 'utility'])), }); scheme.FrameFillParams = tObject({ selector: tString, diff --git a/tests/page/frame-evaluate.spec.ts b/tests/page/frame-evaluate.spec.ts index 7536e34a96..79386fe34f 100644 --- a/tests/page/frame-evaluate.spec.ts +++ b/tests/page/frame-evaluate.spec.ts @@ -17,7 +17,6 @@ import { test as it, expect } from './pageTest'; import { attachFrame, detachFrame } from '../config/utils'; -import type { Frame } from '../../src/client/frame'; it('should have different execution contexts', async ({ page, server }) => { await page.goto(server.EMPTY_PAGE); @@ -184,22 +183,3 @@ it('evaluateHandle should work', async ({page, server}) => { expect(windowHandle).toBeTruthy(); }); -it('evaluateInUtility should work', async ({page}) => { - await page.setContent('hello'); - const mainFrame = page.mainFrame() as any as Frame; - await mainFrame.evaluate(() => window['foo'] = 42); - expect(await mainFrame.evaluate(() => window['foo'])).toBe(42); - expect(await mainFrame._evaluateInUtility(() => window['foo'])).toBe(undefined); - expect(await mainFrame._evaluateInUtility(() => document.body.textContent)).toBe('hello'); -}); - -it('evaluateHandleInUtility should work', async ({page}) => { - await page.setContent('hello'); - const mainFrame = page.mainFrame() as any as Frame; - await mainFrame.evaluate(() => window['foo'] = 42); - expect(await mainFrame.evaluate(() => window['foo'])).toBe(42); - const handle1 = await mainFrame._evaluateHandleInUtility(() => window['foo']); - expect(await handle1.jsonValue()).toBe(undefined); - const handle2 = await mainFrame._evaluateHandleInUtility(() => document.body); - expect(await handle2.evaluate(body => body.textContent)).toBe('hello'); -});