@wordbricks/playwright-mcp 0.1.25 → 0.1.27
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/lib/browserContextFactory.js +616 -0
- package/lib/browserServerBackend.js +86 -0
- package/lib/config.js +302 -0
- package/lib/context.js +320 -0
- package/lib/extension/cdpRelay.js +352 -0
- package/lib/extension/extensionContextFactory.js +56 -0
- package/lib/frameworkPatterns.js +35 -0
- package/lib/hooks/antiBotDetectionHook.js +178 -0
- package/lib/hooks/core.js +145 -0
- package/lib/hooks/eventConsumer.js +52 -0
- package/lib/hooks/events.js +42 -0
- package/lib/hooks/formatToolCallEvent.js +12 -0
- package/lib/hooks/frameworkStateHook.js +182 -0
- package/lib/hooks/grouping.js +72 -0
- package/lib/hooks/jsonLdDetectionHook.js +182 -0
- package/lib/hooks/networkFilters.js +82 -0
- package/lib/hooks/networkSetup.js +61 -0
- package/lib/hooks/networkTrackingHook.js +67 -0
- package/lib/hooks/pageHeightHook.js +75 -0
- package/lib/hooks/registry.js +41 -0
- package/lib/hooks/requireTabHook.js +26 -0
- package/lib/hooks/schema.js +89 -0
- package/lib/hooks/waitHook.js +33 -0
- package/lib/index.js +41 -0
- package/lib/mcp/inProcessTransport.js +71 -0
- package/lib/mcp/proxyBackend.js +130 -0
- package/lib/mcp/server.js +91 -0
- package/lib/mcp/tool.js +44 -0
- package/lib/mcp/transport.js +188 -0
- package/lib/playwrightTransformer.js +520 -0
- package/lib/program.js +112 -0
- package/lib/response.js +192 -0
- package/lib/sessionLog.js +123 -0
- package/lib/tab.js +251 -0
- package/lib/tools/common.js +55 -0
- package/lib/tools/console.js +33 -0
- package/lib/tools/dialogs.js +50 -0
- package/lib/tools/evaluate.js +62 -0
- package/lib/tools/extractFrameworkState.js +225 -0
- package/lib/tools/files.js +48 -0
- package/lib/tools/form.js +66 -0
- package/lib/tools/getSnapshot.js +36 -0
- package/lib/tools/getVisibleHtml.js +68 -0
- package/lib/tools/install.js +51 -0
- package/lib/tools/keyboard.js +83 -0
- package/lib/tools/mouse.js +97 -0
- package/lib/tools/navigate.js +66 -0
- package/lib/tools/network.js +121 -0
- package/lib/tools/networkDetail.js +238 -0
- package/lib/tools/networkSearch/bodySearch.js +161 -0
- package/lib/tools/networkSearch/grouping.js +37 -0
- package/lib/tools/networkSearch/helpers.js +32 -0
- package/lib/tools/networkSearch/searchHtml.js +76 -0
- package/lib/tools/networkSearch/types.js +1 -0
- package/lib/tools/networkSearch/urlSearch.js +124 -0
- package/lib/tools/networkSearch.js +278 -0
- package/lib/tools/pdf.js +41 -0
- package/lib/tools/repl.js +414 -0
- package/lib/tools/screenshot.js +103 -0
- package/lib/tools/scroll.js +131 -0
- package/lib/tools/snapshot.js +161 -0
- package/lib/tools/tabs.js +62 -0
- package/lib/tools/tool.js +35 -0
- package/lib/tools/utils.js +78 -0
- package/lib/tools/wait.js +60 -0
- package/lib/tools.js +68 -0
- package/lib/utils/adBlockFilter.js +90 -0
- package/lib/utils/codegen.js +55 -0
- package/lib/utils/extensionPath.js +10 -0
- package/lib/utils/fileUtils.js +40 -0
- package/lib/utils/graphql.js +269 -0
- package/lib/utils/guid.js +22 -0
- package/lib/utils/httpServer.js +39 -0
- package/lib/utils/log.js +21 -0
- package/lib/utils/manualPromise.js +111 -0
- package/lib/utils/networkFormat.js +14 -0
- package/lib/utils/package.js +20 -0
- package/lib/utils/result.js +2 -0
- package/lib/utils/sanitizeHtml.js +130 -0
- package/lib/utils/truncate.js +103 -0
- package/lib/utils/withTimeout.js +7 -0
- package/package.json +11 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for truncating values for display
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Recursively truncate values for display, limiting strings, arrays, and object keys at each depth level
|
|
6
|
+
*/
|
|
7
|
+
export const truncate = (value, options) => {
|
|
8
|
+
const { maxStringLength = 100, maxItems = 10 } = options ?? {};
|
|
9
|
+
if (typeof value === "string") {
|
|
10
|
+
if (value.length > maxStringLength)
|
|
11
|
+
return value.substring(0, Math.max(0, maxStringLength - 3)) + "...";
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
const limited = maxItems !== undefined ? value.slice(0, maxItems) : value;
|
|
16
|
+
return limited.map((v) => truncate(v, options));
|
|
17
|
+
}
|
|
18
|
+
if (value && typeof value === "object") {
|
|
19
|
+
let entries = Object.entries(value);
|
|
20
|
+
if (maxItems !== undefined)
|
|
21
|
+
entries = entries.slice(0, maxItems);
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const [key, val] of entries)
|
|
24
|
+
out[key] = truncate(val, options);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
export const truncateStringTo = (text, max) => {
|
|
30
|
+
if (max <= 0)
|
|
31
|
+
return { text: "", truncated: text.length > 0 };
|
|
32
|
+
if (text.length <= max)
|
|
33
|
+
return { text, truncated: false };
|
|
34
|
+
const sliceLen = Math.max(0, max - 3);
|
|
35
|
+
return { text: text.slice(0, sliceLen) + "...", truncated: true };
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Create a standardized truncation note like:
|
|
39
|
+
* … [truncated: showing 120/500 chars (24%)]
|
|
40
|
+
* Caller may optionally provide a formatter (e.g. bytes -> "8 KB") and/or units label.
|
|
41
|
+
*/
|
|
42
|
+
export const formatTruncationLine = (shown, total, options) => {
|
|
43
|
+
const { units, formatter } = options ?? {};
|
|
44
|
+
const pct = total ? Math.round((shown / total) * 100) : 0;
|
|
45
|
+
const shownStr = formatter ? formatter(shown) : String(shown);
|
|
46
|
+
const totalStr = formatter ? formatter(total) : String(total);
|
|
47
|
+
const unitsPart = units ? ` ${units}` : "";
|
|
48
|
+
return `… [truncated: showing ${shownStr}/${totalStr}${unitsPart} (${pct}%)]`;
|
|
49
|
+
};
|
|
50
|
+
export const trimLeafValuesDeep = (value, maxChars) => {
|
|
51
|
+
if (value === null || value === undefined)
|
|
52
|
+
return value;
|
|
53
|
+
if (typeof value === "string")
|
|
54
|
+
return value.length > maxChars ? value.slice(0, maxChars) + "..." : value;
|
|
55
|
+
if (Array.isArray(value))
|
|
56
|
+
return value.map((v) => trimLeafValuesDeep(v, maxChars));
|
|
57
|
+
if (typeof value === "object") {
|
|
58
|
+
const out = {};
|
|
59
|
+
for (const [k, v] of Object.entries(value))
|
|
60
|
+
out[k] = trimLeafValuesDeep(v, maxChars);
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
export const trimJsonLeafValues = (input, maxChars) => {
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(input);
|
|
68
|
+
const trimmed = trimLeafValuesDeep(parsed, maxChars);
|
|
69
|
+
return JSON.stringify(trimmed);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return input.length > maxChars ? input.slice(0, maxChars) + "..." : input;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export const toJsonPathNormalized = (path) => {
|
|
76
|
+
let root = null;
|
|
77
|
+
if (path.startsWith("response.body."))
|
|
78
|
+
root = "response.body";
|
|
79
|
+
else if (path.startsWith("request.body."))
|
|
80
|
+
root = "request.body";
|
|
81
|
+
else
|
|
82
|
+
return null;
|
|
83
|
+
let p = path.slice(root.length + 1);
|
|
84
|
+
if (p.includes(" > ") || p.includes("@"))
|
|
85
|
+
return null;
|
|
86
|
+
p = p.replace(/\.\*/g, "[*]");
|
|
87
|
+
p = p.replace(/\.(\d+)(?=\.|$)/g, "[$1]");
|
|
88
|
+
return { root, jsonPath: `$.${p}` };
|
|
89
|
+
};
|
|
90
|
+
export const toJsonPathOriginal = (path) => {
|
|
91
|
+
let root = null;
|
|
92
|
+
if (path.startsWith("response.body."))
|
|
93
|
+
root = "response.body";
|
|
94
|
+
else if (path.startsWith("request.body."))
|
|
95
|
+
root = "request.body";
|
|
96
|
+
else
|
|
97
|
+
return null;
|
|
98
|
+
let p = path.slice(root.length + 1);
|
|
99
|
+
if (p.includes(" > ") || p.includes("@"))
|
|
100
|
+
return null;
|
|
101
|
+
p = p.replace(/\.(\d+)(?=\.|$)/g, "[$1]");
|
|
102
|
+
return { root, jsonPath: `$.${p}` };
|
|
103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordbricks/playwright-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "Playwright Tools for MCP",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib/**/*.js",
|
|
8
|
+
"lib/**/*.json",
|
|
9
|
+
"lib/**/*.txt",
|
|
10
|
+
"cli.js",
|
|
11
|
+
"cli-wrapper.js",
|
|
12
|
+
"index.js",
|
|
13
|
+
"index.d.ts",
|
|
14
|
+
"config.d.ts"
|
|
15
|
+
],
|
|
6
16
|
"scripts": {
|
|
7
17
|
"postinstall": "echo 'Skipping filter download during install. Run bun src/scripts/downloadFilters.ts manually if needed.'",
|
|
8
18
|
"build": "tsc && bun run copy-filters",
|