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
12 changes: 11 additions & 1 deletion packages/browser-utils/src/instrumentation/history.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { addHandler, fill, maybeInstrument, supportsHistory, triggerHandlers } from '@sentry/core';
import { addHandler, fill, maybeInstrument, triggerHandlers } from '@sentry/core';
import type { HandlerDataHistory } from '../types';
import { WINDOW } from '../types';

let lastHref: string | undefined;

/**
* Tells whether current environment supports History API
* {@link supportsHistory}.
*
* @returns Answer to the given question.
*/
export function supportsHistory(): boolean {
return 'history' in WINDOW && !!WINDOW.history;
}

/**
* Add an instrumentation handler for when a fetch request happens.
* The handler function is called once when the request starts and once when it ends,
Expand Down
32 changes: 31 additions & 1 deletion packages/browser-utils/test/instrumentation/history.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as instrumentHandlersModule from '@sentry/core';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { WINDOW } from '../../src/types';
import { instrumentHistory } from './../../src/instrumentation/history';
import { instrumentHistory, supportsHistory } from './../../src/instrumentation/history';

describe('instrumentHistory', () => {
const originalHistory = WINDOW.history;
Expand Down Expand Up @@ -116,3 +116,33 @@ describe('instrumentHistory', () => {
});
});
});

describe('supportsHistory', () => {
const originalHistory = WINDOW.history;

afterEach(() => {
// @ts-expect-error - this is fine for testing
WINDOW.history = originalHistory;
});

it('returns true if history is available', () => {
// @ts-expect-error - not setting all history properties
WINDOW.history = {
pushState: () => {},
replaceState: () => {},
};
expect(supportsHistory()).toBe(true);
});

it('returns false if history is not available', () => {
// @ts-expect-error - deletion is okay in this case
delete WINDOW.history;
expect(supportsHistory()).toBe(false);
});

it('returns false if history is undefined', () => {
// @ts-expect-error - undefined is okay in this case
WINDOW.history = undefined;
expect(supportsHistory()).toBe(false);
});
});
19 changes: 11 additions & 8 deletions packages/browser/src/integrations/reportingobserver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import type { Client, IntegrationFn } from '@sentry/core/browser';
import {
captureMessage,
defineIntegration,
getClient,
GLOBAL_OBJ,
supportsReportingObserver,
withScope,
} from '@sentry/core/browser';
import { captureMessage, defineIntegration, getClient, GLOBAL_OBJ, withScope } from '@sentry/core/browser';

const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;

/**
* Tells whether current environment supports ReportingObserver API
* {@link supportsReportingObserver}.
*
* @returns Answer to the given question.
*/
function supportsReportingObserver(): boolean {
return 'ReportingObserver' in WINDOW;
}

const INTEGRATION_NAME = 'ReportingObserver' as const;

interface Report {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export { startIdleSpan } from './tracing/idleSpan';

export { spanStreamingIntegration } from './integrations/browserSpanStreaming';

export { supportsDOMError, supportsHistory, supportsNativeFetch, supportsReportingObserver } from './utils/supports';
export { supportsNativeFetch } from './utils/supports';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Public support helpers removed without deprecation

Medium Severity

supportsDOMError, supportsHistory, and supportsReportingObserver were dropped from the public @sentry/core and @sentry/core/browser entry points with no deprecation window. This is flagged because the review rules call out public API removals and missing deprecation notices. Downstream imports of these helpers will fail in a minor release. Nearby unused helpers such as supportsFetch and supportsReferrerPolicy remain exported and marked deprecated instead.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 07f89b5. Configure here.

export type { XhrBreadcrumbData, XhrBreadcrumbHint } from './types/breadcrumb';
export type { BrowserClientReplayOptions } from './types/browseroptions';
38 changes: 0 additions & 38 deletions packages/core/src/utils/supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ export function supportsErrorEvent(): boolean {
}
}

/**
* Tells whether current environment supports DOMError objects
* {@link supportsDOMError}.
*
* @returns Answer to the given question.
*/
export function supportsDOMError(): boolean {
try {
// Chrome: VM89:1 Uncaught TypeError: Failed to construct 'DOMError':
// 1 argument required, but only 0 present.
// @ts-expect-error It really needs 1 argument, not 0.
new DOMError('');
return true;
} catch {
return false;
}
}

/**
* Tells whether current environment supports DOMException objects
* {@link supportsDOMException}.
Expand All @@ -54,16 +36,6 @@ export function supportsDOMException(): boolean {
}
}

/**
* Tells whether current environment supports History API
* {@link supportsHistory}.
*
* @returns Answer to the given question.
*/
export function supportsHistory(): boolean {
return 'history' in WINDOW && !!WINDOW.history;
}

/**
* Tells whether current environment supports Fetch API
* {@link supportsFetch}.
Expand Down Expand Up @@ -141,16 +113,6 @@ export function supportsNativeFetch(): boolean {
return result;
}

/**
* Tells whether current environment supports ReportingObserver API
* {@link supportsReportingObserver}.
*
* @returns Answer to the given question.
*/
export function supportsReportingObserver(): boolean {
return 'ReportingObserver' in WINDOW;
}

/**
* Tells whether current environment supports Referrer Policy API
* {@link supportsReferrerPolicy}.
Expand Down
5 changes: 3 additions & 2 deletions packages/core/test/lib/utils/is.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
isThenable,
isVueViewModel,
} from '../../../src/utils/is';
import { supportsDOMError, supportsDOMException, supportsErrorEvent } from '../../../src/utils/supports';
import { supportsDOMException, supportsErrorEvent } from '../../../src/utils/supports';
import { resolvedSyncPromise } from '../../../src/utils/syncpromise';
import { testOnlyIfNodeVersionAtLeast } from '../../testutils';

if (supportsDOMError()) {
// @ts-expect-error See: src/supports.ts for details
if (typeof DOMError !== 'undefined') {
describe('isDOMError()', () => {
test('should work as advertised', () => {
expect(isDOMError(new Error())).toEqual(false);
Expand Down
32 changes: 0 additions & 32 deletions packages/core/test/lib/utils/supports.test.ts

This file was deleted.

Loading