Skip to content

fix(widget): capture document.currentScript before DOMContentLoaded (#676)#1054

Open
vianmora wants to merge 1 commit intoHiEventsDev:developfrom
vianmora:fix/widget-currentscript-null
Open

fix(widget): capture document.currentScript before DOMContentLoaded (#676)#1054
vianmora wants to merge 1 commit intoHiEventsDev:developfrom
vianmora:fix/widget-currentscript-null

Conversation

@vianmora
Copy link

@vianmora vianmora commented Feb 25, 2026

Problem

When widget.js is loaded in without async, the browser executes the script while the DOM is still parsing (readyState === 'loading'). The IIFE registers a DOMContentLoaded listener and returns. By the time that listener fires, document.currentScript is null, causing a silent crash: Uncaught TypeError: Cannot read properties of null (reading 'src')

=> The widget never renders.

Fix

Capture document.currentScript at IIFE invocation time and pass it as a parameter. The reference remains valid regardless of when loadWidget() is eventually called. No need to put the script in head, you can now put it wherever you want in the body.

I think it can also resolve #676

Checklist

  • I have read the contributing guidelines.
  • My code is of good quality and follows the coding standards of the project.
  • I have tested my changes, and they work as expected.

…ContentLoaded listener. By the time the listener fires, document.currentScript is null, causing a crash. Capturing the reference at IIFE invocation time fixes the issue regardless of script placement or loading strategy.
@vianmora vianmora force-pushed the fix/widget-currentscript-null branch from d04d693 to ce9488b Compare February 25, 2026 18:16
@vianmora
Copy link
Author

I see that this PR fix actually the same issue : #677
So tell me ;)

@vianmora vianmora changed the title fix(widget): capture document.currentScript before DOMContentLoaded fix(widget): capture document.currentScript before DOMContentLoaded (#676) Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Widget Embed Browser Compatibility

1 participant