Skip to content

Commit 958c209

Browse files
committed
fix: add error logging to widget component
1 parent ffef6b3 commit 958c209

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

snippets/widget.mdx

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,56 @@
1-
export const KnowrithmWidget = () => {
2-
if (typeof window !== 'undefined') {
3-
// Only run on client side
4-
React.useEffect(() => {
5-
// Prevent duplicate loads
6-
if (window.__knowrithmWidgetLoaded) return;
7-
window.__knowrithmWidgetLoaded = true;
1+
export function KnowrithmWidget() {
2+
if (typeof window === 'undefined') return null;
3+
4+
React.useEffect(() => {
5+
if (window.__knowrithmWidgetLoaded) return;
6+
window.__knowrithmWidgetLoaded = true;
87

9-
// Set widget configuration
10-
window.AIChatWidget = {
11-
agentId: "2b041b45-a585-47e9-abaf-ebaad766bce9",
12-
apiUrl: "https://app.knowrithm.org/api/v1",
13-
color: "#0972A3",
14-
position: "right",
15-
appearance: {
16-
theme: "light",
17-
primaryColor: "#0972A3",
18-
placement: "bottom-right",
19-
buttonText: "Chat with us",
20-
showBranding: true
21-
},
22-
behavior: {
23-
autoOpen: false,
24-
initialDelay: 0,
25-
persistSession: true,
26-
pollingInterval: 10000,
27-
enableSounds: false
28-
},
29-
callbacks: {
30-
onLoad: null,
31-
onError: null,
32-
onMessage: null,
33-
onClose: null
34-
},
35-
assets: {
36-
scriptUrl: "https://app.knowrithm.org/api/widget.js",
37-
styleUrl: "https://minio.knowrithm.org/browser/knowrithm-bucket/chat-widget.css"
38-
}
39-
};
8+
window.AIChatWidget = {
9+
agentId: "2b041b45-a585-47e9-abaf-ebaad766bce9",
10+
apiUrl: "https://app.knowrithm.org/api/v1",
11+
color: "#0972A3",
12+
position: "right",
13+
appearance: {
14+
theme: "light",
15+
primaryColor: "#0972A3",
16+
placement: "bottom-right",
17+
buttonText: "Chat with us",
18+
showBranding: true
19+
},
20+
behavior: {
21+
autoOpen: false,
22+
initialDelay: 0,
23+
persistSession: true,
24+
pollingInterval: 10000,
25+
enableSounds: false
26+
},
27+
callbacks: {
28+
onLoad: null,
29+
onError: null,
30+
onMessage: null,
31+
onClose: null
32+
},
33+
assets: {
34+
scriptUrl: "https://app.knowrithm.org/api/widget.js",
35+
styleUrl: "https://minio.knowrithm.org/browser/knowrithm-bucket/chat-widget.css"
36+
}
37+
};
4038

41-
// Load the widget script
42-
const script = document.createElement('script');
43-
script.src = 'https://app.knowrithm.org/api/widget.js';
44-
script.type = 'text/javascript';
45-
script.async = true;
46-
document.head.appendChild(script);
39+
const script = document.createElement('script');
40+
script.src = 'https://app.knowrithm.org/api/widget.js';
41+
script.type = 'text/javascript';
42+
script.async = true;
43+
script.onload = () => console.log('Knowrithm widget loaded');
44+
script.onerror = (e) => console.error('Failed to load Knowrithm widget:', e);
45+
document.head.appendChild(script);
4746

48-
// Load the widget CSS
49-
const link = document.createElement('link');
50-
link.rel = 'stylesheet';
51-
link.href = 'https://minio.knowrithm.org/browser/knowrithm-bucket/chat-widget.css';
52-
document.head.appendChild(link);
53-
}, []);
54-
}
47+
const link = document.createElement('link');
48+
link.rel = 'stylesheet';
49+
link.href = 'https://minio.knowrithm.org/browser/knowrithm-bucket/chat-widget.css';
50+
document.head.appendChild(link);
51+
}, []);
5552

5653
return null;
57-
};
54+
}
5855

5956
<KnowrithmWidget />

0 commit comments

Comments
 (0)