mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 17:54:47 +00:00
fix: rebase synthetic browser profiles
This commit is contained in:
@@ -73,6 +73,17 @@ export async function createBrowserProfileConfig(params: {
|
||||
const mutation = await mutateConfigFile<BrowserProfileConfig>({
|
||||
afterWrite: { mode: "auto" },
|
||||
mutate: async (draft) => {
|
||||
const rawDraftBrowser = draft.browser as
|
||||
| (NonNullable<typeof draft.browser> & { cdpPortRangeEnd?: unknown })
|
||||
| undefined;
|
||||
const draftCdpPortRangeEnd =
|
||||
typeof rawDraftBrowser?.cdpPortRangeEnd === "number"
|
||||
? rawDraftBrowser.cdpPortRangeEnd
|
||||
: undefined;
|
||||
const useRebasedPortRange =
|
||||
draft.gateway?.port !== undefined ||
|
||||
draft.browser?.cdpPortRangeStart !== undefined ||
|
||||
draftCdpPortRangeEnd !== undefined;
|
||||
const latestResolved = resolveBrowserConfig(
|
||||
{
|
||||
...params.resolved,
|
||||
@@ -82,12 +93,14 @@ export async function createBrowserProfileConfig(params: {
|
||||
draft,
|
||||
);
|
||||
const latestRootResolved = resolveBrowserConfig(draft.browser, draft);
|
||||
const latestProfileSource = useRebasedPortRange ? latestRootResolved : latestResolved;
|
||||
const latestProfiles = draft.browser?.profiles ?? {};
|
||||
if (params.name in latestProfiles || params.name in latestResolved.profiles) {
|
||||
if (params.name in latestProfiles || params.name in latestProfileSource.profiles) {
|
||||
throw new BrowserConflictError(`profile "${params.name}" already exists`);
|
||||
}
|
||||
|
||||
const profileColor = params.color ?? allocateColor(getUsedColors(latestResolved.profiles));
|
||||
const profileColor =
|
||||
params.color ?? allocateColor(getUsedColors(latestProfileSource.profiles));
|
||||
|
||||
let nextProfileConfig: BrowserProfileConfig;
|
||||
if (params.parsedCdpUrl) {
|
||||
@@ -109,18 +122,7 @@ export async function createBrowserProfileConfig(params: {
|
||||
color: profileColor,
|
||||
};
|
||||
} else {
|
||||
const usedPorts = getUsedPorts(latestResolved.profiles);
|
||||
const rawDraftBrowser = draft.browser as
|
||||
| (NonNullable<typeof draft.browser> & { cdpPortRangeEnd?: unknown })
|
||||
| undefined;
|
||||
const draftCdpPortRangeEnd =
|
||||
typeof rawDraftBrowser?.cdpPortRangeEnd === "number"
|
||||
? rawDraftBrowser.cdpPortRangeEnd
|
||||
: undefined;
|
||||
const useRebasedPortRange =
|
||||
draft.gateway?.port !== undefined ||
|
||||
draft.browser?.cdpPortRangeStart !== undefined ||
|
||||
draftCdpPortRangeEnd !== undefined;
|
||||
const usedPorts = getUsedPorts(latestProfileSource.profiles);
|
||||
const rangeSource = useRebasedPortRange ? latestRootResolved : params.resolved;
|
||||
const range = cdpPortRange({
|
||||
controlPort: rangeSource.controlPort,
|
||||
|
||||
@@ -194,10 +194,10 @@ describe("BrowserProfilesService", () => {
|
||||
const service = createBrowserProfilesService(ctx);
|
||||
const result = await service.createProfile({ name: "work" });
|
||||
|
||||
expect(result.cdpPort).toBe(18800);
|
||||
expect(state.resolved.profiles.work?.cdpPort).toBe(18800);
|
||||
expect(result.cdpPort).toBe(18801);
|
||||
expect(state.resolved.profiles.work?.cdpPort).toBe(18801);
|
||||
const profiles = writtenBrowserConfig().profiles as Record<string, { cdpPort?: number }>;
|
||||
expect(profiles.work?.cdpPort).toBe(18800);
|
||||
expect(profiles.work?.cdpPort).toBe(18801);
|
||||
});
|
||||
|
||||
it("accepts per-profile cdpUrl for remote Chrome", async () => {
|
||||
|
||||
Reference in New Issue
Block a user