Files
skald-connectors/connectors/playwright/verify.js
T
Daniele fa8bbcb808 add playwright connector (v1 / 1.0.0) + commit pending docs reorganization
- new global mcp_local connector wrapping @playwright/mcp@0.0.79:
  index.js argv wrapper (--headless --isolated --no-sandbox) importing
  the package cli.js, postinstall downloads chromium-only browser,
  verify.js headless-launch probe, 24 tools with display names
- also carries the pending docs work: changelog extracted to
  CHANGELOG.md, manifest guide, SKALD.md/CLAUDE.md updates
2026-08-19 17:37:13 +01:00

54 lines
1.9 KiB
JavaScript

// Verify-before-save probe for the Playwright connector.
//
// Prints exactly ONE JSON object on stdout:
// {"ok": bool, "message": string, "details"?: object}
// Exit code 0 on success, 1 on failure. All diagnostics go to stderr.
//
// This connector has no credentials; what can actually break at runtime is
// the Chromium side: the binary must be present and launchable headless in
// this environment (system libraries, sandbox restrictions). The probe
// launches a real headless Chromium on about:blank and closes it.
import { createRequire } from "node:module";
import { existsSync } from "node:fs";
import { basename } from "node:path";
const require = createRequire(import.meta.url);
const finish = (ok, message, details) => {
const out = { ok, message };
if (details) out.details = details;
process.stdout.write(JSON.stringify(out) + "\n");
process.exit(ok ? 0 : 1);
};
let chromium;
let executablePath;
try {
// Resolve playwright-core relative to @playwright/mcp (it is a dependency
// of the pinned package, not of this connector's package.json).
const mcpRequire = createRequire(require.resolve("@playwright/mcp/package.json"));
({ chromium } = mcpRequire("playwright-core"));
executablePath = chromium.executablePath();
} catch (e) {
finish(false, `Cannot resolve the Playwright installation: ${e.message}`);
}
if (!existsSync(executablePath)) {
finish(false, "The Chromium binary is not installed. Reinstall the connector dependencies (the postinstall step downloads it).", { executablePath });
}
let browser;
try {
browser = await chromium.launch({ headless: true, args: ["--no-sandbox"] });
} catch (e) {
finish(false, `Chromium failed to launch: ${String(e.message).split("\n")[0]}`, { executablePath });
}
try {
const page = await browser.newPage();
await page.goto("about:blank");
finish(true, `Chromium launched headless successfully (${basename(executablePath)}).`);
} finally {
await browser.close().catch(() => {});
}