launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
112 stars 65 forks source link

SDK working properly in Safari, not in Chrome #190

Closed mssodhi closed 4 years ago

mssodhi commented 4 years ago

Is this a support request? This issue tracker is maintained by LaunchDarkly SDK developers and is intended for feedback on the SDK code. If you're not sure whether the problem you are having is specifically related to the SDK, or to the LaunchDarkly service overall, it may be more appropriate to contact the LaunchDarkly support team; they can help to investigate the problem and will consult the SDK team if necessary. You can submit a support request by going here and clicking "submit a request", or by emailing support@launchdarkly.com.

Note that issues filed on this issue tracker are publicly accessible. Do not provide any private account information on your issues. If your problem is specific to your account, you should submit a support request as described above.

Describe the bug A clear and concise description of what the bug is. Initializing the JS Client SDK isn't adding user to LD Dashboard users list, and it's not registering user events.

I investigated the issue and found out that it worked properly in Safari, but in Chrome it did not work.

To reproduce Steps to reproduce the behavior. I've created a simple code sandbox sample. All you need to do is plug in an env key. Then run this in chrome. If it's working properly, you should see the user added to the users' list, and there being a user event in the debugger tab.

If it doesn't work, test in Safari and it'll work fine. https://codesandbox.io/s/naughty-moser-2fuwd

Expected behavior A clear and concise description of what you expected to happen.

Upon initializing the client SDK and calling identify(), the user should be added to user list and user events should be shown in the debugger.

Logs If applicable, add any log output related to your problem.

SDK version The version of this SDK that you are using. 2.15.2

Language version, developer tools For instance, Go 1.11 or Ruby 2.5.3. If you are using a language that requires a separate compiler, such as C, please include the name and version of the compiler too.

OS/platform For instance, Ubuntu 16.04, Windows 10, or Android 4.0.3. If your code is running in a browser, please also include the browser type and version. Chrome Version 78.0.3904.97 (Official Build) (64-bit) Mac OS 10.14.6

Additional context Add any other context about the problem here.

eli-darkly commented 4 years ago

I can't reproduce this problem. The user shows up correctly on my dashboard after running your sandbox code in Chrome with my environment ID. I'm using the same Chrome version and Mac OS version that you used.

With any kind of problem like this, if you're able to reproduce it consistently, it would be a good idea to check the browser debug tools for 1. any error messages in the console and 2. the Ajax request that the SDK uses to send the event data. The latter would be a POST request to https://events.launchdarkly.com/events/bulk/$ENVIRONMENT_ID (this will usually be preceded by an OPTIONS request to the same URL, which you can ignore), and it should contain some JSON data like this:

[{
  "kind":"identify",
  "key":"sandbox_user",
  "user":{"firstName":"Sand","lastName":"Box","key":"sandbox_user"},
  "creationDate":1574228200279
}]

Do you see this request? Did it get a successful response (202 status)?

Also... were you using the same user data in both your Chrome test and your Safari test? If you are, and if you did the Safari test fairly soon after the Chrome test, then it would be impossible to tell which test the user came from; it could just be a processing delay.

mssodhi commented 4 years ago

Hmmm... yeah that's really strange. I'm able to reproduce it in chrome (even tried incognito). The weird thing is, there's no request to events.launchdarkly.com. But if I run the same code in firefox or safari, everything works as expected and I clearly can see the request to events.launchdarkly.com.

The only request I see in Chrome are: https://app.launchdarkly.com/sdk/goals/, and https://app.launchdarkly.com/sdk/evalx//user

I've been testing with Chrome for the majority of the day, and then tried Safari. So enough time between the different browsers.

eli-darkly commented 4 years ago

Yeah, if you're not seeing a request to events.launchdarkly.com at all in Chrome, then my theory about it being a processing delay is clearly wrong— the SDK is apparently not delivering the events to LD at all. I don't know how to explain this. I presume you're not seeing any console errors?

mssodhi commented 4 years ago

Yeah, none at all. Even though it's not identifying the user to LD, it's able to get the correct flag settings for the user. I'm guessing that's because it's able to fetch the flags from the evalx api and is not dependent on the events api.

It's really odd because the code works fine on both Safari and Firefox. And apparently working fine for you on the same version of Chrome.

cjcaj commented 4 years ago

I'm seeing the same issue on Chrome 78.0.3904.97. I don't see any requests to events but I do see them on Safari.

eli-darkly commented 4 years ago

You don't by any chance have "do not track" or an ad blocker enabled in Chrome, do you? I would probably expect to see a failed request in the debugger if it was an ad blocker, but "do not track" would prevent it from trying to send events at all.

cjcaj commented 4 years ago

I did have "do not track" on. I see the event requests now with it turned off. Thanks! It'd be great to have a note in the docs if it's not there already.

eli-darkly commented 4 years ago

@cjcaj Aha! Yes, there's a note about it here if you search for "do not track". I just didn't think of it at first.

eli-darkly commented 4 years ago

Whoops - I was going to close this issue, but I haven't heard from @mssodhi yet so I can't be sure that it is the same problem.

mssodhi commented 4 years ago

Ah, that's it! That fixed the issue. Thanks for your help @eli-darkly!

Is there a way to by-pass the do not track restriction in the SDK? Not sure how many end-users it will impact.

eli-darkly commented 4 years ago

@mssodhi There isn't currently. We have considered it in the past, but the current consensus is that even though "do not track" is very inconsistently implemented and impossible to really enforce, it is considered bad behavior for front-end web tools to disregard it in the context of sending analytics data; it is also the kind of thing that could get LaunchDarkly's domain blacklisted by ad-blockers that would not otherwise be blocking us.