Hey Botpress Community,
I'm struggling to integrate the v1 webchat script into a React 19 application built with Vite and I'm hoping someone might have encountered this or has insights.
Goal: Embed the v1 webchat using the standard inject.js and the bot-specific configuration script (from the Botpress share/configure section), and have the chat widget open automatically when the page loads.
Environment:
React: 19.1.0
Vite: 6.3.1
Botpress Webchat: v1 inject script (
https://cdn.botpress.cloud/webchat/v1/inject.js) + the generated config script (
https://files.bpcontent.cloud/...js)
Note: I initially tried the @botpress/webchat npm package (v1.6.1 according to npm audit), but ran into issues with missing exports (WebchatProvider) and potential incompatibility with React 19. I've since removed all React component code for Botpress.
Problem:
The core issue seems to be a timing problem where the configuration script (which calls window.botpress.init(...)) executes before the main inject.js script has fully initialized the window.botpress object. This results in the error:
Uncaught TypeError: window.botpress is undefined
at
(
https://files.bpcontent.cloud/...)
This happens even when using various script loading strategies. The widget either fails to load entirely or shows a non-functional icon.
What I've Tried (Inject Script Method):
Placing both inject.js and the config script (...7PMMSRBX.js) at the end of
with/without defer.
Placing both scripts in the
with/without defer.
Loading inject.js first, then using its onload to dynamically load the config script.
Loading inject.js, then using an inline script with DOMContentLoaded to manually call window.botpress.init() with the config object extracted from the config script.
Loading inject.js, then using an inline script to poll (setInterval/setTimeout) until window.botpress.init exists before calling it with the config object.
Adding a separate script block to listen for webchat:ready and call window.botpress.open(), both with and without the polling logic for init.
Questions:
Is there a known timing issue or specific technique required for the v1 inject.js script within a Vite development server environment (especially with React 19)?
What is the most reliable way to ensure window.botpress (and its methods like init, on, open) are fully available before attempting to use them when loading via script tags in an SPA?
Is there any configuration within the init object itself that forces auto-open for v1, or is the webchat:ready -> open() pattern the correct way (once window.botpress is reliably defined)?
Any help or pointers would be greatly appreciated! Happy to provide more details (like vite.config.js or package.json) if needed.
Thanks!