PostHog / posthog-js

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

Allow ngsw-bypass header to bypass the angular service worker #697

Open patricsteiner opened 1 year ago

patricsteiner commented 1 year ago

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... Could you allow this specific header? Or is there any other way to fix this issue?

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.
pauldambra commented 3 months ago

angular still does this https://angular.dev/ecosystem/service-workers/devops#bypassing-the-service-worker