diff --git a/.changeset/six-zoos-explode.md b/.changeset/six-zoos-explode.md new file mode 100644 index 000000000000..7527ff9888b7 --- /dev/null +++ b/.changeset/six-zoos-explode.md @@ -0,0 +1,5 @@ +--- +'@solana/rpc-subscriptions': patch +--- + +The online/offline checker in the subscriptions implementation no longer throws an error when hosted in the Content Scripts environment of a browser extension diff --git a/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-autopinger-test.ts b/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-autopinger-test.ts index 18d0bb21c2ba..efd661351f45 100644 --- a/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-autopinger-test.ts +++ b/packages/rpc-subscriptions/src/__tests__/rpc-subscriptions-autopinger-test.ts @@ -10,7 +10,7 @@ describe('getRpcSubscriptionsChannelWithAutoping', () => { let mockOn: jest.Mock; let mockSend: jest.Mock; let mockWindowAddEventListener: jest.Mock; - let originalWindowAddEventListener: typeof globalThis.window.addEventListener; + let originalWindowAddEventListener: typeof globalThis.addEventListener; function receiveError(error?: unknown) { mockOn.mock.calls.filter(([type]) => type === 'error').forEach(([_, listener]) => listener(error)); } @@ -25,8 +25,8 @@ describe('getRpcSubscriptionsChannelWithAutoping', () => { beforeEach(() => { jest.useFakeTimers(); if (__BROWSER__) { - originalWindowAddEventListener = globalThis.window.addEventListener; - globalThis.window.addEventListener = mockWindowAddEventListener = jest.fn(); + originalWindowAddEventListener = globalThis.addEventListener; + globalThis.addEventListener = mockWindowAddEventListener = jest.fn(); } mockOn = jest.fn().mockReturnValue(() => {}); mockSend = jest.fn().mockResolvedValue(void 0); @@ -37,7 +37,7 @@ describe('getRpcSubscriptionsChannelWithAutoping', () => { }); afterEach(() => { if (__BROWSER__) { - globalThis.window.addEventListener = originalWindowAddEventListener; + globalThis.addEventListener = originalWindowAddEventListener; } }); it('sends a ping message to the channel at the specified interval', async () => { diff --git a/packages/rpc-subscriptions/src/rpc-subscriptions-autopinger.ts b/packages/rpc-subscriptions/src/rpc-subscriptions-autopinger.ts index 03ab184e3033..bd06b4b9032b 100644 --- a/packages/rpc-subscriptions/src/rpc-subscriptions-autopinger.ts +++ b/packages/rpc-subscriptions/src/rpc-subscriptions-autopinger.ts @@ -48,14 +48,14 @@ export function getRpcSubscriptionsChannelWithAutoping