PostHog / posthog-js

Send usage data from your web app or site to PostHog, with autocapture.
https://posthog.com/docs/libraries/js
Other
272 stars 112 forks source link

Uncaught RangeError: invalid field value #710

Closed dynalz closed 1 year ago

dynalz commented 1 year ago

I'm having an issue on this page in particular (live): https://lp.ricardomatos.me/e2_imo4all_o2f1-masterclass_1

For some reason I cannot capture anything, as it just throws an error Error to reproduce in console: posthog.capture('input-capture', { $set: {foo: "bar"} })

Traceback as follows:

uuidv7.ts:59 Uncaught RangeError: invalid field value
    at Function.value (uuidv7.ts:59:19)
    at e.value (uuidv7.ts:181:21)
    at e.value (uuidv7.ts:137:28)
    at F (uuidv7.ts:244:92)
    at se (uuidv7.ts:241:37)
    at e.value (posthog-core.ts:851:19)
    at e.value (posthog-core.ts:520:18)
    at posthog-core.ts:2107:18
    at L (utils.ts:129:26)
    at posthog-core.ts:2106:5

I managed to debug and trace it back to here: image

neilkakkar commented 1 year ago

(cc: @pauldambra )

pauldambra commented 1 year ago

Copying random code off the internet finally back-fired 🤣 Thanks for the heads-up @neilkakkar and thanks for the report @dynalz . This is a super clear bug report thanks for taking the time 🙌

pauldambra commented 1 year ago

If I visit your page with adblockers on then I can run PostHog without seeing the error.

In your screenshot, the value of the first argument should be a number but appears to be a Date object. I think one of the other trackers on the page is over-riding Date.now() which is very cheeky of them 🤣 Or maybe Chrome is being super helpful

Screenshot 2023-06-23 at 12 51 48

My chrome (at least) provides a number as expected.

So I guess there are two things here

1) Is there a safer way for us to get the current time 2) Should we really throw in this method? If we send an event to PostHog without a UUID we generate one on the backend. So we lose re-triablity but you don't lose your data 🤔

pauldambra commented 1 year ago

My whole network at home blocks ad-trackers so this was hard to investigate 🤣

I hooked my phone up for remote debugging since that device has a VPN.

You have a date.js from assets.clickfunnels.com which overrides a number of Date operations. At least one in such a way that they no longer match the spec. That breaks PostHog but it'll potentially break other tools or your own code too.

The header of that file

/**
 * Version: 1.0 Alpha-1 
 * Build Date: 13-Nov-2007
 * Copyright (c) 2006-2007, Coolite Inc. (http://www.coolite.com/). All rights reserved.
 * License: Licensed under The MIT License. See license.txt and http://www.datejs.com/license/. 
 * Website: http://www.datejs.com/ or http://www.coolite.com/datejs/
 */

This means I'd suggest that you strip that tool out and replace it tbh.

Funnily enough, the name clickfunnels rang a bell for me. We reported this exact problem to them in November 2021. Internal slack conversation for that investigation is here https://posthog.slack.com/archives/C0113360FFV/p1635850088131000 (@rcmarron originally found this bug for a different PostHog customer and might enjoy seeing it crop up again)

datejs that clickfunnels relies on has newer versions that don't have this problem but clickfunnels haven't updated for several years

pauldambra commented 1 year ago

I've emailed clickfunnels again to let them know this is still broken for people.

rcmarron commented 1 year ago

Hah! Funny to see this pop up again! Thanks for the mention @pauldambra!

I had stumbled on this article a bit ago. It talks about how to detect if a function has been monkey patched and also how to get the original function back (by pulling it from an i-frame 🤯). I haven't actually tried it, but could be worth looking into.