You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4fb766b
Browse filesBrowse the repository at this point in the historyBrowse files
Add `crossOrigin`, `onLoad` and `onLoadFailed` options to `IntercomProvider` to set the messenger `<script>` crossorigin attribute and detect when the messenger script loads or fails to load
Copy file name to clipboardExpand all lines: packages/react-use-intercom/README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,9 @@ Place the `IntercomProvider` as high as possible in your application. This will
91
91
| 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 ||
92
92
| initializeDelay | number | Indicates if the intercom initialization should be delayed, delay is in ms, defaults to 0. See https://github.com/devrnt/react-use-intercom/pull/236| false ||
93
93
| autoBootProps | IntercomProps | Pass properties to `boot` method when `autoBoot` is `true`| false ||
94
+
| crossOrigin | 'anonymous' \| 'use-credentials' \| '' | Sets the [`crossOrigin`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script#crossorigin) attribute on the Messenger `<script>` (standard DOM attribute, not an Intercom API). Use `'anonymous'` for full error details in error logging; works because Intercom's CDN allows CORS | false ||
95
+
| onLoad | () => void | triggered when the Messenger script has loaded successfully | false ||
96
+
| onLoadFailed | () => void | triggered when the Messenger script has failed to load (network issues, Intercom downtime, firewall, blocking browser extensions, ...) | false ||
94
97
95
98
#### Example
96
99
```ts
@@ -306,6 +309,24 @@ Since [v1.2.0](https://github.com/devrnt/react-use-intercom/releases/tag/v1.2.0)
306
309
307
310
For reference see https://github.com/devrnt/react-use-intercom/pull/236 and https://forum.intercom.com/s/question/0D52G00004WxWLs/can-i-delay-loading-intercom-on-my-site-to-reduce-the-js-load
308
311
312
+
### Detect a broken Messenger
313
+
314
+
The Messenger script can fail to load for various reasons, e.g. network issues, Intercom downtime, firewall rules, or browser extensions like tracking blockers.
315
+
316
+
Pass `onLoadFailed` to `<IntercomProvider />` to detect when that happens and offer the user an alternative support channel. Use `onLoad` to know when the script loaded successfully (e.g. to hide a loading state).
317
+
318
+
```tsx
319
+
<IntercomProvider
320
+
appId={INTERCOM_APP_ID}
321
+
onLoad={() =>console.log('Messenger loaded')}
322
+
onLoadFailed={() =>console.log('Messenger failed to load')}
323
+
>
324
+
...
325
+
</IntercomProvider>
326
+
```
327
+
328
+
Pass `crossOrigin="anonymous"` to unlock full error details for errors thrown by the Messenger loader script — a standard [`<script>` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script#crossorigin) rather than an Intercom feature. It works because Intercom's CDN serves the script with permissive CORS headers.
329
+
309
330
## Contributing
310
331
311
332
Contributions are welcome! Please read the [Contributing Guidelines](CONTRIBUTING.md) for details on how to contribute to the project.
0 commit comments