Clarify native extension type boundaries

This commit is contained in:
Brennan Benson
2026-11-13 23:21:12 -08:00
parent 691e40d93a
commit 7f50d98a95
5 changed files with 9 additions and 5 deletions
@@ -48,6 +48,7 @@ vi.mock('./profile-sessions/browser-extension-session-loader', () => ({
_profile: string,
_id: string,
run: (session: Electron.Session) => Promise<unknown>
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture operation callback does not use native session members.
) => run({} as Electron.Session),
hasBrowserExtensionProfileDemand: () => true,
getBrowserExtensionSessionForProfile: vi.fn(),
@@ -46,6 +46,7 @@ vi.mock('../profile-sessions/browser-extension-session-loader', () => ({
_profile: string,
_id: string,
run: (session: Electron.Session) => Promise<unknown>
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture operation callback does not use native session members.
) => run({} as Electron.Session),
hasBrowserExtensionProfileDemand: () => true,
getBrowserExtensionSessionForProfile: (profileId: string) =>
@@ -36,6 +36,7 @@ vi.mock('../profile-sessions/browser-extension-session-loader', () => ({
_profile: string,
_id: string,
run: (session: Electron.Session) => Promise<unknown>
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture operation callback does not use native session members.
) => run({} as Electron.Session),
hasBrowserExtensionProfileDemand: () => true,
getBrowserExtensionSessionForProfile: () => ({}),
@@ -440,6 +440,7 @@ it('reuses completed full maintenance until the install store changes, and scope
it('skips repeated no-worker cleanup only after completion and invalidates it for every worker generation', async () => {
const { refreshWorkerRegistration } = await import('./browser-extension-worker-registration')
const clearStorageData = vi.fn(async () => {})
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: worker registration cleanup only calls the provided clearStorageData method.
const session = { clearStorageData } as unknown as Electron.Session
const prepared = {
extensionId: 'b'.repeat(32),
@@ -100,11 +100,11 @@ export function installMainWindowWebviewSecurity(mainWindow: BrowserWindow): voi
{ url: string; options: Electron.LoadURLOptions }
>()
const captureInitialNavigation = (_event: Electron.Event, guest: Electron.WebContents): void => {
const arguments_ =
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Electron WebContents exposes getLastWebPreferences at runtime; its public type omits it.
(
guest as Electron.WebContents & { getLastWebPreferences: () => Electron.WebPreferences }
).getLastWebPreferences()?.additionalArguments ?? []
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: Electron WebContents exposes getLastWebPreferences at runtime; its public type omits it.
const nativeGuest = guest as Electron.WebContents & {
getLastWebPreferences: () => Electron.WebPreferences
}
const arguments_ = nativeGuest.getLastWebPreferences()?.additionalArguments ?? []
const marker = arguments_.find((argument) => pendingInitialNavigation.has(argument))
if (!marker) {
return