Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added crossOrigin, onLoad, and onLoadFailed config options #675

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fluidsonic
Copy link

  • crossOrigin: "anonymous" forces CORS when loading the Messenger script (<script crossOrigin="anonymous" …>). That in turn allows the website/app to receive full error information if the Messenger script throws an error. That's important for error logging and follow-ups with Intercom's own support.
  • onLoad and onLoadFailed are called when the Messenger script is loaded successfully or not loaded successfully. That allows for
    • showing a pending/loading animation while the chat is loading
    • showing alternative means of communication in case the Messenger can't be loaded (network issues, Intercom downtime, firewall, browser extensions that block Intercom, etc.)
  • README and Cypress tests are updated accordingly
<IntercomProvider
    
    crossOrigin="anonymous"
    onLoad={() => console.log("Loaded!")}
    onLoadFailed={() => console.log("Failed to load!")}
>

Copy link

changeset-bot bot commented Jun 11, 2024

🦋 Changeset detected

Latest commit: e7954c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-use-intercom Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Owner

@devrnt devrnt left a comment

Choose a reason for hiding this comment

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

Big thanks for all the work you did.

I've already quickly gone through your code. At this moment I can't tell yet when I'll do a thorough sweep and release it.

Can you also provide me some reference(s) where the (official) Intercom docs/forum mentions setting the crossorigin attribute?

@@ -91,6 +91,9 @@ Place the `IntercomProvider` as high as possible in your application. This will
| apiBase | string | If you need to route your Messenger requests through a different endpoint than the default. Generally speaking, this is not needed.<br/> Format: `https://${INTERCOM_APP_ID}.intercom-messenger.com` (See: [https://github.com/devrnt/react-use-intercom/pull/96](https://github.com/devrnt/react-use-intercom/pull/96)) | false | |
Copy link
Owner

Choose a reason for hiding this comment

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

Can you also copy and paste this in the other README?

@@ -26,9 +35,21 @@ const initialize = (appId: string, timeout = 0) => {
var l = function () {
setTimeout(function () {
var s = d.createElement('script');
s.crossOrigin = crossOrigin;
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
s.crossOrigin = crossOrigin;
s.crossorigin = crossOrigin;

s.type = 'text/javascript';
s.async = true;
s.src = 'https://widget.intercom.io/widget/' + appId;
if (onLoad) {
s.addEventListener('load', () => {
onLoad();
Copy link
Owner

Choose a reason for hiding this comment

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

This can be undefined right?

if (onLoadFailed) {
s.addEventListener('error', () => {
// No need to pass any information from the ErrorEvent because it will contain no information about the error.
onLoadFailed();
Copy link
Owner

Choose a reason for hiding this comment

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

This can be also be undefined right?

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.

None yet

2 participants