mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 05:27:26 +00:00
refactor(browser): share client-actions url helpers
This commit is contained in:
@@ -3,20 +3,9 @@ import type {
|
|||||||
BrowserActionPathResult,
|
BrowserActionPathResult,
|
||||||
BrowserActionTabResult,
|
BrowserActionTabResult,
|
||||||
} from "./client-actions-types.js";
|
} from "./client-actions-types.js";
|
||||||
|
import { buildProfileQuery, withBaseUrl } from "./client-actions-url.js";
|
||||||
import { fetchBrowserJson } from "./client-fetch.js";
|
import { fetchBrowserJson } from "./client-fetch.js";
|
||||||
|
|
||||||
function buildProfileQuery(profile?: string): string {
|
|
||||||
return profile ? `?profile=${encodeURIComponent(profile)}` : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function withBaseUrl(baseUrl: string | undefined, path: string): string {
|
|
||||||
const trimmed = baseUrl?.trim();
|
|
||||||
if (!trimmed) {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
return `${trimmed.replace(/\/$/, "")}${path}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type BrowserFormField = {
|
export type BrowserFormField = {
|
||||||
ref: string;
|
ref: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
|||||||
@@ -4,20 +4,9 @@ import type {
|
|||||||
BrowserNetworkRequest,
|
BrowserNetworkRequest,
|
||||||
BrowserPageError,
|
BrowserPageError,
|
||||||
} from "./pw-session.js";
|
} from "./pw-session.js";
|
||||||
|
import { buildProfileQuery, withBaseUrl } from "./client-actions-url.js";
|
||||||
import { fetchBrowserJson } from "./client-fetch.js";
|
import { fetchBrowserJson } from "./client-fetch.js";
|
||||||
|
|
||||||
function buildProfileQuery(profile?: string): string {
|
|
||||||
return profile ? `?profile=${encodeURIComponent(profile)}` : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function withBaseUrl(baseUrl: string | undefined, path: string): string {
|
|
||||||
const trimmed = baseUrl?.trim();
|
|
||||||
if (!trimmed) {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
return `${trimmed.replace(/\/$/, "")}${path}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function browserConsoleMessages(
|
export async function browserConsoleMessages(
|
||||||
baseUrl: string | undefined,
|
baseUrl: string | undefined,
|
||||||
opts: { level?: string; targetId?: string; profile?: string } = {},
|
opts: { level?: string; targetId?: string; profile?: string } = {},
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
import type { BrowserActionOk, BrowserActionTargetOk } from "./client-actions-types.js";
|
import type { BrowserActionOk, BrowserActionTargetOk } from "./client-actions-types.js";
|
||||||
|
import { buildProfileQuery, withBaseUrl } from "./client-actions-url.js";
|
||||||
import { fetchBrowserJson } from "./client-fetch.js";
|
import { fetchBrowserJson } from "./client-fetch.js";
|
||||||
|
|
||||||
function buildProfileQuery(profile?: string): string {
|
|
||||||
return profile ? `?profile=${encodeURIComponent(profile)}` : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function withBaseUrl(baseUrl: string | undefined, path: string): string {
|
|
||||||
const trimmed = baseUrl?.trim();
|
|
||||||
if (!trimmed) {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
return `${trimmed.replace(/\/$/, "")}${path}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function browserCookies(
|
export async function browserCookies(
|
||||||
baseUrl: string | undefined,
|
baseUrl: string | undefined,
|
||||||
opts: { targetId?: string; profile?: string } = {},
|
opts: { targetId?: string; profile?: string } = {},
|
||||||
|
|||||||
11
src/browser/client-actions-url.ts
Normal file
11
src/browser/client-actions-url.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export function buildProfileQuery(profile?: string): string {
|
||||||
|
return profile ? `?profile=${encodeURIComponent(profile)}` : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function withBaseUrl(baseUrl: string | undefined, path: string): string {
|
||||||
|
const trimmed = baseUrl?.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
return `${trimmed.replace(/\/$/, "")}${path}`;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user