diff --git a/packages/replay/src/coreHandlers/handleScope.ts b/packages/replay/src/coreHandlers/handleScope.ts index 8f9081639ed3..79d8aa541a37 100644 --- a/packages/replay/src/coreHandlers/handleScope.ts +++ b/packages/replay/src/coreHandlers/handleScope.ts @@ -26,7 +26,11 @@ export const handleScopeListener: (replay: ReplayContainer) => (scope: Scope) => * An event handler to handle scope changes. */ export function handleScope(scope: Scope): Breadcrumb | null { - const newBreadcrumb = scope.getLastBreadcrumb(); + // TODO (v8): Remove this guard. This was put in place because we introduced + // Scope.getLastBreadcrumb mid-v7 which caused incompatibilities with older SDKs. + // For now, we'll just return null if the method doesn't exist but we should eventually + // get rid of this guard. + const newBreadcrumb = scope.getLastBreadcrumb && scope.getLastBreadcrumb(); // Listener can be called when breadcrumbs have not changed, so we store the // reference to the last crumb and only return a crumb if it has changed diff --git a/packages/replay/test/unit/coreHandlers/handleScope.test.ts b/packages/replay/test/unit/coreHandlers/handleScope.test.ts index 8f0a587b79c7..c7ba7cdc75ce 100644 --- a/packages/replay/test/unit/coreHandlers/handleScope.test.ts +++ b/packages/replay/test/unit/coreHandlers/handleScope.test.ts @@ -3,7 +3,12 @@ import type { Breadcrumb, Scope } from '@sentry/types'; import * as HandleScope from '../../../src/coreHandlers/handleScope'; describe('Unit | coreHandlers | handleScope', () => { - const mockHandleScope = jest.spyOn(HandleScope, 'handleScope'); + let mockHandleScope: jest.SpyInstance; + + beforeEach(() => { + mockHandleScope = jest.spyOn(HandleScope, 'handleScope'); + mockHandleScope.mockClear(); + }); it('returns a breadcrumb only if last breadcrumb has changed', function () { const scope = { @@ -47,4 +52,11 @@ describe('Unit | coreHandlers | handleScope', () => { expect(mockHandleScope).toHaveBeenCalledTimes(1); expect(mockHandleScope).toHaveReturnedWith(expect.objectContaining({ message: 'f00', category: 'console' })); }); + + it('returns null if the method does not exist on the scope', () => { + const scope = {} as unknown as Scope; + HandleScope.handleScope(scope); + expect(mockHandleScope).toHaveBeenCalledTimes(1); + expect(mockHandleScope).toHaveReturnedWith(null); + }); });