Skip to content

Commit

Permalink
Add browser deprecations (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG authored Dec 17, 2024
1 parent 2c9fae9 commit 94bdfeb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@ This functionality can be disabled in your `.env`:
SENTRY_VUE_ALLOW_TEST_ERRORS=false
```

## Deprecating older browsers

You may end up having a lot of errors caused by people using really old browsers that don't support some more modern widely supported functions. To combat this, you can use the `deprecations` section in the configuration file:

```php
'deprecations' => [
'String.prototype.replaceAll',
'Array.prototype.at',
]
```

Before initializing Sentry, this package will first check whether any of the given variables/functions are nullish (null or undefined). These are checked with `window` as the base variable.
If *any* of them end up being nullish, Sentry will not be loaded and frontend errors will not be logged.

## Filtering errors

You can use the standard Sentry configuration for `ignoreErrors` as described in the [sentry documentation](https://docs.sentry.io/platforms/javascript/guides/vue/configuration/filtering/#using-ignore-errors).

This can be done in the configuration file like so:

```php
'ignoreErrors' => [
'AbortError',
'_isDestroyed',
],
```

## License

GNU General Public License v3. Please see [License File](LICENSE) for more information.
12 changes: 12 additions & 0 deletions config/rapidez/sentry-vue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@

// Amount of errors to be logged to sentry (1.00 = 100%)
'sampleRate' => env('SENTRY_VUE_SAMPLE_RATE', 100) / 100,

// See the Sentry documentation: https://docs.sentry.io/platforms/javascript/guides/vue/configuration/filtering/#using-ignore-errors
'ignoreErrors' => [
// 'AbortError',
],

// If any of the following variables/functions are nullish (null or undefined), do not enable Sentry.
// This helps avoid errors that are only caused by extremely old browsers.
'deprecations' => [
// replaceAll has been implemented on all browsers since late 2020. Uncomment to use.
// 'String.prototype.replaceAll',
],
],

// For integrations, see: https://docs.sentry.io/platforms/javascript/guides/vue/configuration/integrations/
Expand Down
15 changes: 14 additions & 1 deletion resources/js/package.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
if (import.meta.env.VITE_SENTRY_DSN !== undefined && window.config.sentry.enabled) {
(() => import('./sentry.js'))()
let deprecations = window.config.sentry.configuration.deprecations || []
let deprecated = false
deprecations.forEach((deprecation) => {
let test = deprecation.split('.').reduce((value, next) => value?.[next] ?? null, window)
if (test === null) {
deprecated = true
}
})

if (deprecated) {
console.error('This browser is not supported. Please upgrade to a newer version.')
} else {
(() => import('./sentry.js'))()
}
}

0 comments on commit 94bdfeb

Please sign in to comment.