• /
  • Log in
  • Free account

CSP v2: Host and install the Browser agent

If your organization has strict requirements about Content Security Policy (CSP) v2, you may need to host the New Relic Browser agent in order to properly install and run it. For example, if the New Relic domain hosting the Browser agent is being blocked by your website, you may see an error similar to this:

Browser agent.js is unable to run because it violates the following 
Content Security Protocol directive: script-src = *.google.com other URLs

In this situation, you must copy and paste the agent's JavaScript code and self-host it as a .js file. This allows the page to reference the .js file during page load.



In order to host the Browser agent with your app, make sure you follow these requirements:

CSP and Browser agent


Application or platform

Your app or platform where your site is hosted must meet New Relic Browser's standard compatibility requirements. Exception: CSP restrictions prevent you from linking an APM app for Browser monitoring.


You must have a Pro+SPA Browser subscription for your app.

Host location for domains

The .js file for New Relic Browser must be hosted on a highly available or replicated location, such as a CDN or distributed network. This helps ensure performance is not affected.

  • If you see error messages, add New Relic Browser domains to your CSP whitelist.

  • If you want New Relic Browser to monitor Salesforce Lightning pages, follow the Salesforce procedures to add New Relic Browser domains to your CSP whitelist.

    By hosting the agent, you are responsible for any performance impact on the location where the agent is hosted.

Browser agent version

Your selected app must use the latest Browser agent version.

1. Whitelist New Relic Browser domains

Follow your organization's standard procedures to request a CSP exception. Then add both of these New Relic Browser domains to your CSP whitelist:

  • https://js-agent.newrelic.com: This is where the New Relic Browser agent is hosted. The Browser agent download requires three files to run. Two are downloaded after the initial agent is run to continue capturing performance data.
  • https://bam.nr-data.net: This is the endpoint where the New Relic Browser agent receives data from your site.

Here is example HTML to add to the head of your site:

Content-Security-Policy: default-src 'self' https://js-agent.newrelic.com https://bam.nr-data.net

2. Copy Browser app's JS snippet

To create and host a .js file, you must first copy the Browser agent's JavaScript snippet from the hosting app.

  1. Go to rpm.newrelic.com/browser.
  2. From the list of Browser apps, select the app for which you want to self-host the Browser agent.
  3. Select Settings > Application settings > Copy/paste JavaScript code.
  4. Copy the Browser agent's JavaScript snippet.
  5. Save and exit the Browser app's Application settings page.

Continue with the procedures to create a .js file for your page.

3. Create .js file for page

After you copy the Browser agent's JavaScript snippet from the selected Browser app:

  1. Open a text editor and paste the Browser agent's JavaScript snippet.
  2. Delete the first line (<script type="text/javascript">) and the last line of the JavaScript snippet (</script>).
  3. Save the text file as nr-spa-VERSION_NUMBER.min.js, where VERSION_NUMBER is the latest Browser agent version.
  4. Reference the .js file in the <head> of your webpage.

After you install the Browser agent's JavaScript snippet, you can use the New Relic Browser UI to monitor website performance.

For more help

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.