Skip to content

CDN/browser bundle script-tag initialization did not work, but ESM import did #41

@Quitoboss

Description

@Quitoboss

Hi, I found an issue with the browser/widget integration.

Setup

  • Widget package: @chatcops/widget@0.3.0
  • Using the CDN browser build in a plain HTML page
  • Inline mode

Actual behavior

Using the script-tag/CDN approach did not initialize the widget correctly in my tests.

This did not work reliably:

<script
  src="https://cdn.jsdelivr.net/npm/@chatcops/widget@0.3.0/dist/chatcops.min.js"
  data-api-url="https://apis.makeonweb.es/chat"
  data-mode="inline"
  data-container="#digacibot-chat"
></script>

Also, trying to initialize from the global object with:

window.ChatCops.init(...)
resulted in:

Uncaught TypeError: window.ChatCops.init is not a function

What did work

Using the ESM build with manual init worked:

<script type="module">
  import ChatCops from 'https://cdn.jsdelivr.net/npm/@chatcops/widget@0.3.0/dist/chatcops.esm.js';

  ChatCops.init({
    apiUrl: 'https://apis.makeonweb.es/chat',
    mode: 'inline',
    container: '#digacibot-chat'
  });
</script>

Expected behavior

At least one of these should work consistently:

  • script-tag auto init via data-*
  • global browser API via window.ChatCops.init(...)

Notes

I am not fully sure whether the root cause is:

  • the auto-init logic
  • the IIFE/global export shape
  • or both

But the behavior difference between the CDN script-tag path and the ESM import path seems reproducible.

It may be worth checking:

  • the browser IIFE export shape
  • the auto-init logic used with data-*
  • the documentation examples for browser/CDN usage

Thanks and best regards from Spain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions