Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: fix all Proxy() to account for symbol properties (#21272)
Dmitry Gozman27027658dc20
diff --git a/packages/playwright-core/src/client/channelOwner.ts b/packages/playwright-core/src/client/channelOwner.tsindex af85d90fe7..6a2118cf75 100644--- a/packages/playwright-core/src/client/channelOwner.ts+++ b/packages/playwright-core/src/client/channelOwner.ts@@ -132,7 +132,7 @@ export abstract class ChannelOwner<T extends channels.Channel = channels.Channelprivate _createChannel(base: Object): T {const channel = new Proxy(base, {- get: (obj: any, prop) => {+ get: (obj: any, prop: string | symbol) => {if (typeof prop === 'string') {const validator = maybeFindValidator(this._type, prop, 'Params');if (validator) {diff --git a/packages/playwright-core/src/client/clientInstrumentation.ts b/packages/playwright-core/src/client/clientInstrumentation.tsindex bda55dca49..a90f2964ad 100644--- a/packages/playwright-core/src/client/clientInstrumentation.ts+++ b/packages/playwright-core/src/client/clientInstrumentation.ts@@ -31,7 +31,9 @@ export interface ClientInstrumentationListener {export function createInstrumentation(): ClientInstrumentation {const listeners: ClientInstrumentationListener[] = [];return new Proxy({}, {- get: (obj: any, prop: string) => {+ get: (obj: any, prop: string | symbol) => {+ if (typeof prop !== 'string')+ return obj[prop];if (prop === 'addListener')return (listener: ClientInstrumentationListener) => listeners.push(listener);if (prop === 'removeListener')diff --git a/packages/playwright-core/src/server/instrumentation.ts b/packages/playwright-core/src/server/instrumentation.tsindex 8f06a7afcd..d58ed444ea 100644--- a/packages/playwright-core/src/server/instrumentation.ts+++ b/packages/playwright-core/src/server/instrumentation.ts@@ -84,7 +84,9 @@ export interface InstrumentationListener {export function createInstrumentation(): Instrumentation {const listeners = new Map<InstrumentationListener, BrowserContext | APIRequestContext | null>();return new Proxy({}, {- get: (obj: any, prop: string) => {+ get: (obj: any, prop: string | symbol) => {+ if (typeof prop !== 'string')+ return obj[prop];if (prop === 'addListener')return (listener: InstrumentationListener, context: BrowserContext | APIRequestContext | null) => listeners.set(listener, context);if (prop === 'removeListener')diff --git a/packages/playwright-core/src/server/socksInterceptor.ts b/packages/playwright-core/src/server/socksInterceptor.tsindex 0fd31645e5..498e8bfe73 100644--- a/packages/playwright-core/src/server/socksInterceptor.ts+++ b/packages/playwright-core/src/server/socksInterceptor.ts@@ -32,7 +32,7 @@ export class SocksInterceptor {let lastId = -1;this._channel = new Proxy(new EventEmitter(), {- get: (obj: any, prop) => {+ get: (obj: any, prop: string | symbol) => {if ((prop in obj) || obj[prop] !== undefined || typeof prop !== 'string')return obj[prop];return (params: any) => {diff --git a/packages/playwright-test/src/matchers/expect.ts b/packages/playwright-test/src/matchers/expect.tsindex f6a3707101..af94aa5312 100644--- a/packages/playwright-test/src/matchers/expect.ts+++ b/packages/playwright-test/src/matchers/expect.ts@@ -101,7 +101,7 @@ export const printReceivedStringContainExpectedResult = (type ExpectMessageOrOptions = undefined | string | { message?: string, timeout?: number, intervals?: number[] };-function createExpect(actual: unknown, messageOrOptions: ExpectMessageOrOptions, isSoft: boolean, isPoll: boolean, generator?: Generator) {+function createExpect(actual: unknown, messageOrOptions: ExpectMessageOrOptions, isSoft: boolean, isPoll: boolean, generator?: Generator): any {return new Proxy(expectLibrary(actual), new ExpectMetaInfoProxyHandler(messageOrOptions, isSoft, isPoll, generator));}@@ -164,7 +164,7 @@ type ExpectMetaInfo = {generator?: Generator;};-class ExpectMetaInfoProxyHandler {+class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {private _info: ExpectMetaInfo;constructor(messageOrOptions: ExpectMessageOrOptions, isSoft: boolean, isPoll: boolean, generator?: Generator) {@@ -178,8 +178,10 @@ class ExpectMetaInfoProxyHandler {}}- get(target: any, matcherName: any, receiver: any): any {+ get(target: Object, matcherName: string | symbol, receiver: any): any {let matcher = Reflect.get(target, matcherName, receiver);+ if (typeof matcherName !== 'string')+ return matcher;if (matcher === undefined)throw new Error(`expect: Property '${matcherName}' not found.`);if (typeof matcher !== 'function') {diff --git a/tests/page/page-basic.spec.ts b/tests/page/page-basic.spec.tsindex f0980698c3..1f2458ddc1 100644--- a/tests/page/page-basic.spec.ts+++ b/tests/page/page-basic.spec.ts@@ -257,3 +257,11 @@ it('has navigator.webdriver set to true', async ({ page, browserName }) => {it.skip(browserName === 'firefox');expect(await page.evaluate(() => navigator.webdriver)).toBe(true);});++it('should iterate over page properties', async ({ page }) => {+ const props = [];+ for (const prop in page) {+ if (page[prop] && typeof page[prop] === 'object')+ props.push(page[prop][Symbol.iterator]);+ }+});