When using the ESM bundle of @cognigy/webchat, calling webchat.endSession() throws a ReferenceError due to what appears to be a minification/bundling issue with the self.crypto.randomUUID() reference.
Version
@cognigy/webchat/v/3.30.1
Reproduction
- Import the webchat using the ESM bundle
- Initialize the webchat
- Call webchat.endSession()
Expected behaviour
The session should end and a new session ID should be generated.
Actual behaviour
ReferenceError: b is not defined
The error originates from the bundled code where self.crypto.randomUUID() appears to have been incorrectly minified/tree-shaken.
Workaround
The endSession() behavior can seemingly be replicated by dispatching the underlying Redux actions directly:
webchat.store.dispatch({
type: "SWITCH_SESSION",
sessionId: crypto.randomUUID(),
});
webchat.store.dispatch({ type: "CLEAR_MESSAGES" });
This bypasses the broken bundled code by calling the browser's native crypto.randomUUID() directly.