mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
[DEBUG] More descriptive event reporting
This patch improves DEBUG reporting so that circular event arguments are shown with some information.
This commit is contained in:
parent
0f3a0dcbfc
commit
adf35952fc
@ -158,19 +158,24 @@ class Helper {
|
||||
* @return {string}
|
||||
*/
|
||||
function stringifyArgument(arg) {
|
||||
if (typeof arg !== 'function') {
|
||||
try {
|
||||
if (Helper.isString(arg) || Helper.isNumber(arg) || !arg)
|
||||
return JSON.stringify(arg);
|
||||
} catch (e) {
|
||||
// The object was recursive
|
||||
return arg.toString();
|
||||
}
|
||||
}
|
||||
if (typeof arg === 'function') {
|
||||
let text = arg.toString().split('\n').map(line => line.trim()).join('');
|
||||
if (text.length > 20)
|
||||
text = text.substring(0, 20) + '…';
|
||||
return `"${text}"`;
|
||||
}
|
||||
const state = {};
|
||||
const keys = Object.keys(arg);
|
||||
for (let key of keys) {
|
||||
const value = arg[key];
|
||||
if (Helper.isString(value) || Helper.isNumber(value))
|
||||
state[key] = JSON.stringify(value);
|
||||
}
|
||||
const name = arg.constructor.name === 'Object' ? '' : arg.constructor.name;
|
||||
return name + JSON.stringify(state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user