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
4 changes: 2 additions & 2 deletions packages/web-extension/src/messaging/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BackgroundMessenger, createBackgroundMessenger, generalizeBackgroundMessenger } from './BackgroundMessenger';
import { ChannelName, ConsumeRemoteApiOptions, ExposeApiProps, MessengerDependencies } from './types';
import { FinalizationRegistryDestructor } from './util';
import { FinalizationRegistryDestructor, isBackgroundProcess } from './util';
import { consumeMessengerRemoteApi, exposeMessengerApi } from './remoteApi';
import { createNonBackgroundMessenger } from './NonBackgroundMessenger';

Expand All @@ -15,7 +15,7 @@ export * from './errors';

export type BaseChannel = { baseChannel: ChannelName };

const isInBackgroundProcess = typeof window === 'undefined';
const isInBackgroundProcess = isBackgroundProcess();

const getBackgroundMessenger = (() => {
let backgroundMessenger: BackgroundMessenger | null = null;
Expand Down
4 changes: 4 additions & 0 deletions packages/web-extension/src/messaging/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ export class FinalizationRegistryDestructor implements Destructor {
this.#registry.register(obj, objectId);
}
}

// Firefox addons use a generated background page to run the background script, so they have a window object
export const isBackgroundProcess = () =>
typeof window === 'undefined' || window.location.href.includes('_generated_background');
Loading