@wordbricks/playwright-mcp 0.1.20 → 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 (89) hide show
  1. package/cli-wrapper.js +15 -14
  2. package/cli.js +1 -1
  3. package/config.d.ts +11 -6
  4. package/index.d.ts +7 -5
  5. package/index.js +1 -1
  6. package/package.json +34 -57
  7. package/LICENSE +0 -202
  8. package/lib/browserContextFactory.js +0 -326
  9. package/lib/browserServerBackend.js +0 -84
  10. package/lib/config.js +0 -286
  11. package/lib/context.js +0 -309
  12. package/lib/extension/cdpRelay.js +0 -346
  13. package/lib/extension/extensionContextFactory.js +0 -56
  14. package/lib/frameworkPatterns.js +0 -35
  15. package/lib/hooks/antiBotDetectionHook.js +0 -171
  16. package/lib/hooks/core.js +0 -144
  17. package/lib/hooks/eventConsumer.js +0 -52
  18. package/lib/hooks/events.js +0 -42
  19. package/lib/hooks/formatToolCallEvent.js +0 -16
  20. package/lib/hooks/frameworkStateHook.js +0 -182
  21. package/lib/hooks/grouping.js +0 -72
  22. package/lib/hooks/jsonLdDetectionHook.js +0 -175
  23. package/lib/hooks/networkFilters.js +0 -82
  24. package/lib/hooks/networkSetup.js +0 -59
  25. package/lib/hooks/networkTrackingHook.js +0 -67
  26. package/lib/hooks/pageHeightHook.js +0 -75
  27. package/lib/hooks/registry.js +0 -42
  28. package/lib/hooks/requireTabHook.js +0 -26
  29. package/lib/hooks/schema.js +0 -89
  30. package/lib/hooks/waitHook.js +0 -33
  31. package/lib/index.js +0 -39
  32. package/lib/mcp/inProcessTransport.js +0 -72
  33. package/lib/mcp/proxyBackend.js +0 -115
  34. package/lib/mcp/server.js +0 -86
  35. package/lib/mcp/tool.js +0 -38
  36. package/lib/mcp/transport.js +0 -181
  37. package/lib/playwrightTransformer.js +0 -497
  38. package/lib/program.js +0 -110
  39. package/lib/response.js +0 -186
  40. package/lib/sessionLog.js +0 -121
  41. package/lib/tab.js +0 -249
  42. package/lib/tools/common.js +0 -55
  43. package/lib/tools/console.js +0 -33
  44. package/lib/tools/dialogs.js +0 -47
  45. package/lib/tools/evaluate.js +0 -53
  46. package/lib/tools/extractFrameworkState.js +0 -214
  47. package/lib/tools/files.js +0 -45
  48. package/lib/tools/form.js +0 -57
  49. package/lib/tools/getSnapshot.js +0 -37
  50. package/lib/tools/getVisibleHtml.js +0 -52
  51. package/lib/tools/install.js +0 -51
  52. package/lib/tools/keyboard.js +0 -78
  53. package/lib/tools/mouse.js +0 -99
  54. package/lib/tools/navigate.js +0 -70
  55. package/lib/tools/network.js +0 -123
  56. package/lib/tools/networkDetail.js +0 -229
  57. package/lib/tools/networkSearch/bodySearch.js +0 -147
  58. package/lib/tools/networkSearch/grouping.js +0 -28
  59. package/lib/tools/networkSearch/helpers.js +0 -32
  60. package/lib/tools/networkSearch/searchHtml.js +0 -67
  61. package/lib/tools/networkSearch/types.js +0 -1
  62. package/lib/tools/networkSearch/urlSearch.js +0 -82
  63. package/lib/tools/networkSearch.js +0 -268
  64. package/lib/tools/pdf.js +0 -40
  65. package/lib/tools/repl.js +0 -402
  66. package/lib/tools/screenshot.js +0 -79
  67. package/lib/tools/scroll.js +0 -126
  68. package/lib/tools/snapshot.js +0 -144
  69. package/lib/tools/tabs.js +0 -59
  70. package/lib/tools/tool.js +0 -33
  71. package/lib/tools/utils.js +0 -74
  72. package/lib/tools/wait.js +0 -55
  73. package/lib/tools.js +0 -67
  74. package/lib/utils/adBlockFilter.js +0 -87
  75. package/lib/utils/codegen.js +0 -51
  76. package/lib/utils/extensionPath.js +0 -10
  77. package/lib/utils/fileUtils.js +0 -36
  78. package/lib/utils/graphql.js +0 -258
  79. package/lib/utils/guid.js +0 -22
  80. package/lib/utils/httpServer.js +0 -39
  81. package/lib/utils/log.js +0 -21
  82. package/lib/utils/manualPromise.js +0 -111
  83. package/lib/utils/networkFormat.js +0 -12
  84. package/lib/utils/package.js +0 -20
  85. package/lib/utils/result.js +0 -2
  86. package/lib/utils/sanitizeHtml.js +0 -98
  87. package/lib/utils/truncate.js +0 -103
  88. package/lib/utils/withTimeout.js +0 -7
  89. package/src/index.ts +0 -50
@@ -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,50 +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 { BrowserServerBackend } from './browserServerBackend.js';
18
- import { resolveConfig } from './config.js';
19
- import { contextFactory } from './browserContextFactory.js';
20
- import * as mcpServer from './mcp/server.js';
21
-
22
- import type { Config } from '../config.js';
23
- import type { BrowserContext } from 'playwright-core';
24
- import type { BrowserContextFactory } from './browserContextFactory.js';
25
- import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
26
-
27
- export async function createConnection(userConfig: Config = {}, contextGetter?: () => Promise<BrowserContext>): Promise<Server> {
28
- const config = await resolveConfig(userConfig);
29
- const factory = contextGetter ? new SimpleBrowserContextFactory(contextGetter) : contextFactory(config);
30
- return mcpServer.createServer(new BrowserServerBackend(config, factory), false);
31
- }
32
-
33
- class SimpleBrowserContextFactory implements BrowserContextFactory {
34
- name = 'custom';
35
- description = 'Connect to a browser using a custom context getter';
36
-
37
- private readonly _contextGetter: () => Promise<BrowserContext>;
38
-
39
- constructor(contextGetter: () => Promise<BrowserContext>) {
40
- this._contextGetter = contextGetter;
41
- }
42
-
43
- async createContext(): Promise<{ browserContext: BrowserContext, close: () => Promise<void> }> {
44
- const browserContext = await this._contextGetter();
45
- return {
46
- browserContext,
47
- close: () => browserContext.close()
48
- };
49
- }
50
- }