Skip to content

fix(useScriptTag): convert Event to Error in promise rejection#184

Merged
childrentime merged 2 commits intomainfrom
fix/useScriptTag-error-handling
Jan 4, 2026
Merged

fix(useScriptTag): convert Event to Error in promise rejection#184
childrentime merged 2 commits intomainfrom
fix/useScriptTag-error-handling

Conversation

@childrentime
Copy link
Owner

Problem

Certain sites reject errors with an Event object, not an Error. This causes issues with global uncaught exception handlers that expect Error objects, resulting in confusing error messages like "Event Event (type=error) captured as promise rejection" when a script load is interrupted.

Solution

  • Convert Event objects to proper Error objects before rejecting the promise
  • Preserve the original event for debugging purposes via error.event property
  • Provide meaningful error messages that include the script source URL
  • Set appropriate error names (ScriptLoadError and ScriptLoadAbortError)

Changes

  • Updated error and abort event handlers in useScriptTag to create Error objects
  • Updated version to 6.1.7

Testing

  • No linting errors
  • Maintains backward compatibility (original event accessible via error.event)

Certain sites reject errors with an Event object, not an Error. This causes issues with global uncaught exception handlers that expect Error objects, resulting in confusing error messages like 'Event Event (type=error) captured as promise rejection'.

This fix converts Event objects to proper Error objects before rejecting the promise, while preserving the original event for debugging purposes via error.event property.
@childrentime childrentime merged commit 77cbe7c into main Jan 4, 2026
4 checks passed
@childrentime childrentime deleted the fix/useScriptTag-error-handling branch January 4, 2026 06:20
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.

1 participant