> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/framework-setups/angular.md).

# Angular

> **Applies to:** Angular CLI applications. Angular 17 and later build with the esbuild-based **application** builder by default; Angular 8–16 (and projects that kept `@angular-devkit/build-angular:browser`) build with **webpack**.

## Which builder do you use? <a href="#which-builder" id="which-builder"></a>

Open `angular.json` → `projects.<app>.architect.build.builder`:

| `builder` value                                                             | Output folder to scan | Output format                                                   | `--es6Modules` |
| --------------------------------------------------------------------------- | --------------------- | --------------------------------------------------------------- | -------------- |
| `@angular-devkit/build-angular:application` or `@angular/build:application` | `dist/<app>/browser`  | ES modules (`main-*.js`, `chunk-*.js`, `polyfills-*.js`)        | Yes            |
| `@angular-devkit/build-angular:browser-esbuild`                             | `dist/<app>`          | ES modules                                                      | Yes            |
| `@angular-devkit/build-angular:browser` (webpack)                           | `dist/<app>`          | Classic scripts (`main.*.js`, `runtime.*.js`, `polyfills.*.js`) | No             |

## Step 1: Turn on source maps for the build you scan <a href="#source-maps" id="source-maps"></a>

Production builds have source maps off by default. Turn them on in the configuration you build for testing (here `production`):

```jsonc
// angular.json → projects.<app>.architect.build.configurations.production
{
  "sourceMap": {
    "scripts": true,
    "styles": false,
    "vendor": false,
    "hidden": false
  }
}
```

* `"sourceMap": true` also works.
* `"hidden": true` works too, as long as the `.map` files stay next to the bundles during the scan.
* `"vendor": false` keeps third-party code out of the maps.

## Step 2: Build, scan and instrument <a href="#scan" id="scan"></a>

{% tabs %}
{% tab title="Angular 17+ (application builder)" %}

```bash
printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
npm ci
npx ng build --configuration production

npx slnodejs config --tokenFile sltoken.txt --appName my-angular-app \
  --branchName "$BRANCH_NAME" --buildName "$BUILD_NUMBER"
npx slnodejs scan --tokenFile sltoken.txt --buildSessionIdFile buildSessionId \
  --scanDir dist/my-angular-app/browser --scmType git --es6Modules \
  --instrumentForBrowsers --outputPath sl_dist \
  --labId qa-env --excludeSourceMapFiles skipCopy
```

{% endtab %}

{% tab title="Angular 8–16 (webpack)" %}

```bash
printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
npm ci
npx ng build --configuration production

npx slnodejs config --tokenFile sltoken.txt --appName my-angular-app \
  --branchName "$BRANCH_NAME" --buildName "$BUILD_NUMBER"
npx slnodejs scan --tokenFile sltoken.txt --buildSessionIdFile buildSessionId \
  --scanDir dist/my-angular-app --scmType git \
  --instrumentForBrowsers --outputPath sl_dist \
  --labId qa-env --excludeSourceMapFiles skipCopy
```

{% endtab %}
{% endtabs %}

Deploy the contents of `sl_dist` in place of the build output folder.

## Step 3: Exclude what you do not maintain <a href="#exclude" id="exclude"></a>

Angular internals (`@angular/`, `zone.js`, `rxjs`, `tslib`) are not instrumented by default. Exclude generated bundles from the scan with a `.slignore` in the project root:

```gitignore
# webpack builder
**/runtime*.js
**/polyfills*.js
**/vendor*.js
# Angular 8–12 differential loading: legacy ES5 copies
**/*-es5.js
**/es5/**
# esbuild builder
**/polyfills-*.js
```

Without the `-es5` exclusions, Angular 8–12 builds report every method twice; see [Angular 8+: Duplicate Method Reporting](https://docs.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/node-javascript/angular-8+-duplicate-method-reporting.md).

## Angular-specific notes <a href="#notes" id="notes"></a>

| Topic                                                      | What to do                                                                                                                                                                                                                                                                                                                                                 |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--splitPreambleIntoFile`                                  | Angular apps set `<base href>`, so a relative `--preambleFileUrl` resolves against it and works on deep routes. If the app is served under a sub-path, make sure `<base href>` matches it, or pass a full URL.                                                                                                                                             |
| Lazy-loaded routes                                         | No extra setup: every chunk of the build reports to the same build session.                                                                                                                                                                                                                                                                                |
| Server-side rendering (Angular Universal / `@angular/ssr`) | Scan `dist/<app>/browser` with `--instrumentForBrowsers` and `dist/<app>/server` without it, each with its own `--moduleName`, like the [Next.js setup](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/advanced-features/next.js-with-sealights-node-and-browser-agents-multi-module-scan.md). |
| Content security policy                                    | Angular apps often ship a CSP. Allow the SeaLights or Collector host; see [Configuration → Content security policy](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/configuration.md#content-security-policy).                                                                                  |
| Angular unit tests (Karma)                                 | Captured separately with an NYC report; see [Karma Test Framework](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/capturing-tests/karma-test-framework.md).                                                                                                                                    |

## Check it <a href="#check" id="check"></a>

* Before CI: `npx slnodejs dryRun --scanDir dist/my-angular-app/browser --es6Modules --verbose --instrumentForBrowsers --tokenFile sltoken.txt` (drop `--es6Modules` for the webpack builder). `included-files.json` should list `main-*.js` and `chunk-*.js`, and `sl-mapping.json` should resolve to `src/app/...`.
* After deployment: [Check that it works](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/setting-up-browser-coverage.md#check-that-it-works).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/framework-setups/angular.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
