Browser monitoring is a beta AppSignal Labs feature. The
@appsignal/browser package is published under the beta tag on npm, and its
configuration and API may still change between beta releases. Share feedback
in our Discord community.Find your Front-end API key
Browser monitoring uses your application’s Front-end API key, listed under “Front-end error monitoring” on the “Push & deploy” page of your application’s settings. This key is app-specific, so a staging and a production app each have their own. It is meant to be exposed in public, so it is safe to include in your front-end bundle. It is not one of the Push keys your back-end integrations use. Those are on the same page, listed as the Organization Push key and the App environment Push key, and they are write-only keys that must stay secret. If you ever need to replace the Front-end API key, that page has a button to cycle it. Cycling generates a new key and invalidates the old one in a single step, and you cannot undo it, so deploy the new key promptly. Anything still sending the old key stops reporting in the meantime.Install the package
beta tag. Without it, package managers resolve to the latest stable release, and there is not one yet.
Initialize the SDK
Callinit() once, as early in the page lifecycle as you can. Anything that throws before init() runs is not captured.
Create an appsignal.js file next to your application’s entry point:
activeties collection to your build environment, so development, test, and CI runs stay quiet. When it isfalse,init()does nothing at all: it changes nothing on the page, starts no timers, and makes no requests. Every other function does nothing too, so you can call them anywhere without checking first.appVersionis the release tag, commit SHA, or deploy ID of the running build. Errors and web vitals are tagged with it, which is what makes the version filters and sourcemap lookups work.endpointis where data is sent. Usehttps://appsignal-endpoint.netunless you proxy AppSignal traffic through your own domain. When you leave it out, the SDK posts to the current origin, which is the setting you want if you do proxy.
Install without a bundler
If you add JavaScript to your pages with a plain<script> tag rather than building it with a bundler, use the UMD build. It provides the same functions on a global called AppsignalBrowser:
Report the current route
Single-page applications should tell the SDK which route template the user is on, for example/users/:id rather than /users/42:
Verify the installation
- Deploy a build with
activeset totrue, or temporarily setactive: truein development. - Open your application and throw an error from the browser console, for example
setTimeout(() => { throw new Error("AppSignal test error") }). Throwing from the console directly is caught by the console itself and never reacheswindow. - Open the Errors view in the Browser section of your application in AppSignal. The error arrives within a few seconds.
Content Security Policy
If your application sends a Content Security Policy header, add the AppSignal endpoint toconnect-src, or requests are blocked:
Assets hosted on a CDN
When a script loaded from another domain throws an error, the browser refuses to share the details. Your page sees only the messageScript error., with no stack trace and no line number. There is nothing there to debug, so the SDK throws those away.
To get the real errors from scripts on a CDN, serve them with an Access-Control-Allow-Origin header and add the crossorigin attribute to the script tags:
📖 Continue with our installation guide.
Uninstall
- Remove the
import "./appsignal"line from your entry point, and deleteappsignal.js. - Remove
@appsignal/browserfrom yourpackage.json, then runnpm installoryarn installto update your lockfile. Alternatively, runnpm uninstall @appsignal/browseroryarn remove @appsignal/browser. - Commit and deploy. Your application stops sending browser data as soon as the new build is live.
- Optionally, remove the app in AppSignal.
destroy(). It takes effect immediately, but does not persist: the next page load starts collecting again.
📖 Continue with our uninstall
guide.