Skip to content

Handle Experience Builder and preview environments gracefully#9

Merged
josecdiaz merged 2 commits intosalesforce:mainfrom
dominic-butlerSFDC:fix/preview-environment-handling
Apr 27, 2026
Merged

Handle Experience Builder and preview environments gracefully#9
josecdiaz merged 2 commits intosalesforce:mainfrom
dominic-butlerSFDC:fix/preview-environment-handling

Conversation

@dominic-butlerSFDC
Copy link
Copy Markdown
Member

Salesforce's own CORS and CSP policies block the Embedded Service bootstrap script and SCRT configuration API from preview domains (*.salesforce-experience.com), making the component non-functional in builder and preview environments. Rather than failing silently or flooding the console with errors, the component now detects these environments on mount and shows a clear informational message: "Chat is not available in the Experience Builder or preview environments. To test this component, publish the site and visit the published URL."

Changes:

  • Add PREVIEW_ERROR_MSG constant and _isPreviewError flag
  • Guard connectedCallback and handleSubmit against preview domains
  • Anchor _isSitePreview() to *.salesforce-experience.com subdomains to avoid false positives on customer-owned domains
  • Hide the "Try again" button for preview errors (retrying won't help)
  • Update script.onerror fallback to use the same constant and flag
  • Add Troubleshooting entry to README explaining the behaviour
  • Set haaSkeletonLoader isExposed to false and remove targets block

Salesforce's own CORS and CSP policies block the Embedded Service
bootstrap script and SCRT configuration API from preview domains
(*.salesforce-experience.com), making the component non-functional
in builder and preview environments. Rather than failing silently or
flooding the console with errors, the component now detects these
environments on mount and shows a clear informational message:
"Chat is not available in the Experience Builder or preview
environments. To test this component, publish the site and visit
the published URL."

Changes:
- Add PREVIEW_ERROR_MSG constant and _isPreviewError flag
- Guard connectedCallback and handleSubmit against preview domains
- Anchor _isSitePreview() to *.salesforce-experience.com subdomains
  to avoid false positives on customer-owned domains
- Hide the "Try again" button for preview errors (retrying won't help)
- Update script.onerror fallback to use the same constant and flag
- Add Troubleshooting entry to README explaining the behaviour
- Set haaSkeletonLoader isExposed to false and remove targets block

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@salesforce-cla
Copy link
Copy Markdown

Thanks for the contribution! It looks like @dominic-butlerSFDC is an internal user so signing the CLA is not required. However, we need to confirm this.

@dominic-butlerSFDC
Copy link
Copy Markdown
Member Author

I have signed the Salesforce CLA

Copy link
Copy Markdown
Member

@josecdiaz josecdiaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still a few minor changes and the PR must be submitted from a Github authoring user.

Comment thread force-app/main/default/lwc/haaInlineEnhancedChat/haaInlineEnhancedChat.js Outdated
Comment thread force-app/main/default/lwc/haaInlineEnhancedChat/haaInlineEnhancedChat.js Outdated
Moves the Experience Builder/preview error message out of a hardcoded
constant and into a new custom label (HAA_error_previewEnvironment) so
it can be translated and customised like all other component messages.
Bumps version to v1.04.

Updates component README to reflect the new label, correct the error
variant count, replace the stale "Known Issues" CORS entry with an
accurate description of the intentional preview environment handling,
and note that "Try again" is hidden for preview errors. Updates the
root README Customization section to call out the new label.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@dominic-butlerSFDC
Copy link
Copy Markdown
Member Author

Comments addressed.

@josecdiaz josecdiaz merged commit 420210c into salesforce:main Apr 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants