> 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/micro-frontends.md).

# Micro-frontends

> **Applies to:** pages composed of several separately built and deployed front ends: webpack or Rspack Module Federation, single-spa, import maps, iframes, or independently deployed script bundles.

## The rule <a href="#rule" id="rule"></a>

**Each separately built front end is its own SeaLights build**: its own `config` (its own application name), its own `scan --instrumentForBrowsers`, its own instrumented output. On the page, the Browser Agent runs one instance per build session and reports each build's coverage separately. Give all front ends that are tested together the **same lab ID**.

```
 shell (host)     config --appName shell      scan --instrumentForBrowsers --labId qa-env ─┐
 orders (remote)  config --appName orders     scan --instrumentForBrowsers --labId qa-env  ├─► one page, three agents, lab "qa-env"
 billing (remote) config --appName billing    scan --instrumentForBrowsers --labId qa-env ─┘
```

## Example: Module Federation host and remote <a href="#example" id="example"></a>

Run in each repository (or each package of a monorepo), after its own build:

```bash
# in the remote's pipeline
printf '%s' "$SEALIGHTS_AGENT_TOKEN" > sltoken.txt
npx slnodejs config --tokenFile sltoken.txt --appName orders-mfe \
  --branchName "$BRANCH_NAME" --buildName "$BUILD_NUMBER"
npx slnodejs scan --tokenFile sltoken.txt --buildSessionIdFile buildSessionId \
  --scanDir dist --scmType git \
  --instrumentForBrowsers --outputPath sl_dist --labId qa-env
# deploy sl_dist as the remote's files in the test environment

# in the host's pipeline: the same commands with --appName shell
```

Add `--es6Modules` for front ends whose output is ES modules.

## Notes <a href="#notes" id="notes"></a>

| Topic                                                | What to do                                                                                                                                                                                                                                                                                                                                                                                                |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Shared dependencies (React, Angular, Vue singletons) | They are skipped by default inside every bundle; no extra setup.                                                                                                                                                                                                                                                                                                                                          |
| One front end is instrumented, another is not        | Coverage is reported only for the instrumented one. That is fine during a gradual rollout.                                                                                                                                                                                                                                                                                                                |
| Same build loaded twice                              | A second configuration with a build session ID that is already running on the page is ignored.                                                                                                                                                                                                                                                                                                            |
| Context propagation to back ends                     | If any front end on the page is instrumented with `--enableOpenTelemetry`, propagation applies to every request from the page. With several `--allowCORS` values, the last build that sets one wins, so give every front end the same list. See [Context Propagation](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/context-propagation.md). |
| Several environments                                 | Instrument each front end once per environment with that environment's `--labId`, or set `window["__sl.labId__"]` in the host page, which applies to every build on the page. See [Configuration → Lab ID](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/browser-agent/configuration.md#lab-id).                                                           |
| One release made of all front ends                   | To report them as one release, create an [integration build](https://docs.sealights.io/knowledgebase/setup-and-configuration/build-and-test-execution/integration-build.md) with the front ends as components.                                                                                                                                                                                            |
| Front ends in iframes                                | Each iframe is its own page with its own agent instances; the same rules apply.                                                                                                                                                                                                                                                                                                                           |

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

On a page that loads several front ends, the console shows one `has been loaded` line per build, and `window.$SealightsAgent.dumpSlMappings()` returns one mapping per build. See [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/micro-frontends.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.
