@wordbricks/playwright-mcp 0.1.22 → 0.1.23
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/package.json +6 -6
- package/lib/browserContextFactory.js +0 -399
- package/lib/browserServerBackend.js +0 -86
- package/lib/config.js +0 -300
- package/lib/context.js +0 -311
- package/lib/extension/cdpRelay.js +0 -352
- package/lib/extension/extensionContextFactory.js +0 -56
- package/lib/frameworkPatterns.js +0 -35
- package/lib/hooks/antiBotDetectionHook.js +0 -178
- package/lib/hooks/core.js +0 -145
- package/lib/hooks/eventConsumer.js +0 -52
- package/lib/hooks/events.js +0 -42
- package/lib/hooks/formatToolCallEvent.js +0 -12
- package/lib/hooks/frameworkStateHook.js +0 -182
- package/lib/hooks/grouping.js +0 -72
- package/lib/hooks/jsonLdDetectionHook.js +0 -182
- package/lib/hooks/networkFilters.js +0 -82
- package/lib/hooks/networkSetup.js +0 -61
- package/lib/hooks/networkTrackingHook.js +0 -67
- package/lib/hooks/pageHeightHook.js +0 -75
- package/lib/hooks/registry.js +0 -41
- package/lib/hooks/requireTabHook.js +0 -26
- package/lib/hooks/schema.js +0 -89
- package/lib/hooks/waitHook.js +0 -33
- package/lib/index.js +0 -41
- package/lib/mcp/inProcessTransport.js +0 -71
- package/lib/mcp/proxyBackend.js +0 -130
- package/lib/mcp/server.js +0 -91
- package/lib/mcp/tool.js +0 -44
- package/lib/mcp/transport.js +0 -188
- package/lib/playwrightTransformer.js +0 -520
- package/lib/program.js +0 -112
- package/lib/response.js +0 -192
- package/lib/sessionLog.js +0 -123
- package/lib/tab.js +0 -251
- package/lib/tools/common.js +0 -55
- package/lib/tools/console.js +0 -33
- package/lib/tools/dialogs.js +0 -50
- package/lib/tools/evaluate.js +0 -62
- package/lib/tools/extractFrameworkState.js +0 -225
- package/lib/tools/files.js +0 -48
- package/lib/tools/form.js +0 -66
- package/lib/tools/getSnapshot.js +0 -36
- package/lib/tools/getVisibleHtml.js +0 -68
- package/lib/tools/install.js +0 -51
- package/lib/tools/keyboard.js +0 -83
- package/lib/tools/mouse.js +0 -97
- package/lib/tools/navigate.js +0 -66
- package/lib/tools/network.js +0 -121
- package/lib/tools/networkDetail.js +0 -238
- package/lib/tools/networkSearch/bodySearch.js +0 -161
- package/lib/tools/networkSearch/grouping.js +0 -37
- package/lib/tools/networkSearch/helpers.js +0 -32
- package/lib/tools/networkSearch/searchHtml.js +0 -76
- package/lib/tools/networkSearch/types.js +0 -1
- package/lib/tools/networkSearch/urlSearch.js +0 -124
- package/lib/tools/networkSearch.js +0 -278
- package/lib/tools/pdf.js +0 -41
- package/lib/tools/repl.js +0 -414
- package/lib/tools/screenshot.js +0 -103
- package/lib/tools/scroll.js +0 -131
- package/lib/tools/snapshot.js +0 -161
- package/lib/tools/tabs.js +0 -62
- package/lib/tools/tool.js +0 -35
- package/lib/tools/utils.js +0 -78
- package/lib/tools/wait.js +0 -60
- package/lib/tools.js +0 -68
- package/lib/utils/adBlockFilter.js +0 -90
- package/lib/utils/codegen.js +0 -55
- package/lib/utils/extensionPath.js +0 -10
- package/lib/utils/fileUtils.js +0 -40
- package/lib/utils/graphql.js +0 -269
- package/lib/utils/guid.js +0 -22
- package/lib/utils/httpServer.js +0 -39
- package/lib/utils/log.js +0 -21
- package/lib/utils/manualPromise.js +0 -111
- package/lib/utils/networkFormat.js +0 -14
- package/lib/utils/package.js +0 -20
- package/lib/utils/result.js +0 -2
- package/lib/utils/sanitizeHtml.js +0 -130
- package/lib/utils/truncate.js +0 -103
- package/lib/utils/withTimeout.js +0 -7
- package/src/index.ts +0 -60
package/lib/utils/truncate.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
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/lib/utils/withTimeout.js
DELETED
package/src/index.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import type { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
18
|
-
import type { BrowserContext } from "playwright-core";
|
|
19
|
-
import type { Config } from "../config.js";
|
|
20
|
-
import type { BrowserContextFactory } from "./browserContextFactory.js";
|
|
21
|
-
import { contextFactory } from "./browserContextFactory.js";
|
|
22
|
-
import { BrowserServerBackend } from "./browserServerBackend.js";
|
|
23
|
-
import { resolveConfig } from "./config.js";
|
|
24
|
-
import * as mcpServer from "./mcp/server.js";
|
|
25
|
-
|
|
26
|
-
export async function createConnection(
|
|
27
|
-
userConfig?: Config,
|
|
28
|
-
contextGetter?: () => Promise<BrowserContext>,
|
|
29
|
-
): Promise<Server> {
|
|
30
|
-
const config = await resolveConfig(userConfig || {});
|
|
31
|
-
const factory = contextGetter
|
|
32
|
-
? new SimpleBrowserContextFactory(contextGetter)
|
|
33
|
-
: contextFactory(config);
|
|
34
|
-
return mcpServer.createServer(
|
|
35
|
-
new BrowserServerBackend(config, factory),
|
|
36
|
-
false,
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class SimpleBrowserContextFactory implements BrowserContextFactory {
|
|
41
|
-
name = "custom";
|
|
42
|
-
description = "Connect to a browser using a custom context getter";
|
|
43
|
-
|
|
44
|
-
private readonly _contextGetter: () => Promise<BrowserContext>;
|
|
45
|
-
|
|
46
|
-
constructor(contextGetter: () => Promise<BrowserContext>) {
|
|
47
|
-
this._contextGetter = contextGetter;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async createContext(): Promise<{
|
|
51
|
-
browserContext: BrowserContext;
|
|
52
|
-
close: () => Promise<void>;
|
|
53
|
-
}> {
|
|
54
|
-
const browserContext = await this._contextGetter();
|
|
55
|
-
return {
|
|
56
|
-
browserContext,
|
|
57
|
-
close: () => browserContext.close(),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|