Skip to content

Commit 4ffac14

Browse files
Update messaging.html
1 parent da72a06 commit 4ffac14

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

godwin/sdb3/messaging.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ <h2>godwin@sdb3.org</h2>
6767
console.log("Received the onEmbeddedMessagingBusinessHoursEnded event…");
6868
console.log("Event detail: ", event.detail);
6969
});
70+
71+
// Listen for visibility changes
72+
document.addEventListener('visibilitychange', () => {
73+
if (document.visibilityState === 'hidden') {
74+
// Call the API when the page is hidden
75+
embeddedservice_bootstrap.userVerificationAPI
76+
.clearSession(true)
77+
.then(() => {
78+
// ✅ Success handling
79+
console.log('Session cleared successfully.');
80+
embeddedservice_bootstrap.utilAPI.removeAllComponents();
81+
console.log('Removed components successfully.');
82+
debugger;
83+
})
84+
.catch(error => {
85+
// ❌ Error handling
86+
console.error('Error clearing session:', error);
87+
})
88+
.finally(() => {
89+
// 🛡️ Code that should run regardless of outcome
90+
console.log('clearSession finished (success or error).');
91+
});
92+
}
93+
});
7094
</script>
7195
<script type='text/javascript'>
7296
function initEmbeddedMessaging() {

0 commit comments

Comments
 (0)