Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify API call arguments. #68

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion collectors/APICallCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ class APICallCollector extends BaseCollector {
this._calls.push({
source: breakpoint.source,
description: breakpoint.description,
arguments: breakpoint.arguments
arguments: breakpoint.arguments.map(arg => {
try {
return JSON.parse(arg);
} catch (e) {
return arg;
}
})
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion collectors/APICalls/TrackerTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ class TrackerTracker {
// only save arguments if requested for given breakpoint
if (saveArguments) {
conditionScript += `
data.args = Array.from(arguments).map(a => a.toString());
data.args = Array.from(arguments).map(a => {
try {
return JSON.stringify(a);
} catch (e) {
return a.toString();
}
});
`;
}

Expand Down
11 changes: 9 additions & 2 deletions tests/collectors/APICallCollector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ async function main() {
payload: JSON.stringify({
description: 'Document.cookie setter',
stack: '(https://example.com/different.js:1:23)\n(https://example.com/different.js:2:23)',
args: ['uuid=123']
args: [
"\"uuid=123\"",
"{\"key\":\"key\",\"value\":\"value\"}"
]
})
});

Expand All @@ -113,7 +116,11 @@ async function main() {
source: 'https://example.com/different.js',
description: 'Document.cookie setter',
arguments: [
'uuid=123'
"uuid=123",
{
key: "key",
value: "value"
}
]
}
]
Expand Down