Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

const integrations = Sentry.getDefaultIntegrations({}).filter(
defaultIntegration => defaultIntegration.name === 'HttpContext',
);
Comment on lines +5 to +7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I isolated this similarly to how the SDK was initialized in the original issue so that only this integration is active.
We don't have to do this but given that all other tests that implicitly check on some of the fields are conventional Sentry.init SDK scenarios, I think we can leave it as-is.


const client = new Sentry.BrowserClient({
dsn: 'https://[email protected]/1337',
transport: Sentry.makeFetchTransport,
stackParser: Sentry.defaultStackParser,
integrations: integrations,
});

const scope = new Sentry.Scope();
scope.setClient(client);
client.init();

window._sentryScope = scope;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window._sentryScope.captureException(new Error('client init'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';

import { sentryTest } from '../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';

sentryTest('httpContextIntegration captures user-agent and referrer', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);

// Simulate document.referrer being set to test full functionality of the integration
await page.goto(url, { referer: 'https://sentry.io/' });

const errorEvent = await errorEventPromise;

expect(errorEvent.exception?.values).toHaveLength(1);

expect(errorEvent.request).toEqual({
headers: {
'User-Agent': expect.any(String),
Referer: 'https://sentry.io/',
},
url: expect.any(String),
});
});
Loading