Skip to content

Commit f0298ce

Browse files
authored
Merge pull request #124 from codex-team/feature/optional-console-tracker
feat(hawk-js): make console tracker optional
2 parents ce82963 + 9b914eb commit f0298ce

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Initialization settings:
7373
| `vue` | Vue constructor | optional | Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application) |
7474
| `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling |
7575
| `disableVueErrorHandler` | boolean | optional | Do not initialize Vue errors handling |
76+
| `consoleTracking` | boolean | optional | Initialize console logs tracking |
7677
| `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk |
7778

7879
Other available [initial settings](types/hawk-initial-settings.d.ts) are described at the type definition.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hawk.so/javascript",
33
"type": "commonjs",
4-
"version": "3.2.4",
4+
"version": "3.2.5",
55
"description": "JavaScript errors tracking for Hawk.so",
66
"files": [
77
"dist"

src/catcher.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ export default class Catcher {
9292
*/
9393
private readonly disableVueErrorHandler: boolean = false;
9494

95+
/**
96+
* Console log handler
97+
*/
98+
private readonly consoleTracking: boolean;
99+
95100
/**
96101
* Catcher constructor
97102
*
@@ -111,6 +116,7 @@ export default class Catcher {
111116
this.context = settings.context || undefined;
112117
this.beforeSend = settings.beforeSend;
113118
this.disableVueErrorHandler = settings.disableVueErrorHandler ?? false;
119+
this.consoleTracking = settings.consoleTracking ?? true;
114120

115121
if (!this.token) {
116122
log(
@@ -136,7 +142,9 @@ export default class Catcher {
136142
},
137143
});
138144

139-
initConsoleCatcher();
145+
if (this.consoleTracking) {
146+
initConsoleCatcher();
147+
}
140148

141149
/**
142150
* Set global handlers
@@ -237,7 +245,9 @@ export default class Catcher {
237245
* Add error to console logs
238246
*/
239247

240-
addErrorEvent(event);
248+
if (this.consoleTracking) {
249+
addErrorEvent(event);
250+
}
241251

242252
/**
243253
* Promise rejection reason is recommended to be an Error, but it can be a string:
@@ -503,7 +513,7 @@ export default class Catcher {
503513
const userAgent = window.navigator.userAgent;
504514
const location = window.location.href;
505515
const getParams = this.getGetParams();
506-
const consoleLogs = getConsoleLogStack();
516+
const consoleLogs = this.consoleTracking && getConsoleLogStack();
507517

508518
const addons: JavaScriptAddons = {
509519
window: {
@@ -522,7 +532,7 @@ export default class Catcher {
522532
addons.RAW_EVENT_DATA = this.getRawData(error);
523533
}
524534

525-
if (consoleLogs.length > 0) {
535+
if (consoleLogs && consoleLogs.length > 0) {
526536
addons.consoleOutput = consoleLogs;
527537
}
528538

src/types/hawk-initial-settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,9 @@ export interface HawkInitialSettings {
7373
* Used by @hawk.so/nuxt since Nuxt has own error hook.
7474
*/
7575
disableVueErrorHandler?: boolean;
76+
77+
/**
78+
* Console log handler
79+
*/
80+
consoleTracking?: boolean;
7681
}

0 commit comments

Comments
 (0)