Skip to content

Commit 767e2d3

Browse files
Prevent debugging serialization to cause page to break
1 parent 96b512b commit 767e2d3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,22 @@ export function hasTaintedMethod (scope, shouldStackCheck = false) {
398398
return false
399399
}
400400

401+
/**
402+
* @param {*[]} argsArray
403+
* @returns {string | undefined}
404+
*/
405+
function debugSerialize (argsArray) {
406+
const serializedArgs = argsArray.map((arg) => {
407+
try {
408+
return JSON.stringify(arg)
409+
} catch (e) {
410+
// Sometimes this happens when we can't serialize an object to string but we still wish to log it and make other args readable
411+
return '[unserializable]'
412+
}
413+
})
414+
return JSON.stringify(serializedArgs)
415+
}
416+
401417
/**
402418
* @template {object} P
403419
* @typedef {object} ProxyObject<P>
@@ -440,7 +456,7 @@ export class DDGProxy {
440456
kind: this.property,
441457
documentUrl: document.location.href,
442458
stack: getStack(),
443-
args: JSON.stringify(args[2])
459+
args: debugSerialize(args[2])
444460
})
445461
}
446462
// The normal return value

0 commit comments

Comments
 (0)