1+ const WIDGET_TAG = 'vapi-voice-agent-widget' ;
2+ const isLocalhost = window . location . hostname === 'localhost' || window . location . hostname === '127.0.0.1' ;
3+ const WIDGET_SCRIPT_URL = isLocalhost
4+ ? 'http://localhost:9001/widget.js'
5+ : 'https://docs-widget.vercel.app/widget.js' ;
6+
7+ function injectVapiWidget ( ) {
8+ console . log ( '[custom.js] injectVapiWidget called' ) ;
9+ if ( document . querySelector ( WIDGET_TAG ) ) {
10+ console . log ( '[custom.js] Widget already present in DOM' ) ;
11+ return ;
12+ }
13+
14+ const script = document . createElement ( 'script' ) ;
15+ script . src = WIDGET_SCRIPT_URL ;
16+ script . async = true ;
17+ script . onload = ( ) => {
18+ console . log ( '[custom.js] Widget script loaded' ) ;
19+ // Create the web component after the script loads
20+ const widget = document . createElement ( WIDGET_TAG ) ;
21+ const apiKey = '6d46661c-2dce-4032-b62d-64c151a14e0d' ;
22+ widget . setAttribute ( 'apiKey' , apiKey ) ;
23+ widget . style . position = 'fixed' ;
24+ widget . style . bottom = '0' ;
25+ widget . style . right = '0' ;
26+ widget . style . zIndex = '9999' ;
27+ document . body . appendChild ( widget ) ;
28+ console . log ( '[custom.js] Widget element appended to DOM' ) ;
29+ } ;
30+ document . body . appendChild ( script ) ;
31+ console . log ( '[custom.js] Widget script appended to DOM' ) ;
32+ }
33+
34+ if ( document . readyState === 'loading' ) {
35+ console . log ( '[custom.js] Waiting for DOMContentLoaded' ) ;
36+ document . addEventListener ( 'DOMContentLoaded' , injectVapiWidget ) ;
37+ } else {
38+ injectVapiWidget ( ) ;
39+ }
0 commit comments