Browser SDK 2 initialization error "null is not an object"
Expected Behavior
The Browser SDK should load reliably on Safari.
Current Behavior
When loading my site with Amplitude's Browser SDK 2 on Safari, I get the error:
null is not an object (evaluating 'a.args[f]._STUBBED_PLUGIN_NAME')
This prevents all events from being sent for that session. This seems to be happen most often in Safari, and it happens at random. It also happens more often if I use the Safari browser cache between refreshes.
I've yet to be able to reproduce this on Chrome.
Steps to Reproduce
I am using the following code to load Amplitude SDK:
<head>
...
<!-- Start Amplitude -->
<script type="text/javascript" src="https://cdn.amplitude.com/script/<%= amplitudeAppId %>.js"></script>
<script type="text/javascript">
window.amplitude.init(
"<%= amplitudeAppId %>",
{
optOut: true,
minIdLength: 1,
autocapture: {
attribution: true,
sessions: true,
pageViews: false,
formInteractions: false,
fileDownloads: false,
elementInteractions: false,
},
},
);
</script>
<!-- End Amplitude -->
...
</head>
NOTE: the optOut true is intentional as it is set manually later after cookie consent. The main issue here is that the SDK itself fails to load.
Environment
- JS SDK Version: latest (i.e.
<script type="text/javascript" src="https://cdn.amplitude.com/script/<%= amplitudeAppId %>.js"></script>) - Installation Method: script
- Browser and Version: Safari 14.0.2
@dhruvg, it should be fixed. Could you check again?
Still happening. If I open my site on Safari and refresh 10 times with console open. One or two times, this error will be thrown. Probably some race condition. Please advise.
Could you provide the url of your website so that I can reproduce?
Could you clear cache and try again? Scripts are stored in cache as well.
I cleared the cache. website is https://booksirens.com
I'm testing on Safari 14.0.2 on Big Sur 11.1
@dhruvg We weren't able to reproduce in Safari v18.1 on our side and we don't have access to Safari 14.0.2. Can you provide another set screenshots of the errors seen and where does the error occur in code? If you have access to a newer Safari, can you verify that it doesn't happen there?
Unfortunately, I don't have access to the latest Safari but you can see the error in my original post
Let me know if you had something specific in mind that those screenshots don't provide.
@dhruvg We made some update to the script. The error location should be different now. We would like to know the new location where the error occurs, even if it's the same error. Thanks.
Sorry, but I also no longer have access to Safari 14.02. Closing.