perf: cache browser plugin sdk facades

This commit is contained in:
Peter Steinberger
2026-04-17 20:26:14 +01:00
parent 809f42eeea
commit c408bbe9c9
5 changed files with 34 additions and 24 deletions

View File

@@ -227,14 +227,7 @@ describe("plugin activation boundary", () => {
loadBundledPluginPublicSurfaceModuleSync.mock.calls.map(
([params]) => params.artifactBasename,
),
).toEqual([
"browser-host-inspection.js",
"browser-control-auth.js",
"browser-profiles.js",
"browser-profiles.js",
"browser-host-inspection.js",
"browser-host-inspection.js",
]);
).toEqual(["browser-host-inspection.js", "browser-control-auth.js", "browser-profiles.js"]);
loadBundledPluginPublicSurfaceModuleSync.mockReset();
await expect(browser.closeTrackedBrowserTabsForSessions({ sessionKeys: [] })).resolves.toBe(0);

View File

@@ -24,11 +24,15 @@ type BrowserControlAuthSurface = {
) => Promise<EnsureBrowserControlAuthResult>;
};
let cachedBrowserControlAuthSurface: BrowserControlAuthSurface | undefined;
function loadBrowserControlAuthSurface(): BrowserControlAuthSurface {
return loadBundledPluginPublicSurfaceModuleSync<BrowserControlAuthSurface>({
dirName: "browser",
artifactBasename: "browser-control-auth.js",
});
cachedBrowserControlAuthSurface ??=
loadBundledPluginPublicSurfaceModuleSync<BrowserControlAuthSurface>({
dirName: "browser",
artifactBasename: "browser-control-auth.js",
});
return cachedBrowserControlAuthSurface;
}
export function resolveBrowserControlAuth(

View File

@@ -11,11 +11,15 @@ type BrowserHostInspectionSurface = {
parseBrowserMajorVersion: (rawVersion: string | null | undefined) => number | null;
};
let cachedBrowserHostInspectionSurface: BrowserHostInspectionSurface | undefined;
function loadBrowserHostInspectionSurface(): BrowserHostInspectionSurface {
return loadBundledPluginPublicSurfaceModuleSync<BrowserHostInspectionSurface>({
dirName: "browser",
artifactBasename: "browser-host-inspection.js",
});
cachedBrowserHostInspectionSurface ??=
loadBundledPluginPublicSurfaceModuleSync<BrowserHostInspectionSurface>({
dirName: "browser",
artifactBasename: "browser-host-inspection.js",
});
return cachedBrowserHostInspectionSurface;
}
export function resolveGoogleChromeExecutableForPlatform(

View File

@@ -10,15 +10,19 @@ type BrowserMaintenanceSurface = {
closeTrackedBrowserTabsForSessions: (params: CloseTrackedBrowserTabsParams) => Promise<number>;
};
let cachedBrowserMaintenanceSurface: BrowserMaintenanceSurface | undefined;
function hasRequestedSessionKeys(sessionKeys: Array<string | undefined>): boolean {
return sessionKeys.some((key) => Boolean(key?.trim()));
}
function loadBrowserMaintenanceSurface(): BrowserMaintenanceSurface {
return loadBundledPluginPublicSurfaceModuleSync<BrowserMaintenanceSurface>({
dirName: "browser",
artifactBasename: "browser-maintenance.js",
});
cachedBrowserMaintenanceSurface ??=
loadBundledPluginPublicSurfaceModuleSync<BrowserMaintenanceSurface>({
dirName: "browser",
artifactBasename: "browser-maintenance.js",
});
return cachedBrowserMaintenanceSurface;
}
export async function closeTrackedBrowserTabsForSessions(

View File

@@ -57,11 +57,16 @@ type BrowserProfilesSurface = {
) => ResolvedBrowserProfile | null;
};
let cachedBrowserProfilesSurface: BrowserProfilesSurface | undefined;
function loadBrowserProfilesSurface(): BrowserProfilesSurface {
return loadBundledPluginPublicSurfaceModuleSync<BrowserProfilesSurface>({
dirName: "browser",
artifactBasename: "browser-profiles.js",
});
cachedBrowserProfilesSurface ??= loadBundledPluginPublicSurfaceModuleSync<BrowserProfilesSurface>(
{
dirName: "browser",
artifactBasename: "browser-profiles.js",
},
);
return cachedBrowserProfilesSurface;
}
export function resolveBrowserConfig(