Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hawk.so/javascript",
"type": "commonjs",
"version": "3.2.5",
"version": "3.2.6",
"description": "JavaScript errors tracking for Hawk.so",
"files": [
"dist"
Expand Down
18 changes: 16 additions & 2 deletions src/addons/consoleCatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function createConsoleCatcher(): {
* Converts any argument to its string representation
*
* @param arg - Value to convert to string
* @throws Error if the argument can not be stringified, for example by such reason:
* SecurityError: Failed to read a named property 'toJSON' from 'Window': Blocked a frame with origin "https://codex.so" from accessing a cross-origin frame.
*/
function stringifyArg(arg: unknown): string {
if (typeof arg === 'string') {
Expand Down Expand Up @@ -52,7 +54,13 @@ function createConsoleCatcher(): {

if (typeof firstArg !== 'string' || !firstArg.includes('%c')) {
return {
message: args.map(stringifyArg).join(' '),
message: args.map(arg => {
try {
return stringifyArg(arg);
} catch (error) {
return '[Error stringifying argument: ' + (error instanceof Error ? error.message : String(error)) + ']';
}
}).join(' '),
styles: [],
};
}
Expand All @@ -76,7 +84,13 @@ function createConsoleCatcher(): {
// Add remaining arguments that aren't styles
const remainingArgs = args
.slice(styles.length + 1)
.map(stringifyArg)
.map(arg => {
try {
return stringifyArg(arg);
} catch (error) {
return '[Error stringifying argument: ' + (error instanceof Error ? error.message : String(error)) + ']';
}
})
.join(' ');

return {
Expand Down