Skip to content

No guards on SDK execution #15545

Description

@sakashimaa

Describe the bug

window.$chatwoot creating cynchronously in chatwootSDK.run() - with all methods and hasLoaded: false, app may count that SDK is ready and start to use his methods like toggleBubbleVisiblity (entrypoints/sdk.js#87-102). However, SDK may be not ready, because DOM of bubble creating way later than this - inside IFRameHelper.onLoad (sdk/IFrameHelper.js#156-193) which is triggered by postMessage in onLoad. Toggle visiblity never checks querySelector result. In result we have two scenarios of error (had been spotted inside real application):

  • user returned back on the page with this sdk, tag of the script is inside DOM, $chatwoot here, but iframe is not ready -> .woot-bubble-holder === null
  • user exiting the page earlier than widget loaded -> addClasses fails with fatal error (can't access property 'e', classList is null)

To Reproduce

  1. create app that uses sdk and count on $chatwoot
  2. try to leave page just when you visited it in browser

Expected behavior

No response

Environment

Linux VM

Cloud Provider

None

Platform

Browser

Operating system

Windows

Browser and version

Zen Browser 1.21.15b

Docker (if applicable)

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is not working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions