Skip to content

Commit 0abd102

Browse files
author
Luca Forstner
committed
feat(browser): Set page context instead of using request interface
1 parent bcb15ba commit 0abd102

7 files changed

Lines changed: 50 additions & 44 deletions

File tree

dev-packages/browser-integration-tests/suites/integrations/httpContext/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Event } from '@sentry/core';
44
import { sentryTest } from '../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
66

7-
sentryTest('httpContextIntegration captures user-agent and referrer', async ({ getLocalTestUrl, page }) => {
7+
sentryTest('pageInformationIntegration captures user-agent and referrer', async ({ getLocalTestUrl, page }) => {
88
const url = await getLocalTestUrl({ testDir: __dirname });
99

1010
const errorEventPromise = getFirstSentryEnvelopeRequest<Event>(page);

dev-packages/browser-integration-tests/suites/manual-client/browser-context/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
dedupeIntegration,
66
defaultStackParser,
77
functionToStringIntegration,
8-
httpContextIntegration,
8+
pageInformationIntegration,
99
eventFiltersIntegration,
1010
linkedErrorsIntegration,
1111
makeFetchTransport,
@@ -15,7 +15,7 @@ const integrations = [
1515
breadcrumbsIntegration(),
1616
functionToStringIntegration(),
1717
dedupeIntegration(),
18-
httpContextIntegration(),
18+
pageInformationIntegration(),
1919
eventFiltersIntegration(),
2020
linkedErrorsIntegration(),
2121
];

packages/angular/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
breadcrumbsIntegration,
55
browserSessionIntegration,
66
globalHandlersIntegration,
7-
httpContextIntegration,
7+
pageInformationIntegration,
88
init as browserInit,
99
linkedErrorsIntegration,
1010
setContext,
@@ -41,7 +41,7 @@ export function getDefaultIntegrations(_options: BrowserOptions = {}): Integrati
4141
globalHandlersIntegration(),
4242
linkedErrorsIntegration(),
4343
dedupeIntegration(),
44-
httpContextIntegration(),
44+
pageInformationIntegration(),
4545
browserSessionIntegration(),
4646
];
4747
}

packages/browser/src/exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export { getDefaultIntegrations, forceLoad, init, onLoad, showReportDialog } fro
8888

8989
export { breadcrumbsIntegration } from './integrations/breadcrumbs';
9090
export { globalHandlersIntegration } from './integrations/globalhandlers';
91-
export { httpContextIntegration } from './integrations/httpcontext';
91+
// eslint-disable-next-line deprecation/deprecation
92+
export { httpContextIntegration, pageInformationIntegration } from './integrations/pageinformation';
9293
export { linkedErrorsIntegration } from './integrations/linkederrors';
9394
export { browserApiErrorsIntegration } from './integrations/browserapierrors';
9495

packages/browser/src/integrations/httpcontext.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { defineIntegration, getLocationHref } from '@sentry/core';
2+
import { WINDOW } from '../helpers';
3+
4+
/**
5+
* Collects information about the current page and attaches it as context to the event.
6+
*/
7+
export const pageInformationIntegration = defineIntegration(() => {
8+
return {
9+
// TODO(v10): Update name to "PageInformation"
10+
name: 'HttpContext',
11+
preprocessEvent(event) {
12+
// if none of the information we want exists, don't bother
13+
if (!WINDOW.navigator && !WINDOW.location && !WINDOW.document) {
14+
return;
15+
}
16+
17+
const href = getLocationHref();
18+
19+
// grab as much info as exists and add it to the event
20+
const url = event.request?.url || href;
21+
const request = {
22+
...(url && { url }),
23+
};
24+
event.request = request;
25+
26+
event.contexts = event.contexts || {};
27+
event.contexts.page = {
28+
href: href || undefined,
29+
referrer: WINDOW.document.referrer,
30+
user_agent: WINDOW.navigator.userAgent,
31+
};
32+
},
33+
};
34+
});
35+
36+
/**
37+
* Collects information about the current page and attaches it as context to the event.
38+
*
39+
* @deprecated This integration was renamed to `pageInformationIntegration`, which should be used instead.
40+
*/
41+
export const httpContextIntegration = pageInformationIntegration;

packages/browser/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { breadcrumbsIntegration } from './integrations/breadcrumbs';
2222
import { browserApiErrorsIntegration } from './integrations/browserapierrors';
2323
import { browserSessionIntegration } from './integrations/browsersession';
2424
import { globalHandlersIntegration } from './integrations/globalhandlers';
25-
import { httpContextIntegration } from './integrations/httpcontext';
25+
import { pageInformationIntegration } from './integrations/pageinformation';
2626
import { linkedErrorsIntegration } from './integrations/linkederrors';
2727
import { defaultStackParser } from './stack-parsers';
2828
import { makeFetchTransport } from './transports/fetch';
@@ -43,7 +43,7 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
4343
globalHandlersIntegration(),
4444
linkedErrorsIntegration(),
4545
dedupeIntegration(),
46-
httpContextIntegration(),
46+
pageInformationIntegration(),
4747
browserSessionIntegration(),
4848
];
4949
}

0 commit comments

Comments
 (0)