window.median. This guide explains how the sandbox works, how to work around its constraints reliably, and how to configure your Salesforce org and Median app for correct mobile rendering.
This is part two of a four-part series:
- Getting started with Salesforce Experience Cloud
- Lightning Web Components and the JavaScript Bridge (this page)
- Deep linking for Salesforce Experience Cloud
- Salesforce LWC component deployment and reference
Step 4: Resolve Lightning Web Security sandbox constraints
Lightning Web Components run inside a sandboxed JavaScript environment called Lightning Web Security (LWS), or its predecessor Lightning Locker. This sandbox prevents components from accessing global variables outside their own namespace. The practical effect for Median integrations is that a naive call towindow.median inside an LWC will return undefined, even when the bridge has been injected correctly by the native shell.
Recommended pattern for bridge access
Always access the bridge through the top-level window reference rather than the component’s localwindow reference:
window.median and window.Median are included to handle casing differences across Median SDK versions.
Checking for LWS vs legacy locker
LWS provides broader support for cross-window communication than the legacy Locker Service and is the preferred sandbox for new orgs. To confirm which sandbox your org is using, navigate to Setup > Session Settings and look for the Lightning Web Security toggle. Enable LWS if it is not already active and your org supports it.Detecting whether the page is running inside the Median app
Always guard bridge calls with a presence check before invoking any native feature. This ensures the component degrades gracefully when loaded in a desktop browser, Experience Builder preview, or any context outside the Median native shell.gonativeio/median-salesforce-components
Loading repository data...
Troubleshooting: window.median is undefined inside an LWC
If the bridge is not reachable after applying the pattern above, verify the following:
- LWS is enabled in Setup > Session Settings.
- The CSP is set to Relaxed in Experience Builder > Settings > Security and Privacy (see Getting started with Salesforce Experience Cloud).
- You are accessing the bridge via
window.medianusing theget _median()accessor pattern, not a localwindowreference. - You are testing on a physical device inside the Median app, not in Experience Builder preview, which does not inject the bridge.
Step 5: Configure a mobile-aware user agent
Salesforce detects the browser type from the User Agent string to determine which resources to serve. If the Median app sends a generic WebView User Agent, Salesforce may serve the desktop layout of your Experience Cloud site, which produces a degraded mobile experience. To configure a custom User Agent in Median App Studio:- In your app settings, navigate to Web Overrides > User Agent.
- Append a custom identifier such as
medianto the existing User Agent string. Do not replace the full User Agent string, as Salesforce uses parts of it to identify the browser engine.

App Studio: user agent configuration