fix(browser): restore tsc types
This commit is contained in:
@@ -232,7 +232,12 @@ export async function fileUploadViaPlaywright(opts: {
|
|||||||
const timeout = Math.max(500, Math.min(60_000, opts.timeoutMs ?? 10_000));
|
const timeout = Math.max(500, Math.min(60_000, opts.timeoutMs ?? 10_000));
|
||||||
const fileChooser = await page.waitForEvent("filechooser", { timeout });
|
const fileChooser = await page.waitForEvent("filechooser", { timeout });
|
||||||
if (!opts.paths?.length) {
|
if (!opts.paths?.length) {
|
||||||
await fileChooser.cancel();
|
// Playwright removed `FileChooser.cancel()`; best-effort close the chooser instead.
|
||||||
|
try {
|
||||||
|
await page.keyboard.press("Escape");
|
||||||
|
} catch {
|
||||||
|
// Best-effort.
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fileChooser.setFiles(opts.paths);
|
await fileChooser.setFiles(opts.paths);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
|
|
||||||
const STATIC_RESOURCE_TYPES = new Set(["image", "font", "stylesheet", "media"]);
|
const STATIC_RESOURCE_TYPES = new Set(["image", "font", "stylesheet", "media"]);
|
||||||
|
|
||||||
const tracingContexts = new WeakSet<unknown>();
|
const tracingContexts = new WeakSet<object>();
|
||||||
|
|
||||||
function consolePriority(level: string) {
|
function consolePriority(level: string) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
|||||||
@@ -27,6 +27,29 @@ import {
|
|||||||
toStringOrEmpty,
|
toStringOrEmpty,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
|
|
||||||
|
type MouseButton = "left" | "right" | "middle";
|
||||||
|
type KeyboardModifier = "Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift";
|
||||||
|
|
||||||
|
function normalizeMouseButton(value: unknown): MouseButton | undefined {
|
||||||
|
const raw = toStringOrEmpty(value);
|
||||||
|
if (raw === "left" || raw === "right" || raw === "middle") return raw;
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeModifiers(value: unknown): KeyboardModifier[] | undefined {
|
||||||
|
const raw = toStringArray(value);
|
||||||
|
if (!raw?.length) return undefined;
|
||||||
|
const normalized = raw.filter(
|
||||||
|
(m): m is KeyboardModifier =>
|
||||||
|
m === "Alt" ||
|
||||||
|
m === "Control" ||
|
||||||
|
m === "ControlOrMeta" ||
|
||||||
|
m === "Meta" ||
|
||||||
|
m === "Shift",
|
||||||
|
);
|
||||||
|
return normalized.length ? normalized : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export type BrowserActionCore =
|
export type BrowserActionCore =
|
||||||
| "back"
|
| "back"
|
||||||
| "click"
|
| "click"
|
||||||
@@ -228,10 +251,8 @@ export async function handleBrowserActionCore(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const doubleClick = toBoolean(args.doubleClick) ?? false;
|
const doubleClick = toBoolean(args.doubleClick) ?? false;
|
||||||
const button = toStringOrEmpty(args.button) || undefined;
|
const button = normalizeMouseButton(args.button);
|
||||||
const modifiers = Array.isArray(args.modifiers)
|
const modifiers = normalizeModifiers(args.modifiers);
|
||||||
? (args.modifiers as string[])
|
|
||||||
: undefined;
|
|
||||||
const tab = await ctx.ensureTabAvailable(target);
|
const tab = await ctx.ensureTabAvailable(target);
|
||||||
await clickViaPlaywright({
|
await clickViaPlaywright({
|
||||||
cdpPort,
|
cdpPort,
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ import {
|
|||||||
toStringOrEmpty,
|
toStringOrEmpty,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
|
|
||||||
|
type MouseButton = "left" | "right" | "middle";
|
||||||
|
|
||||||
|
function normalizeMouseButton(value: unknown): MouseButton | undefined {
|
||||||
|
const raw = toStringOrEmpty(value);
|
||||||
|
if (raw === "left" || raw === "right" || raw === "middle") return raw;
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export type BrowserActionExtra =
|
export type BrowserActionExtra =
|
||||||
| "console"
|
| "console"
|
||||||
| "locator"
|
| "locator"
|
||||||
@@ -223,7 +231,7 @@ export async function handleBrowserActionExtra(
|
|||||||
jsonError(res, 400, "x and y are required");
|
jsonError(res, 400, "x and y are required");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const button = toStringOrEmpty(args.button) || undefined;
|
const button = normalizeMouseButton(args.button);
|
||||||
const tab = await ctx.ensureTabAvailable(target);
|
const tab = await ctx.ensureTabAvailable(target);
|
||||||
await mouseClickViaPlaywright({
|
await mouseClickViaPlaywright({
|
||||||
cdpPort,
|
cdpPort,
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ async function readStdin(): Promise<string> {
|
|||||||
const chunks: string[] = [];
|
const chunks: string[] = [];
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
process.stdin.setEncoding("utf8");
|
process.stdin.setEncoding("utf8");
|
||||||
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
process.stdin.on("data", (chunk) => chunks.push(String(chunk)));
|
||||||
process.stdin.on("end", () => resolve(chunks.join("")));
|
process.stdin.on("end", () => resolve(chunks.join("")));
|
||||||
process.stdin.on("error", reject);
|
process.stdin.on("error", reject);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ async function readStdin(): Promise<string> {
|
|||||||
const chunks: string[] = [];
|
const chunks: string[] = [];
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
process.stdin.setEncoding("utf8");
|
process.stdin.setEncoding("utf8");
|
||||||
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
process.stdin.on("data", (chunk) => chunks.push(String(chunk)));
|
||||||
process.stdin.on("end", () => resolve(chunks.join("")));
|
process.stdin.on("end", () => resolve(chunks.join("")));
|
||||||
process.stdin.on("error", reject);
|
process.stdin.on("error", reject);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -851,8 +851,7 @@ export async function monitorWebProvider(
|
|||||||
const tsDisplay = msg.timestamp
|
const tsDisplay = msg.timestamp
|
||||||
? new Date(msg.timestamp).toISOString()
|
? new Date(msg.timestamp).toISOString()
|
||||||
: new Date().toISOString();
|
: new Date().toISOString();
|
||||||
const fromDisplay =
|
const fromDisplay = msg.chatType === "group" ? conversationId : msg.from;
|
||||||
msg.chatType === "group" ? conversationId : msg.from;
|
|
||||||
console.log(
|
console.log(
|
||||||
`\n[${tsDisplay}] ${fromDisplay} -> ${msg.to}: ${combinedBody}`,
|
`\n[${tsDisplay}] ${fromDisplay} -> ${msg.to}: ${combinedBody}`,
|
||||||
);
|
);
|
||||||
@@ -956,9 +955,7 @@ export async function monitorWebProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fromDisplay =
|
const fromDisplay =
|
||||||
msg.chatType === "group"
|
msg.chatType === "group" ? conversationId : (msg.from ?? "unknown");
|
||||||
? conversationId
|
|
||||||
: (msg.from ?? "unknown");
|
|
||||||
if (isVerbose()) {
|
if (isVerbose()) {
|
||||||
console.log(
|
console.log(
|
||||||
success(
|
success(
|
||||||
|
|||||||
Reference in New Issue
Block a user