Skip to content
Open
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
18 changes: 17 additions & 1 deletion packages/shared/src/mcp/chrome-path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { existsSync } from 'node:fs';
import { MIDSCENE_MCP_CHROME_PATH, globalConfigManager } from '../env';

let cachedSystemChromePath: string | undefined = undefined;

export function clearSystemChromePathCache() {
cachedSystemChromePath = undefined;
}

export function getSystemChromePath(): string | undefined {
if (cachedSystemChromePath !== undefined) {
return cachedSystemChromePath;
}

const platform = process.platform;

const chromePaths: Record<string, string[]> = {
Expand Down Expand Up @@ -29,7 +39,13 @@ export function getSystemChromePath(): string | undefined {
};

const paths = chromePaths[platform] ?? [];
return paths.find((p) => existsSync(p));
const foundPath = paths.find((p) => existsSync(p));

if (foundPath) {
cachedSystemChromePath = foundPath;
}

return foundPath;
}

export function resolveChromePath(): string {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/tests/unit-test/chrome-path.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync } from 'node:fs';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import {
clearSystemChromePathCache,
getSystemChromePath,
resolveChromePath,
} from '../../src/mcp/chrome-path';
Expand All @@ -22,6 +23,7 @@ describe('Chrome Path Resolution', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(existsSync).mockReturnValue(false);
clearSystemChromePathCache();
});

afterEach(() => {
Expand Down
Loading