diff --git a/README.md b/README.md index 454b498..11fb44a 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 | +| `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/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" diff --git a/src/catcher.ts b/src/catcher.ts index 0cd4326..62ba63a 100644 --- a/src/catcher.ts +++ b/src/catcher.ts @@ -92,6 +92,11 @@ export default class Catcher { */ private readonly disableVueErrorHandler: boolean = false; + /** + * Console log handler + */ + private readonly consoleTracking: boolean; + /** * 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.consoleTracking = settings.consoleTracking ?? true; if (!this.token) { log( @@ -136,7 +142,9 @@ export default class Catcher { }, }); - initConsoleCatcher(); + if (this.consoleTracking) { + initConsoleCatcher(); + } /** * Set global handlers @@ -237,7 +245,9 @@ export default class Catcher { * Add error to console logs */ - addErrorEvent(event); + if (this.consoleTracking) { + addErrorEvent(event); + } /** * Promise rejection reason is recommended to be an Error, but it can be a string: @@ -503,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.consoleTracking && getConsoleLogStack(); const addons: JavaScriptAddons = { window: { @@ -522,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; } diff --git a/src/types/hawk-initial-settings.ts b/src/types/hawk-initial-settings.ts index 0cd7a59..04bfe24 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; + + /** + * Console log handler + */ + consoleTracking?: boolean; }