Skip to content

Improve custom Loader Script init flow #58428

@mydea

Description

@mydea

Currently, when using the Loader Script, you have to configure it like this:

<script src="... loader URL"></script>
<script>
Sentry.onLoad(function() {
  Sentry.init({ ... });
});
</script>

In order for this to work, we depend on very specific timing semantics - you have to call Sentry.onLoad after you added the loader script, but before the loader script fetched the CDN bundle.

In order to streamline this, I propose to add a new way to do this:

<script>
window.sentryOnLoad = function() {
  Sentry.init({ ... });
};
</script>

This could be configured either before or after the loader script tag, and we would pick it up in the loader, if configured, in addition to any Sentry.onLoad() callbacks.

Alternatively, we could also make it an array:

<script>
window.sentryOnLoad = window.sentryOnLoad || [];
window.sentryOnLoad.push(function() {
  Sentry.init({ ... });
});
</script>

This has the benefit of allowing multiple calls, but makes the setup a bit more complicated. I would personally vote for the first option, for simplicity - if you need multiple callbacks, you can still use Sentry.onLoad().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions