From 2784e9b4532a345bf424dde77baec7d1270faf10 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Thu, 24 Apr 2025 16:08:07 +0300 Subject: [PATCH 1/6] init --- README.md | 1 + src/catcher.ts | 11 ++++++++++- src/types/hawk-initial-settings.ts | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 454b498..b8e878f 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Initialization settings: | `vue` | Vue constructor | optional | Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application) | | `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling | | `disableVueErrorHandler` | boolean | optional | Do not initialize Vue errors handling | +| `disableConsoleLogHandler` | boolean | optional | Do not initialize console logs tracking | | `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk | Other available [initial settings](types/hawk-initial-settings.d.ts) are described at the type definition. diff --git a/src/catcher.ts b/src/catcher.ts index 0cd4326..32ab2ef 100644 --- a/src/catcher.ts +++ b/src/catcher.ts @@ -92,6 +92,11 @@ export default class Catcher { */ private readonly disableVueErrorHandler: boolean = false; + /** + * Disable console log handler + */ + private readonly disableConsoleLogHandler: boolean = false; + /** * Catcher constructor * @@ -111,6 +116,7 @@ export default class Catcher { this.context = settings.context || undefined; this.beforeSend = settings.beforeSend; this.disableVueErrorHandler = settings.disableVueErrorHandler ?? false; + this.disableConsoleLogHandler = settings.disableConsoleLogHandler ?? false; if (!this.token) { log( @@ -136,7 +142,10 @@ export default class Catcher { }, }); - initConsoleCatcher(); + if (!settings.disableConsoleLogHandler) { + initConsoleCatcher(); + console.log('Console log handler initialized'); + } /** * Set global handlers diff --git a/src/types/hawk-initial-settings.ts b/src/types/hawk-initial-settings.ts index 0cd7a59..6ad54e2 100644 --- a/src/types/hawk-initial-settings.ts +++ b/src/types/hawk-initial-settings.ts @@ -73,4 +73,9 @@ export interface HawkInitialSettings { * Used by @hawk.so/nuxt since Nuxt has own error hook. */ disableVueErrorHandler?: boolean; + + /** + * Disable console log handler + */ + disableConsoleLogHandler?: boolean; } From 0f796754bc80cb22904f3590ac6c98b6760c50dd Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Thu, 24 Apr 2025 16:51:07 +0300 Subject: [PATCH 2/6] dev --- src/catcher.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/catcher.ts b/src/catcher.ts index 32ab2ef..6d64f96 100644 --- a/src/catcher.ts +++ b/src/catcher.ts @@ -144,7 +144,6 @@ export default class Catcher { if (!settings.disableConsoleLogHandler) { initConsoleCatcher(); - console.log('Console log handler initialized'); } /** @@ -246,7 +245,9 @@ export default class Catcher { * Add error to console logs */ - addErrorEvent(event); + if (!this.disableConsoleLogHandler) { + addErrorEvent(event); + } /** * Promise rejection reason is recommended to be an Error, but it can be a string: @@ -512,7 +513,7 @@ export default class Catcher { const userAgent = window.navigator.userAgent; const location = window.location.href; const getParams = this.getGetParams(); - const consoleLogs = getConsoleLogStack(); + const consoleLogs = !this.disableConsoleLogHandler ? getConsoleLogStack() : []; const addons: JavaScriptAddons = { window: { From 519359cde594a9c20039d49689f2454de7a5ab2a Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Thu, 24 Apr 2025 23:05:16 +0300 Subject: [PATCH 3/6] version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 36d8941..87ea539 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@hawk.so/javascript", "type": "commonjs", - "version": "3.2.4", + "version": "3.2.5", "description": "JavaScript errors tracking for Hawk.so", "files": [ "dist" From acb251fa26c0aadc943b1cfed6830934498ff221 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 26 Apr 2025 16:46:27 +0300 Subject: [PATCH 4/6] consoleTracking --- README.md | 2 +- src/catcher.ts | 12 ++++++------ src/types/hawk-initial-settings.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b8e878f..11fb44a 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Initialization settings: | `vue` | Vue constructor | optional | Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application) | | `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling | | `disableVueErrorHandler` | boolean | optional | Do not initialize Vue errors handling | -| `disableConsoleLogHandler` | boolean | optional | Do not initialize console logs tracking | +| `consoleTracking` | boolean | optional | Initialize console logs tracking | | `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk | Other available [initial settings](types/hawk-initial-settings.d.ts) are described at the type definition. diff --git a/src/catcher.ts b/src/catcher.ts index 6d64f96..d94c872 100644 --- a/src/catcher.ts +++ b/src/catcher.ts @@ -93,9 +93,9 @@ export default class Catcher { private readonly disableVueErrorHandler: boolean = false; /** - * Disable console log handler + * Console log handler */ - private readonly disableConsoleLogHandler: boolean = false; + private readonly consoleTracking: boolean = true; /** * Catcher constructor @@ -116,7 +116,7 @@ export default class Catcher { this.context = settings.context || undefined; this.beforeSend = settings.beforeSend; this.disableVueErrorHandler = settings.disableVueErrorHandler ?? false; - this.disableConsoleLogHandler = settings.disableConsoleLogHandler ?? false; + this.consoleTracking = settings.consoleTracking ?? true; if (!this.token) { log( @@ -142,7 +142,7 @@ export default class Catcher { }, }); - if (!settings.disableConsoleLogHandler) { + if (settings.consoleTracking) { initConsoleCatcher(); } @@ -245,7 +245,7 @@ export default class Catcher { * Add error to console logs */ - if (!this.disableConsoleLogHandler) { + if (this.consoleTracking) { addErrorEvent(event); } @@ -513,7 +513,7 @@ export default class Catcher { const userAgent = window.navigator.userAgent; const location = window.location.href; const getParams = this.getGetParams(); - const consoleLogs = !this.disableConsoleLogHandler ? getConsoleLogStack() : []; + const consoleLogs = this.consoleTracking ? getConsoleLogStack() : []; const addons: JavaScriptAddons = { window: { diff --git a/src/types/hawk-initial-settings.ts b/src/types/hawk-initial-settings.ts index 6ad54e2..04bfe24 100644 --- a/src/types/hawk-initial-settings.ts +++ b/src/types/hawk-initial-settings.ts @@ -75,7 +75,7 @@ export interface HawkInitialSettings { disableVueErrorHandler?: boolean; /** - * Disable console log handler + * Console log handler */ - disableConsoleLogHandler?: boolean; + consoleTracking?: boolean; } From a4b6516494a0c07dfbf1b9646d9378f2d1598d03 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 26 Apr 2025 17:17:00 +0300 Subject: [PATCH 5/6] fix --- src/catcher.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catcher.ts b/src/catcher.ts index d94c872..8d7886c 100644 --- a/src/catcher.ts +++ b/src/catcher.ts @@ -95,7 +95,7 @@ export default class Catcher { /** * Console log handler */ - private readonly consoleTracking: boolean = true; + private readonly consoleTracking: boolean; /** * Catcher constructor @@ -142,7 +142,7 @@ export default class Catcher { }, }); - if (settings.consoleTracking) { + if (this.consoleTracking) { initConsoleCatcher(); } From 9b914ebe66165254753ec63750256273c110cff4 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 26 Apr 2025 17:50:31 +0300 Subject: [PATCH 6/6] consoleLogs fix --- src/catcher.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catcher.ts b/src/catcher.ts index 8d7886c..62ba63a 100644 --- a/src/catcher.ts +++ b/src/catcher.ts @@ -513,7 +513,7 @@ export default class Catcher { const userAgent = window.navigator.userAgent; const location = window.location.href; const getParams = this.getGetParams(); - const consoleLogs = this.consoleTracking ? getConsoleLogStack() : []; + const consoleLogs = this.consoleTracking && getConsoleLogStack(); const addons: JavaScriptAddons = { window: { @@ -532,7 +532,7 @@ export default class Catcher { addons.RAW_EVENT_DATA = this.getRawData(error); } - if (consoleLogs.length > 0) { + if (consoleLogs && consoleLogs.length > 0) { addons.consoleOutput = consoleLogs; }