Experience Lwc Runtime Observe

by forcedotcome5164d94d751No license1K starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated yesterday

Use when running Salesforce Lightning Preview for an app or a single LWC component to extract the runtime DOM for inspection. TRIGGER when the user says "preview an LWC locally", "run sf lightning dev", "launch Local Dev", "inspect a component's shadow DOM at runtime", "grab rendered HTML from a live preview", "troubleshoot what actually renders versus the template", "set up Salesforce Live Preview plugin", "lightning preview", "local dev server", or "extract runtime DOM". DO NOT TRIGGER when the user is authoring or editing LWC source code (use experience-lwc-generate) or reviewing component code statically without running it.

Includes scriptsSoftware Development
AI-generated overview

Runs a Salesforce Lightning Preview locally and extracts the rendered runtime DOM of an LWC app or component.

What it does
This skill guides an agent through starting a local Salesforce Lightning Preview session for an LWC app or component using the Salesforce CLI, then navigating to the preview URL with a browser-automation driver and extracting the rendered DOM subtree. It ships helper scripts that verify the toolchain, obtain an authenticated front-door URL without exposing the token, and compute selectors and wrap extracted HTML in output markers. The result is the runtime HTML of the component or app, including shadow-DOM content, for inspection or diffing.
When to use it
Use it when you want to preview an LWC app or component locally before deploying, or when you need the actual rendered HTML subtree at runtime for a diff, screenshot pipeline, or shadow-DOM reasoning. It is also meant for diagnosing why template content does not appear in the DOM. It is not for authoring or editing LWC source code or for static code review.
Requirements
Requires the Salesforce CLI (sf) with the @salesforce/plugin-lightning-dev plugin, an authenticated and Connected org alias, python3, and browser automation (Playwright, Puppeteer, or Chrome DevTools Protocol) in the agent harness. It ships executable scripts for toolchain verification, front-door URL retrieval, and DOM selector/wrapping operations.
<!-- adk-managed-skill -->

Previewing LWC Runtime — Local Dev + DOM Inspection

Guides the agent through two sequential jobs that typically run together:

  1. Start a Lightning Preview session with the Salesforce CLI so an LWC app or component renders in a local dev environment.
  2. Navigate to that preview URL and extract the runtime DOM subtree so the agent (or user) can reason about what actually rendered.

Preview is the prerequisite for DOM inspection. Keep them in this order.

When to Use This Skill

  • The user wants to preview an LWC app or component locally before deploying (sf lightning dev app / sf lightning dev component).
  • The user wants the rendered HTML subtree for a specific component at runtime — for a diff, a screenshot pipeline, or to reason about shadow DOM.
  • The user asks why the template content "isn't in the DOM" — almost always a shadow-DOM misunderstanding handled in Step 2.

Prerequisites

  • Salesforce CLI (sf) installed. Check with sf version.
  • @salesforce/plugin-lightning-dev installed. Check with sf plugins.
  • An authenticated org (sf org list shows at least one connected org).
  • For DOM extraction: browser automation available in the agent harness (Playwright, Puppeteer, Chrome DevTools Protocol — whatever is wired up).

Step 1 — Start the Lightning Preview

Ask the user (or infer from the request) whether the scope is app or component.

1a. Verify the toolchain

Ask the user for (or infer from the request) the org alias the preview should target. Run the bundled verification script with that alias and surface any error it emits — do not re-invoke sf version / sf plugins / sf org display in prose. The script checks CLI presence, @salesforce/plugin-lightning-dev installation, and that the specific target alias is authenticated and Connected, and exits nonzero with an actionable message on failure:

bash
"<skill_dir>/scripts/verify-toolchain.sh" <orgAlias>

If it reports that the target alias is not authenticated or not Connected, direct the user to Enable Local Dev and have them run sf org login web --alias <orgAlias>, then re-run the verification script before proceeding.

1b. Read the subcommand's flags

bash
# For app scopesf lightning dev app --help
# For component scopesf lightning dev component --help

Note required vs optional flags. If a required flag is ambiguous, ask the user before running.

1c. Launch the preview

Prefix every preview command with OPEN_BROWSER=false — the CLI opens a browser window by default, which we do not want when an agent is driving. (This env var is undocumented in --help; rely on it unless the user explicitly asks for a browser window.)

ScopeCommand
appOPEN_BROWSER=false sf lightning dev app -o <orgAlias> -n <appName> -t desktop
componentOPEN_BROWSER=false sf lightning dev component -o <orgAlias> -n <componentName>

When the preview is up, capture the URL and log it in exactly this format:

text
Lightning Preview running at URL: <URL>

If any sub-step fails, stop and surface the error to the user — don't try to paper over auth or plugin-install problems.


Step 2 — Extract the Runtime DOM

Only run this step once Step 1 has produced a live preview URL.

2a. Get an authenticated front-door URL — without surfacing the token to agent context

The front-door URL returned by sf org open --url-only --json contains a short-lived OTP that authenticates the session. Never run sf org open directly — its output would land in the agent tool-output stream and leak an auth token into the transcript, violating agent-safety standard S1. The bundled helper is the only supported way to obtain the URL: it runs sf org open internally with stdout redirected into a chmod 600 tempfile and stderr suppressed, so no URL fragment or token substring ever reaches agent context.

Instead, use the bundled helper script, which writes the URL to a chmod 600 tempfile and prints only export assignments (no token material). Capture the helper output first so a nonzero exit status aborts the caller — eval "$(...)" alone masks failures, letting the agent proceed with an unset $FRONTDOOR_URL_FILE:

bash
frontdoor_env="$("<skill_dir>/scripts/open-frontdoor.sh" <orgAlias> <previewUrl>)" || exit 1eval "$frontdoor_env"

The helper suppresses sf and python3 stderr as well as stdout, so partial URLs and progress noise never reach the agent transcript.

The browser driver must:

  1. Read the URL from $FRONTDOOR_URL_FILE.
  2. Navigate to it to establish a session.
  3. Delete the tempfile immediately after use.
  4. Never cat or otherwise echo the file contents.

OTP tokens expire fast. Bring up the browser driver first, then invoke the helper just before navigating — otherwise the token goes stale.

2b. Navigate and wait

  1. Open the preview URL from Step 1 in the automation browser.
  2. Wait for the network to go idle and the initial render to complete.
  3. If the expected element isn't there, back off briefly and retry before declaring failure — local dev pages sometimes hydrate in two phases.

2c. Extract the subtree

Two deterministic string operations — turning a component name into its c-<kebab> selector and wrapping the extracted HTML in the exact DOM_OUTPUT_START / DOM_OUTPUT_END markers — are handled by <skill_dir>/scripts/extract-dom.sh. Do NOT re-derive the selector or compose the markers in prose; call the script.

Actual DOM traversal must be run by the browser-automation driver (Playwright / Puppeteer / CDP); the script does not drive the browser.

If scope is component

Compute the selector deterministically:

bash
selector="$("<skill_dir>/scripts/extract-dom.sh" selector <componentName>)"

Then, using the driver, pierce the lwr_dev-preview-container shadow root, locate the first visible element matching $selector, and read its subtree HTML (via element.shadowRoot.innerHTML). Pipe that HTML into the wrap step:

bash
printf '%s' "$html_subtree" \  | "<skill_dir>/scripts/extract-dom.sh" wrap component <componentName>
If scope is app

Using the driver, identify the primary app root (prefer document.body or the main app container — not document.documentElement), exclude <head> and non-rendered nodes, and read the subtree HTML. Pipe it into the wrap step:

bash
printf '%s' "$html_subtree" \  | "<skill_dir>/scripts/extract-dom.sh" wrap app

Emit the script's stdout unchanged as the DOM output.

2d. About LWC Shadow DOM (the #1 gotcha)

Lightning Web Components use Shadow DOM. The template content is not directly queryable on the host element:

Access patternWhat you get
element.innerHTMLempty, or only slotted light-DOM content
element.outerHTMLjust the host tag, no children
element.shadowRoot.innerHTMLthe real rendered template content

If the browser driver's DOM query doesn't pierce shadow roots by default, walk shadowRoot explicitly. Most modern automation drivers have a shadow-piercing query helper — use it.


Examples

For a worked end-to-end example (preview a component, capture the front-door URL safely, and extract its DOM), load examples/component-preview-and-dom.md [blocked].


Verification Checklist

  • <skill_dir>/scripts/verify-toolchain.sh <orgAlias> exited zero for the target alias.
  • Preview command ran with OPEN_BROWSER=false.
  • Preview URL logged in the Lightning Preview running at URL: <URL> format.
  • Front-door URL fetched via <skill_dir>/scripts/open-frontdoor.sh (never sf org open directly).
  • DOM extraction used shadowRoot traversal (not innerHTML on the host).
  • DOM output was produced by <skill_dir>/scripts/extract-dom.sh wrap … (script owns the markers).

Troubleshooting

  • verify-toolchain.sh reports "Target org alias is not authenticated or not Connected" — run sf org login web --alias <orgAlias> (the alias must match the one you passed to verify-toolchain.sh and the -o value the preview command uses).
  • verify-toolchain.sh reports the plugin is missing — install it with sf plugins install @salesforce/plugin-lightning-dev.
  • Preview opens a browser window — you forgot OPEN_BROWSER=false.
  • Empty DOM on extraction — you're looking at innerHTML on a host. Use element.shadowRoot.innerHTML instead. Also verify you pierced the lwr_dev-preview-container shadow root.
  • Front-door token fails — it's expired. Re-invoke <skill_dir>/scripts/open-frontdoor.sh and navigate within ~60 seconds.

Source and attribution

Source:forcedotcom/sf-skillsinskills/experience-lwc-runtime-observeat commite5164d9

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal

More from forcedotcom/sf-skills

Service Itsm Teams Itservice Configure

forcedotcom

Configure the "Set Up Salesforce IT Service" checklist for Microsoft Teams Employee Service (ITSM) — the employee side, covering app enablement, marketplace install guidance, user access assignment, and Digital Experience Site selection. Use this for: 'turn on Salesforce IT Service', 'set up IT Service on Teams', 'assign Teams for Employee permission set', 'give employees access to Teams for Employee Service', 'manage user access for Teams ITSM', 'grant users the permission sets needed for Teams Employee Service', 'select a digital experience site for Teams', 'install Salesforce IT Service app on Teams', or any request to complete the IT Service half of the Teams ITSM Go page checklist (including the Manage User Access step). DO NOT TRIGGER for the base Teams Salesforce Go page toggle or Azure/Entra app setup (service-itsm-teams-configure) or for the IT Desk/fulfiller half of the checklist (service-itsm-teams-itdesk-configure).

Awaiting classification1Kupdated yesterday

Service Itsm Teams Coordinate

forcedotcom

End-to-end autopilot orchestrator for setting up Microsoft Teams integration in Salesforce Service Cloud ITSM — runs the whole flow (enable the Teams for Employee Service Go feature, register the Microsoft Entra app, populate Named Credentials, configure the IT Desk and IT Service checklists, turn on Swarming, and optionally embed the Agentforce agent) in one continuous pass, stopping only at the points a human must act. Use when the user asks to set up Microsoft Teams for ITSM end to end, 'set up teams for it service', 'do the whole teams itsm setup', 'configure microsoft teams for employee service', or wants a guided Teams ITSM walkthrough. Delegates each stage to a specialized child skill while driving the sequence itself. DO NOT TRIGGER when the user asks to enable Teams alone, configure just the IT Desk or IT Service checklist alone, or enable Swarming alone — delegate directly to the specific child skill in those cases.

Awaiting classification1Kupdated yesterday

Service Itsm Teams Itdesk Configure

forcedotcom

Configure the "Set Up Salesforce IT Desk" checklist for Microsoft Teams Employee Service (ITSM) — the fulfiller/agent side, covering app enablement, marketplace install guidance, user access assignment, and Swarming collaboration-tool setup. Use this for: 'turn on Salesforce IT Desk', 'set up IT Desk on Teams', 'assign Teams for IT Desk permission set', 'set Teams as collaboration tool for swarming', 'install Salesforce IT Desk app on Teams', or any request to complete the IT Desk half of the Teams ITSM Go page checklist. DO NOT TRIGGER for the base Teams Salesforce Go page toggle or Azure/Entra app setup (service-itsm-teams-configure) or for the IT Service/employee half of the checklist (service-itsm-teams-itservice-configure).

Awaiting classification1Kupdated yesterday

Service Itsm Teams Debug

forcedotcom

Diagnoses failing Microsoft Teams for Employee Service (ITSM) setups by running pass/fail configuration checklists against a Salesforce org.

DevOps & Cloud1Kupdated yesterday

Service Itsm Teams Employee Agent Configure

forcedotcom

Configure the embedded Agentforce Employee Agent so it replies inside the Microsoft Teams ITSM custom client ('Salesforce Employee Assist' / 'Ask AI Agent'). Use this for: 'set up employee agent in Teams', 'embed Agentforce agent in Teams', 'make the IT Service Employee Agent reply in Teams', 'Teams Ask AI Agent not responding', 'agent joins then leaves without replying', 'configure MIAW deployment for Teams employee agent', 'Teams embedded messaging agent setup'. Builds the whole stack headlessly (zero Setup-UI clicks): the Web messaging channel with User Verification ON, the Enhanced Chat User Verification Key Set (JWKS_URL) it requires, the Teams_AgentForce custom-client deployment, the routing flow to the agent, and the Agent Access permission set that lets the portal user reach the agent. DO NOT TRIGGER for enabling the Teams feature Salesforce Go page toggle (service-itsm-teams-configure) or for configuring notification preferences.

Awaiting classification1Kupdated yesterday

Service Itsm Swarming Configure

forcedotcom

Enables the Salesforce Swarming ITSM feature and sets the collaboration tool to Teams via Connect API calls.

DevOps & Cloud1Kupdated yesterday