PostHog / PostHog/posthog

Allow ngsw-bypass header to bypass the angular service worker

Open
#16,009 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
39.9k
Forks
3.4k
Avg merge
7h 27m
Merged PRs (30d)
222

Description

Is your feature request related to a problem?

The Angular service worker (ngsw) intercepts all calls and seems to break session recordings. The only way to bypass the service worker is by adding ngsw-bypass as either a query param or a header to every request to posthog. As far as I can tell it's not possible in posthog to configure "global" query params, so the only way left is adding headers, which is possible with xhr_headers as described here: https://posthog.com/docs/libraries/js

    posthog.init('phc_12345', {
      api_host: "https://eu.posthog.com",
      xhr_headers: {
        'ngsw-bypass': '1',
      },
    });

However unfortunately this is not allowed by posthog...

Access to XMLHttpRequest at 'https://eu.posthog.com/e/?ip=1&_=1234&ver=1.57.2' from origin 'http://localhost:4200' has been blocked by CORS policy: Request header field ngsw-bypass is not allowed by Access-Control-Allow-Headers in preflight response.

Describe the solution you'd like

Allow ngsw-bypass to be set as a header OR add a way to globally add query params to every posthog requests, like for example:

    posthog.init('phc_12345', {
      api_host: "https://eu.posthog.com",
      query_params: {
        'ngsw-bypass': '1',
      },
    });

Describe alternatives you've considered

Setting up an own proxy and removing the header there... But this is an unnecessary indirection that i'd like to avoid.

Thank you very much :) 🦔

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The request concerns CORS for requests to the eu.posthog.com endpoint and the JavaScript xhr_headers configuration; no repository file or test is named. Start by locating the endpoint's preflight and CORS handling, then verify that ngsw-bypass is accepted without breaking existing requests. Done means the documented header no longer fails the browser preflight.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.