fix: console logger can serialize bigint values (#1403)
* fix: console logger can serialize bigint values * teach test jsdom is present * add a changeset
This commit is contained in:
5
.changeset/breezy-mice-breathe.md
Normal file
5
.changeset/breezy-mice-breathe.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'rrweb': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
safely capture BigInt values with the console log plugin"
|
||||||
@@ -91,7 +91,7 @@ export function stringify(
|
|||||||
const keys: unknown[] = [];
|
const keys: unknown[] = [];
|
||||||
return JSON.stringify(
|
return JSON.stringify(
|
||||||
obj,
|
obj,
|
||||||
function (key, value: string | object | null | undefined) {
|
function (key, value: string | bigint | object | null | undefined) {
|
||||||
/**
|
/**
|
||||||
* forked from https://github.com/moll/json-stringify-safe/blob/master/stringify.js
|
* forked from https://github.com/moll/json-stringify-safe/blob/master/stringify.js
|
||||||
* to deCycle the object
|
* to deCycle the object
|
||||||
@@ -120,6 +120,9 @@ export function stringify(
|
|||||||
if (shouldIgnore(value as object)) {
|
if (shouldIgnore(value as object)) {
|
||||||
return toString(value as object);
|
return toString(value as object);
|
||||||
}
|
}
|
||||||
|
if (typeof value === 'bigint') {
|
||||||
|
return value.toString() + 'n';
|
||||||
|
}
|
||||||
if (value instanceof Event) {
|
if (value instanceof Event) {
|
||||||
const eventResult: Record<string, unknown> = {};
|
const eventResult: Record<string, unknown> = {};
|
||||||
for (const eventKey in value) {
|
for (const eventKey in value) {
|
||||||
@@ -158,7 +161,7 @@ export function stringify(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// is function
|
// is function or bigint
|
||||||
if (typeof _obj === 'function') {
|
if (typeof _obj === 'function') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
11
packages/rrweb/test/plugins/console/record.test.ts
Normal file
11
packages/rrweb/test/plugins/console/record.test.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { stringify } from '../../../src/plugins/console/record/stringify';
|
||||||
|
|
||||||
|
describe('console record plugin', () => {
|
||||||
|
it('can stringify bigint', () => {
|
||||||
|
expect(stringify(BigInt(1))).toEqual('"1n"');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user