posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Web experiments maximum call stack

Open leerobert opened this issue 2 months ago • 1 comments

Bug description

Please help me fix this error. Here's the stack trace:

RangeError: Maximum call stack size exceeded
 [IN-APP]  File "../src/web-experiments.ts", line: 34, in: new WebExperiments
        constructor(private _instance: PostHog) {
 [IN-APP]  File "../src/utils/request-utils.ts", line: 99, in: maskQueryParams
        for (let i = 0; i < queryParts.length; i++) {
  File "Unknown Source", in: Array.forEach
 [IN-APP]  File "../src/web-experiments.ts", line: 101, in: this.getWebExperimentsAndEvaluateDisplayLogic
            this.getWebExperiments((webExperiments) => {
 [IN-APP]  File "Unknown Source", line: 1, in: e.<computed> [as get_property]
 [IN-APP]  File "../src/web-experiments.ts", line: 114, in: <anonymous>
                            this._flagToExperiments?.set(webExperiment.feature_flag_key, webExperiment)
 [IN-APP]  File "../src/web-experiments.ts", line: 24, in: webExperimentUrlValidationMap.not_icontains
            !!window && location.href.toLowerCase().indexOf(conditionsUrl.toLowerCase()) === -1,
 [IN-APP]  File "../src/utils/request-utils.ts", line: 99, in: maskQueryParams
        for (let i = 0; i < queryParts.length; i++) {
  File "Unknown Source", in: Array.forEach
 [IN-APP]  File "../src/web-experiments.ts", line: 24, in: webExperimentUrlValidationMap.not_icontains
            !!window && location.href.toLowerCase().indexOf(conditionsUrl.toLowerCase()) === -1,

Note: Frames marked with [IN-APP] are from the application code (my code), while frames without this marker are from external libraries/frameworks. Focus your analysis primarily on the [IN-APP] frames as these are most likely where the issue needs to be fixed.

Can you:

  1. Analyze what's causing this error. Try to consider multiple possible factors, and dig deep to find a root cause.
  2. Explain in detail why this error occurred. Provide code examples if applicable.
  3. Suggest the most likely fix, enumerating multiple possible solutions and choosing the best one.
  4. Attempt to fix this error.

The final output of your efforts should be:

  • An implemented fix for the issue
  • A detailed explanation of the fix and how it addresses the root cause

How to reproduce

Related sub-libraries

  • [ ] All of them
  • [x] posthog-js (web)
  • [ ] posthog-js-lite (web lite)
  • [ ] posthog-node
  • [ ] posthog-react-native
  • [ ] @posthog/react
  • [ ] @posthog/ai
  • [ ] @posthog/nextjs-config

Additional context

Thank you for your bug report – we love squashing them!

leerobert avatar Oct 17 '25 17:10 leerobert

@leerobert thanks for the report @PostHog/team-experiments is that something your team owns?

marandaneto avatar Oct 19 '25 07:10 marandaneto