diff --git a/packages/playwright-core/src/protocol/serializers.ts b/packages/playwright-core/src/protocol/serializers.ts index 5ceeb3bb0e..d43747237f 100644 --- a/packages/playwright-core/src/protocol/serializers.ts +++ b/packages/playwright-core/src/protocol/serializers.ts @@ -71,6 +71,8 @@ function innerParseSerializedValue(value: SerializedValue, handles: any[] | unde return new Date(value.d); if (value.u !== undefined) return new URL(value.u); + if (value.bi !== undefined) + return BigInt(value.bi); if (value.r !== undefined) return new RegExp(value.r.p, value.r.f); @@ -133,6 +135,8 @@ function innerSerializeValue(value: any, handleSerializer: (value: any) => Handl return { n: value }; if (typeof value === 'string') return { s: value }; + if (typeof value === 'bigint') + return { bi: value.toString() }; if (isError(value)) { const error = value; if ('captureStackTrace' in globalThis.Error) { diff --git a/packages/playwright-core/src/protocol/validator.ts b/packages/playwright-core/src/protocol/validator.ts index 378d8bda70..c7aa380f7f 100644 --- a/packages/playwright-core/src/protocol/validator.ts +++ b/packages/playwright-core/src/protocol/validator.ts @@ -57,6 +57,7 @@ scheme.SerializedValue = tObject({ v: tOptional(tEnum(['null', 'undefined', 'NaN', 'Infinity', '-Infinity', '-0'])), d: tOptional(tString), u: tOptional(tString), + bi: tOptional(tString), r: tOptional(tObject({ p: tString, f: tString, diff --git a/packages/playwright-core/src/server/isomorphic/utilityScriptSerializers.ts b/packages/playwright-core/src/server/isomorphic/utilityScriptSerializers.ts index c65b68b8e4..f356bf6906 100644 --- a/packages/playwright-core/src/server/isomorphic/utilityScriptSerializers.ts +++ b/packages/playwright-core/src/server/isomorphic/utilityScriptSerializers.ts @@ -19,6 +19,7 @@ export type SerializedValue = { v: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0' } | { d: string } | { u: string } | + { bi: string } | { r: { p: string, f: string} } | { a: SerializedValue[], id: number } | { o: { k: string, v: SerializedValue }[], id: number } | @@ -91,6 +92,8 @@ export function source() { return new Date(value.d); if ('u' in value) return new URL(value.u); + if ('bi' in value) + return BigInt(value.bi); if ('r' in value) return new RegExp(value.r.p, value.r.f); if ('a' in value) { @@ -157,6 +160,8 @@ export function source() { return value; if (typeof value === 'string') return value; + if (typeof value === 'bigint') + return { bi: value.toString() }; if (isError(value)) { const error = value; diff --git a/packages/protocol/src/channels.ts b/packages/protocol/src/channels.ts index 76cee1e207..d008c2c005 100644 --- a/packages/protocol/src/channels.ts +++ b/packages/protocol/src/channels.ts @@ -179,6 +179,7 @@ export type SerializedValue = { v?: 'null' | 'undefined' | 'NaN' | 'Infinity' | '-Infinity' | '-0', d?: string, u?: string, + bi?: string, r?: { p: string, f: string, diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.yml index 7be9a814cd..12eed0c925 100644 --- a/packages/protocol/src/protocol.yml +++ b/packages/protocol/src/protocol.yml @@ -80,6 +80,8 @@ SerializedValue: d: string? # String representation of the URL. u: string? + # String representation of BigInt. + bi: string? # Regular expression pattern and flags. r: type: object? diff --git a/tests/page/page-evaluate.spec.ts b/tests/page/page-evaluate.spec.ts index d6af07678f..db1120d6fe 100644 --- a/tests/page/page-evaluate.spec.ts +++ b/tests/page/page-evaluate.spec.ts @@ -94,6 +94,11 @@ it('should transfer arrays as arrays, not objects', async ({ page }) => { expect(result).toBe(true); }); +it('should transfer bigint', async ({ page }) => { + expect(await page.evaluate(() => 42n)).toBe(42n); + expect(await page.evaluate(a => a, 17n)).toBe(17n); +}); + it('should transfer maps as empty objects', async ({ page }) => { const result = await page.evaluate(a => a.x.constructor.name + ' ' + JSON.stringify(a.x), { x: new Map([[1, 2]]) }); expect(result).toBe('Object {}');