chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -32,9 +32,7 @@ export async function captureScreenshot(opts: {
|
||||
return await withCdpSocket(opts.wsUrl, async (send) => {
|
||||
await send("Page.enable");
|
||||
|
||||
let clip:
|
||||
| { x: number; y: number; width: number; height: number; scale: number }
|
||||
| undefined;
|
||||
let clip: { x: number; y: number; width: number; height: number; scale: number } | undefined;
|
||||
if (opts.fullPage) {
|
||||
const metrics = (await send("Page.getLayoutMetrics")) as {
|
||||
cssContentSize?: { width?: number; height?: number };
|
||||
@@ -50,9 +48,7 @@ export async function captureScreenshot(opts: {
|
||||
|
||||
const format = opts.format ?? "png";
|
||||
const quality =
|
||||
format === "jpeg"
|
||||
? Math.max(0, Math.min(100, Math.round(opts.quality ?? 85)))
|
||||
: undefined;
|
||||
format === "jpeg" ? Math.max(0, Math.min(100, Math.round(opts.quality ?? 85))) : undefined;
|
||||
|
||||
const result = (await send("Page.captureScreenshot", {
|
||||
format,
|
||||
@@ -73,10 +69,7 @@ export async function createTargetViaCdp(opts: {
|
||||
url: string;
|
||||
}): Promise<{ targetId: string }> {
|
||||
const base = opts.cdpUrl.replace(/\/$/, "");
|
||||
const version = await fetchJson<{ webSocketDebuggerUrl?: string }>(
|
||||
`${base}/json/version`,
|
||||
1500,
|
||||
);
|
||||
const version = await fetchJson<{ webSocketDebuggerUrl?: string }>(`${base}/json/version`, 1500);
|
||||
const wsUrlRaw = String(version?.webSocketDebuggerUrl ?? "").trim();
|
||||
const wsUrl = wsUrlRaw ? normalizeCdpWsUrl(wsUrlRaw, opts.cdpUrl) : "";
|
||||
if (!wsUrl) throw new Error("CDP /json/version missing webSocketDebuggerUrl");
|
||||
@@ -86,8 +79,7 @@ export async function createTargetViaCdp(opts: {
|
||||
targetId?: string;
|
||||
};
|
||||
const targetId = String(created?.targetId ?? "").trim();
|
||||
if (!targetId)
|
||||
throw new Error("CDP Target.createTarget returned no targetId");
|
||||
if (!targetId) throw new Error("CDP Target.createTarget returned no targetId");
|
||||
return { targetId };
|
||||
});
|
||||
}
|
||||
@@ -167,10 +159,7 @@ function axValue(v: unknown): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
function formatAriaSnapshot(
|
||||
nodes: RawAXNode[],
|
||||
limit: number,
|
||||
): AriaSnapshotNode[] {
|
||||
function formatAriaSnapshot(nodes: RawAXNode[], limit: number): AriaSnapshotNode[] {
|
||||
const byId = new Map<string, RawAXNode>();
|
||||
for (const n of nodes) {
|
||||
if (n.nodeId) byId.set(n.nodeId, n);
|
||||
@@ -181,14 +170,11 @@ function formatAriaSnapshot(
|
||||
for (const n of nodes) {
|
||||
for (const c of n.childIds ?? []) referenced.add(c);
|
||||
}
|
||||
const root =
|
||||
nodes.find((n) => n.nodeId && !referenced.has(n.nodeId)) ?? nodes[0];
|
||||
const root = nodes.find((n) => n.nodeId && !referenced.has(n.nodeId)) ?? nodes[0];
|
||||
if (!root?.nodeId) return [];
|
||||
|
||||
const out: AriaSnapshotNode[] = [];
|
||||
const stack: Array<{ id: string; depth: number }> = [
|
||||
{ id: root.nodeId, depth: 0 },
|
||||
];
|
||||
const stack: Array<{ id: string; depth: number }> = [{ id: root.nodeId, depth: 0 }];
|
||||
while (stack.length && out.length < limit) {
|
||||
const popped = stack.pop();
|
||||
if (!popped) break;
|
||||
@@ -206,9 +192,7 @@ function formatAriaSnapshot(
|
||||
name: name || "",
|
||||
...(value ? { value } : {}),
|
||||
...(description ? { description } : {}),
|
||||
...(typeof n.backendDOMNodeId === "number"
|
||||
? { backendDOMNodeId: n.backendDOMNodeId }
|
||||
: {}),
|
||||
...(typeof n.backendDOMNodeId === "number" ? { backendDOMNodeId: n.backendDOMNodeId } : {}),
|
||||
depth,
|
||||
});
|
||||
|
||||
@@ -245,10 +229,7 @@ export async function snapshotDom(opts: {
|
||||
nodes: DomSnapshotNode[];
|
||||
}> {
|
||||
const limit = Math.max(1, Math.min(5000, Math.floor(opts.limit ?? 800)));
|
||||
const maxTextChars = Math.max(
|
||||
0,
|
||||
Math.min(5000, Math.floor(opts.maxTextChars ?? 220)),
|
||||
);
|
||||
const maxTextChars = Math.max(0, Math.min(5000, Math.floor(opts.maxTextChars ?? 220)));
|
||||
|
||||
const expression = `(() => {
|
||||
const maxNodes = ${JSON.stringify(limit)};
|
||||
@@ -328,10 +309,7 @@ export async function getDomText(opts: {
|
||||
maxChars?: number;
|
||||
selector?: string;
|
||||
}): Promise<{ text: string }> {
|
||||
const maxChars = Math.max(
|
||||
0,
|
||||
Math.min(5_000_000, Math.floor(opts.maxChars ?? 200_000)),
|
||||
);
|
||||
const maxChars = Math.max(0, Math.min(5_000_000, Math.floor(opts.maxChars ?? 200_000)));
|
||||
const selectorExpr = opts.selector ? JSON.stringify(opts.selector) : "null";
|
||||
const expression = `(() => {
|
||||
const fmt = ${JSON.stringify(opts.format)};
|
||||
@@ -376,14 +354,8 @@ export async function querySelector(opts: {
|
||||
matches: QueryMatch[];
|
||||
}> {
|
||||
const limit = Math.max(1, Math.min(200, Math.floor(opts.limit ?? 20)));
|
||||
const maxText = Math.max(
|
||||
0,
|
||||
Math.min(5000, Math.floor(opts.maxTextChars ?? 500)),
|
||||
);
|
||||
const maxHtml = Math.max(
|
||||
0,
|
||||
Math.min(20000, Math.floor(opts.maxHtmlChars ?? 1500)),
|
||||
);
|
||||
const maxText = Math.max(0, Math.min(5000, Math.floor(opts.maxTextChars ?? 500)));
|
||||
const maxHtml = Math.max(0, Math.min(20000, Math.floor(opts.maxHtmlChars ?? 1500)));
|
||||
|
||||
const expression = `(() => {
|
||||
const sel = ${JSON.stringify(opts.selector)};
|
||||
|
||||
Reference in New Issue
Block a user