mcp-browser-dev-tools 0.0.1-beta.4 → 0.0.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/browser-launcher.mjs +3 -0
- package/src/cli.mjs +11 -5
- package/src/page-context.mjs +18 -3
package/README.md
CHANGED
package/package.json
CHANGED
package/src/browser-launcher.mjs
CHANGED
|
@@ -149,6 +149,9 @@ export function buildBrowserLaunchArgs({
|
|
|
149
149
|
|
|
150
150
|
const args = [];
|
|
151
151
|
if (family === "firefox") {
|
|
152
|
+
if (userDataDir) {
|
|
153
|
+
args.push("-new-instance", "-profile", userDataDir);
|
|
154
|
+
}
|
|
152
155
|
if (remoteDebuggingPort) {
|
|
153
156
|
args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
|
|
154
157
|
}
|
package/src/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdir } from "node:fs/promises";
|
|
3
4
|
import process from "node:process";
|
|
4
5
|
import { pathToFileURL } from "node:url";
|
|
5
6
|
|
|
@@ -68,7 +69,7 @@ function printUsage() {
|
|
|
68
69
|
" --family <name> chromium or firefox",
|
|
69
70
|
" --port <port> remote debugging port",
|
|
70
71
|
" --address <host> remote debugging address for Chromium",
|
|
71
|
-
" --user-data-dir <p> optional
|
|
72
|
+
" --user-data-dir <p> optional Chromium user data dir or Firefox profile dir",
|
|
72
73
|
" --wait-ms <ms> wait for the debug endpoint and print doctor output",
|
|
73
74
|
" --no-doctor skip the post-launch doctor check",
|
|
74
75
|
"",
|
|
@@ -156,16 +157,21 @@ async function runOpen(positional, options) {
|
|
|
156
157
|
: new URL(config.cdpBaseUrl).port || "9222";
|
|
157
158
|
const resolvedPort =
|
|
158
159
|
typeof options.port === "string" ? options.port : defaultPort;
|
|
160
|
+
const userDataDir =
|
|
161
|
+
typeof options["user-data-dir"] === "string"
|
|
162
|
+
? options["user-data-dir"]
|
|
163
|
+
: undefined;
|
|
164
|
+
|
|
165
|
+
if (family === "firefox" && userDataDir) {
|
|
166
|
+
await mkdir(userDataDir, { recursive: true });
|
|
167
|
+
}
|
|
159
168
|
|
|
160
169
|
const args = buildBrowserLaunchArgs({
|
|
161
170
|
family,
|
|
162
171
|
url,
|
|
163
172
|
remoteDebuggingPort: resolvedPort,
|
|
164
173
|
remoteDebuggingAddress: requestedAddress || undefined,
|
|
165
|
-
userDataDir
|
|
166
|
-
family === "chromium" && typeof options["user-data-dir"] === "string"
|
|
167
|
-
? options["user-data-dir"]
|
|
168
|
-
: undefined,
|
|
174
|
+
userDataDir,
|
|
169
175
|
});
|
|
170
176
|
|
|
171
177
|
const child = spawn(executable, args, {
|
package/src/page-context.mjs
CHANGED
|
@@ -214,6 +214,21 @@ export function buildPageContextExpression(
|
|
|
214
214
|
);
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
function summarizeLocator(locator) {
|
|
218
|
+
if (!locator || typeof locator !== "object") {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const summary = {};
|
|
223
|
+
for (const key of ["locator", "strategy", "query", "role", "name", "error"]) {
|
|
224
|
+
if (locator[key] !== undefined) {
|
|
225
|
+
summary[key] = locator[key];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return summary;
|
|
230
|
+
}
|
|
231
|
+
|
|
217
232
|
function describeElement(element, locator) {
|
|
218
233
|
const rect = element.getBoundingClientRect();
|
|
219
234
|
const style = getComputedStyle(element);
|
|
@@ -221,7 +236,7 @@ export function buildPageContextExpression(
|
|
|
221
236
|
const accessibleName = getAccessibleName(element);
|
|
222
237
|
|
|
223
238
|
return {
|
|
224
|
-
locator,
|
|
239
|
+
locator: summarizeLocator(locator),
|
|
225
240
|
tagName: element.tagName,
|
|
226
241
|
id: element.getAttribute("id"),
|
|
227
242
|
className: element.getAttribute("class"),
|
|
@@ -413,7 +428,7 @@ export function buildPageContextExpression(
|
|
|
413
428
|
browserFamily: payload.browserFamily,
|
|
414
429
|
selector: rawLocator,
|
|
415
430
|
found: false,
|
|
416
|
-
locator: resolved,
|
|
431
|
+
locator: summarizeLocator(resolved),
|
|
417
432
|
error: resolved.error,
|
|
418
433
|
};
|
|
419
434
|
}
|
|
@@ -423,7 +438,7 @@ export function buildPageContextExpression(
|
|
|
423
438
|
browserFamily: payload.browserFamily,
|
|
424
439
|
selector: rawLocator,
|
|
425
440
|
found: false,
|
|
426
|
-
locator: resolved,
|
|
441
|
+
locator: summarizeLocator(resolved),
|
|
427
442
|
};
|
|
428
443
|
}
|
|
429
444
|
|