Amplitude-TypeScript icon indicating copy to clipboard operation
Amplitude-TypeScript copied to clipboard

Browser SDK 2 initialization error "null is not an object"

Open rozumem opened this issue 10 months ago • 8 comments

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')

Image

Image

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

rozumem avatar Feb 10 '25 05:02 rozumem

@dhruvg, it should be fixed. Could you check again?

Mercy811 avatar Feb 10 '25 23:02 Mercy811

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.

rozumem avatar Feb 11 '25 02:02 rozumem

Could you provide the url of your website so that I can reproduce?

Mercy811 avatar Feb 11 '25 02:02 Mercy811

Could you clear cache and try again? Scripts are stored in cache as well.

Mercy811 avatar Feb 11 '25 02:02 Mercy811

I cleared the cache. website is https://booksirens.com

I'm testing on Safari 14.0.2 on Big Sur 11.1

rozumem avatar Feb 11 '25 09:02 rozumem

@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?

zhukaihan avatar Feb 26 '25 23:02 zhukaihan

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.

rozumem avatar Mar 03 '25 19:03 rozumem

@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.

zhukaihan avatar Mar 04 '25 18:03 zhukaihan

Sorry, but I also no longer have access to Safari 14.02. Closing.

rozumem avatar Jun 13 '25 06:06 rozumem