diff --git a/cypress/e2e/session-recording.cy.ts b/cypress/e2e/session-recording.cy.ts index 3c4f57327..bcc0577bf 100644 --- a/cypress/e2e/session-recording.cy.ts +++ b/cypress/e2e/session-recording.cy.ts @@ -255,7 +255,7 @@ describe('Session recording', () => { [/https:\/\/example.com/, 'fetch'], ] - // yay, includes expected type 6 network data + // yay, includes expected network data expect(capturedRequests.length).to.equal(expectedCaptureds.length) expectedCaptureds.forEach(([url, initiatorType], index) => { expect(capturedRequests[index].name).to.match(url) @@ -281,7 +281,7 @@ describe('Session recording', () => { }) }) - it('it captures XHR method correctly', () => { + it('it captures XHR/fetch methods correctly', () => { cy.get('[data-cy-xhr-call-button]').click() cy.wait('@example.com') cy.wait('@session-recording') @@ -310,11 +310,13 @@ describe('Session recording', () => { [/https:\/\/example.com/, 'xmlhttprequest'], ] - // yay, includes expected type 6 network data + // yay, includes expected network data expect(capturedRequests.length).to.equal(expectedCaptureds.length) expectedCaptureds.forEach(([url, initiatorType], index) => { - expect(capturedRequests[index].name).to.match(url) - expect(capturedRequests[index].initiatorType).to.equal(initiatorType) + const capturedRequest = capturedRequests[index] + + expect(capturedRequest.name).to.match(url) + expect(capturedRequest.initiatorType).to.equal(initiatorType) }) // the HTML file that cypress is operating on (playground/cypress/index.html) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index c10a1895f..f39a22097 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -574,8 +574,8 @@ export class PostHog { this.compression = includes(config['supportedCompression'], Compression.GZipJS) ? Compression.GZipJS : includes(config['supportedCompression'], Compression.Base64) - ? Compression.Base64 - : undefined + ? Compression.Base64 + : undefined } if (config.analytics?.endpoint) { @@ -586,8 +586,8 @@ export class PostHog { person_profiles: this._initialPersonProfilesConfig ? this._initialPersonProfilesConfig : config['defaultIdentifiedOnly'] - ? 'identified_only' - : 'always', + ? 'identified_only' + : 'always', }) this.siteApps?.onRemoteConfig(config) @@ -1709,7 +1709,7 @@ export class PostHog { * // Capture rage clicks * rageclick: true * - * // transport for sending requests ('XHR' or 'sendBeacon') + * // transport for sending requests ('XHR' | 'fetch' | 'sendBeacon') * // NB: sendBeacon should only be used for scenarios such as * // page unload where a "best-effort" attempt to send is * // acceptable; the sendBeacon API does not support callbacks diff --git a/src/request.ts b/src/request.ts index 8ca2a54fc..3a1e52b19 100644 --- a/src/request.ts +++ b/src/request.ts @@ -218,18 +218,17 @@ const _sendBeacon = (options: RequestOptions) => { const AVAILABLE_TRANSPORTS: { transport: RequestOptions['transport']; method: (options: RequestOptions) => void }[] = [] // We add the transports in order of preference - -if (XMLHttpRequest) { +if (fetch) { AVAILABLE_TRANSPORTS.push({ - transport: 'XHR', - method: xhr, + transport: 'fetch', + method: _fetch, }) } -if (fetch) { +if (XMLHttpRequest) { AVAILABLE_TRANSPORTS.push({ - transport: 'fetch', - method: _fetch, + transport: 'XHR', + method: xhr, }) }