Skip to content

Commit

Permalink
fix: console logger can serialize bigint values
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Jan 25, 2024
1 parent b2460a4 commit 87c6b13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/rrweb/src/plugins/console/record/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function stringify(
const keys: unknown[] = [];
return JSON.stringify(
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
* to deCycle the object
Expand Down Expand Up @@ -120,6 +120,9 @@ export function stringify(
if (shouldIgnore(value as object)) {
return toString(value as object);
}
if (typeof value === 'bigint') {
return value.toString() + 'n';
}
if (value instanceof Event) {
const eventResult: Record<string, unknown> = {};
for (const eventKey in value) {
Expand Down Expand Up @@ -158,7 +161,7 @@ export function stringify(
return true;
}

// is function
// is function or bigint
if (typeof _obj === 'function') {
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions packages/rrweb/test/plugins/console/record.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { stringify } from '../../../src/plugins/console/record/stringify';

describe('console record plugin', () => {
it('can stringify bigint', () => {
expect(stringify(BigInt(1))).toEqual('"1n"');
});
});

0 comments on commit 87c6b13

Please sign in to comment.