@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.
Files changed (83) hide show
  1. package/package.json +6 -6
  2. package/lib/browserContextFactory.js +0 -399
  3. package/lib/browserServerBackend.js +0 -86
  4. package/lib/config.js +0 -300
  5. package/lib/context.js +0 -311
  6. package/lib/extension/cdpRelay.js +0 -352
  7. package/lib/extension/extensionContextFactory.js +0 -56
  8. package/lib/frameworkPatterns.js +0 -35
  9. package/lib/hooks/antiBotDetectionHook.js +0 -178
  10. package/lib/hooks/core.js +0 -145
  11. package/lib/hooks/eventConsumer.js +0 -52
  12. package/lib/hooks/events.js +0 -42
  13. package/lib/hooks/formatToolCallEvent.js +0 -12
  14. package/lib/hooks/frameworkStateHook.js +0 -182
  15. package/lib/hooks/grouping.js +0 -72
  16. package/lib/hooks/jsonLdDetectionHook.js +0 -182
  17. package/lib/hooks/networkFilters.js +0 -82
  18. package/lib/hooks/networkSetup.js +0 -61
  19. package/lib/hooks/networkTrackingHook.js +0 -67
  20. package/lib/hooks/pageHeightHook.js +0 -75
  21. package/lib/hooks/registry.js +0 -41
  22. package/lib/hooks/requireTabHook.js +0 -26
  23. package/lib/hooks/schema.js +0 -89
  24. package/lib/hooks/waitHook.js +0 -33
  25. package/lib/index.js +0 -41
  26. package/lib/mcp/inProcessTransport.js +0 -71
  27. package/lib/mcp/proxyBackend.js +0 -130
  28. package/lib/mcp/server.js +0 -91
  29. package/lib/mcp/tool.js +0 -44
  30. package/lib/mcp/transport.js +0 -188
  31. package/lib/playwrightTransformer.js +0 -520
  32. package/lib/program.js +0 -112
  33. package/lib/response.js +0 -192
  34. package/lib/sessionLog.js +0 -123
  35. package/lib/tab.js +0 -251
  36. package/lib/tools/common.js +0 -55
  37. package/lib/tools/console.js +0 -33
  38. package/lib/tools/dialogs.js +0 -50
  39. package/lib/tools/evaluate.js +0 -62
  40. package/lib/tools/extractFrameworkState.js +0 -225
  41. package/lib/tools/files.js +0 -48
  42. package/lib/tools/form.js +0 -66
  43. package/lib/tools/getSnapshot.js +0 -36
  44. package/lib/tools/getVisibleHtml.js +0 -68
  45. package/lib/tools/install.js +0 -51
  46. package/lib/tools/keyboard.js +0 -83
  47. package/lib/tools/mouse.js +0 -97
  48. package/lib/tools/navigate.js +0 -66
  49. package/lib/tools/network.js +0 -121
  50. package/lib/tools/networkDetail.js +0 -238
  51. package/lib/tools/networkSearch/bodySearch.js +0 -161
  52. package/lib/tools/networkSearch/grouping.js +0 -37
  53. package/lib/tools/networkSearch/helpers.js +0 -32
  54. package/lib/tools/networkSearch/searchHtml.js +0 -76
  55. package/lib/tools/networkSearch/types.js +0 -1
  56. package/lib/tools/networkSearch/urlSearch.js +0 -124
  57. package/lib/tools/networkSearch.js +0 -278
  58. package/lib/tools/pdf.js +0 -41
  59. package/lib/tools/repl.js +0 -414
  60. package/lib/tools/screenshot.js +0 -103
  61. package/lib/tools/scroll.js +0 -131
  62. package/lib/tools/snapshot.js +0 -161
  63. package/lib/tools/tabs.js +0 -62
  64. package/lib/tools/tool.js +0 -35
  65. package/lib/tools/utils.js +0 -78
  66. package/lib/tools/wait.js +0 -60
  67. package/lib/tools.js +0 -68
  68. package/lib/utils/adBlockFilter.js +0 -90
  69. package/lib/utils/codegen.js +0 -55
  70. package/lib/utils/extensionPath.js +0 -10
  71. package/lib/utils/fileUtils.js +0 -40
  72. package/lib/utils/graphql.js +0 -269
  73. package/lib/utils/guid.js +0 -22
  74. package/lib/utils/httpServer.js +0 -39
  75. package/lib/utils/log.js +0 -21
  76. package/lib/utils/manualPromise.js +0 -111
  77. package/lib/utils/networkFormat.js +0 -14
  78. package/lib/utils/package.js +0 -20
  79. package/lib/utils/result.js +0 -2
  80. package/lib/utils/sanitizeHtml.js +0 -130
  81. package/lib/utils/truncate.js +0 -103
  82. package/lib/utils/withTimeout.js +0 -7
  83. package/src/index.ts +0 -60
@@ -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
- };
@@ -1,7 +0,0 @@
1
- // Helper to safely execute a promise with timeout
2
- export const withTimeout = async (promise, ms) => {
3
- return Promise.race([
4
- promise,
5
- new Promise((_, reject) => setTimeout(() => reject(new Error("Timeout")), ms)),
6
- ]);
7
- };
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
- }