@wordbricks/playwright-mcp 0.1.22 → 0.1.24

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,278 +0,0 @@
1
- import { z } from "zod";
2
- import { normalizeUrlForGrouping } from "../hooks/networkFilters.js";
3
- import { getNetworkEventEntry } from "../hooks/networkSetup.js";
4
- import { listNetworkEvents } from "../hooks/networkTrackingHook.js";
5
- import { formatNetworkSummaryLine } from "../utils/networkFormat.js";
6
- import { toJsonPathNormalized, truncateStringTo } from "../utils/truncate.js";
7
- import { searchInRequestBody, searchInResponseBody, } from "./networkSearch/bodySearch.js";
8
- import { getDepth, mergeGroupedMatches, normalizePath, } from "./networkSearch/grouping.js";
9
- import { highlightMatch, parseKeywordParams } from "./networkSearch/helpers.js";
10
- import { searchInUrls } from "./networkSearch/urlSearch.js";
11
- import { defineTool } from "./tool.js";
12
- const MAX_SEARCH_RESULTS = 10;
13
- const MAX_GROUPS_TO_SHOW = 3;
14
- const networkSearchSchema = z.object({
15
- keyword: z
16
- .string()
17
- .describe("Keyword or phrase; avoid generic words—specific terms reduce noise and improve precision."),
18
- });
19
- const createSourceCounts = () => ({
20
- requestUrl: 0,
21
- requestBody: 0,
22
- responseUrl: 0,
23
- responseBody: 0,
24
- responseHeaders: 0,
25
- });
26
- const accumulateSourceCounts = (records) => {
27
- const counts = createSourceCounts();
28
- for (const record of records)
29
- counts[record.source] += 1;
30
- return counts;
31
- };
32
- const cloneSourceCounts = (counts) => ({
33
- requestUrl: counts.requestUrl,
34
- requestBody: counts.requestBody,
35
- responseUrl: counts.responseUrl,
36
- responseBody: counts.responseBody,
37
- responseHeaders: counts.responseHeaders,
38
- });
39
- const computeEventScore = (match) => {
40
- const ageMs = Math.max(0, Date.now() - match.timestamp);
41
- const recencyWindowMs = 10 * 60 * 1000;
42
- const recencyBoost = 1 - Math.min(ageMs / recencyWindowMs, 1);
43
- const base = match.totalMatches;
44
- const responseBonus = match.sourceCounts.responseBody * 2;
45
- const requestBonus = match.sourceCounts.requestBody;
46
- const urlBonus = (match.sourceCounts.requestUrl + match.sourceCounts.responseUrl) * 0.25;
47
- const headerBonus = match.sourceCounts.responseHeaders;
48
- return (base + responseBonus + requestBonus + urlBonus + headerBonus + recencyBoost);
49
- };
50
- const formatGroupPath = (group) => {
51
- const normalized = group.normalized;
52
- const jsonPath = toJsonPathNormalized(normalized);
53
- if (jsonPath)
54
- return `json: ${jsonPath.jsonPath}`;
55
- if (!normalized.includes(" > "))
56
- return normalized;
57
- const withoutWildcard = normalized.replace(/:nth-child\(\*\)/g, "");
58
- const trimmedPrefix = withoutWildcard.startsWith("response.body")
59
- ? withoutWildcard.slice("response.body".length).trim()
60
- : withoutWildcard.startsWith("request.body")
61
- ? withoutWildcard.slice("request.body".length).trim()
62
- : withoutWildcard;
63
- const noLeadingArrow = trimmedPrefix.startsWith(">")
64
- ? trimmedPrefix.slice(1).trim()
65
- : trimmedPrefix;
66
- return `css: ${noLeadingArrow}`;
67
- };
68
- const extractExamples = (group) => {
69
- const items = [];
70
- for (const example of group.examples) {
71
- const raw = example.value ?? example.context;
72
- if (!raw)
73
- continue;
74
- const trimmed = raw.trim();
75
- const base = trimmed.length > 0 ? trimmed : raw;
76
- const { text } = truncateStringTo(base, 160);
77
- if (!items.includes(text))
78
- items.push(text);
79
- }
80
- return items;
81
- };
82
- const searchInResponseSetCookies = async (response, keyword, matches) => {
83
- const cookies = await response.headerValues("set-cookie").catch(() => []);
84
- if (!cookies.length)
85
- return;
86
- for (const [index, cookie] of cookies.entries()) {
87
- if (!cookie.toLowerCase().includes(keyword))
88
- continue;
89
- matches.push({
90
- path: `response.headers.set-cookie[${index}]`,
91
- value: cookie,
92
- context: highlightMatch(cookie, keyword, 120),
93
- source: "responseHeaders",
94
- });
95
- }
96
- };
97
- const networkSearch = defineTool({
98
- capability: "core",
99
- schema: {
100
- name: "browser_network_search",
101
- title: "Search network requests",
102
- description: "Search for keywords in network request/response bodies and URLs",
103
- inputSchema: networkSearchSchema,
104
- type: "readOnly",
105
- },
106
- handle: async (context, params, response) => {
107
- await context.ensureTab();
108
- try {
109
- const keyword = params.keyword?.toLowerCase();
110
- if (!keyword) {
111
- response.addResult("keyword parameter is required");
112
- return;
113
- }
114
- const events = listNetworkEvents(context);
115
- const keywordParams = parseKeywordParams(params.keyword);
116
- const searchMatches = [];
117
- for (const ev of events) {
118
- const entry = getNetworkEventEntry(context, ev.id);
119
- if (!entry)
120
- continue;
121
- const request = entry.request;
122
- const resp = entry.response ?? null;
123
- const matches = [];
124
- searchInUrls(request, resp, keyword, keywordParams, matches);
125
- searchInRequestBody(request, keyword, matches);
126
- if (resp) {
127
- await searchInResponseBody(resp, keyword, matches);
128
- await searchInResponseSetCookies(resp, keyword, matches);
129
- }
130
- if (matches.length > 0) {
131
- const groupMap = new Map();
132
- for (const m of matches) {
133
- const normalized = normalizePath(m.path);
134
- let group = groupMap.get(normalized);
135
- if (!group) {
136
- group = { normalized, count: 0, examples: [] };
137
- groupMap.set(normalized, group);
138
- }
139
- group.count++;
140
- if (group.examples.length < 3) {
141
- const example = {
142
- context: m.context,
143
- value: m.value,
144
- originalPath: m.path !== normalized ? m.path : undefined,
145
- };
146
- if (!group.examples.some((e) => e.context === example.context))
147
- group.examples.push(example);
148
- }
149
- }
150
- const groups = Array.from(groupMap.values()).sort((a, b) => b.count - a.count ||
151
- getDepth(b.normalized) - getDepth(a.normalized));
152
- const totalMatches = matches.length;
153
- const sourceCounts = accumulateSourceCounts(matches);
154
- searchMatches.push({
155
- requestId: ev.id,
156
- timestamp: ev.timestamp,
157
- count: 1,
158
- groups,
159
- totalMatches,
160
- sourceCounts,
161
- request,
162
- response: resp,
163
- });
164
- }
165
- }
166
- if (searchMatches.length === 0) {
167
- response.addResult(`No network requests found containing keyword: "${params.keyword}"`);
168
- return;
169
- }
170
- const aggMap = new Map();
171
- for (const m of searchMatches) {
172
- const key = `${m.request.method().toUpperCase()} ${normalizeUrlForGrouping(m.request.url())}`;
173
- const existing = aggMap.get(key);
174
- const eventScore = computeEventScore(m);
175
- if (!existing) {
176
- aggMap.set(key, {
177
- key,
178
- request: m.request,
179
- response: m.response,
180
- ids: [m.requestId],
181
- count: m.count,
182
- totalMatches: m.totalMatches,
183
- groups: [...m.groups],
184
- primaryGroups: m.groups,
185
- primaryEventId: m.requestId,
186
- primaryTimestamp: m.timestamp,
187
- primarySourceCounts: cloneSourceCounts(m.sourceCounts),
188
- primaryMatches: m.totalMatches,
189
- primaryScore: eventScore,
190
- });
191
- continue;
192
- }
193
- existing.ids.push(m.requestId);
194
- existing.count += m.count;
195
- existing.totalMatches += m.totalMatches;
196
- existing.groups = mergeGroupedMatches(existing.groups, m.groups);
197
- if (!existing.response && m.response)
198
- existing.response = m.response;
199
- const replacePrimary = eventScore > existing.primaryScore ||
200
- (eventScore === existing.primaryScore &&
201
- m.timestamp > existing.primaryTimestamp);
202
- if (!replacePrimary)
203
- continue;
204
- existing.request = m.request;
205
- existing.response = m.response;
206
- existing.primaryGroups = m.groups;
207
- existing.primaryEventId = m.requestId;
208
- existing.primaryTimestamp = m.timestamp;
209
- existing.primarySourceCounts = cloneSourceCounts(m.sourceCounts);
210
- existing.primaryMatches = m.totalMatches;
211
- existing.primaryScore = eventScore;
212
- }
213
- const aggregatedMatches = Array.from(aggMap.values()).sort((a, b) => {
214
- if (a.primaryScore !== b.primaryScore)
215
- return b.primaryScore - a.primaryScore;
216
- if (a.primaryMatches !== b.primaryMatches)
217
- return b.primaryMatches - a.primaryMatches;
218
- return b.primaryTimestamp - a.primaryTimestamp;
219
- });
220
- const topMatches = aggregatedMatches.slice(0, MAX_SEARCH_RESULTS);
221
- const structured = {
222
- keyword: params.keyword,
223
- requests: topMatches.map((m) => {
224
- const method = m.request.method().toUpperCase();
225
- const url = m.request.url();
226
- // Normalize URL for grouping only; not returned in output
227
- const status = m.response ? m.response.status() : undefined;
228
- const queryKeys = (() => {
229
- try {
230
- const u = new URL(url);
231
- const keys = new Set();
232
- u.searchParams.forEach((_, k) => {
233
- if (k)
234
- keys.add(k);
235
- });
236
- return Array.from(keys);
237
- }
238
- catch {
239
- return [];
240
- }
241
- })();
242
- const primaryGroups = m.primaryGroups
243
- .slice()
244
- .sort((a, b) => b.count - a.count ||
245
- getDepth(b.normalized) - getDepth(a.normalized))
246
- .slice(0, MAX_GROUPS_TO_SHOW);
247
- const paths = primaryGroups.map((group) => ({
248
- path: formatGroupPath(group),
249
- examples: extractExamples(group),
250
- }));
251
- const sourceCounts = cloneSourceCounts(m.primarySourceCounts);
252
- const score = Number(m.primaryScore.toFixed(2));
253
- return {
254
- summary: formatNetworkSummaryLine({
255
- method,
256
- url,
257
- status: status || 0,
258
- statusText: m.response?.statusText(),
259
- postData: m.request.postData(),
260
- headers: {},
261
- }),
262
- primaryEventId: m.primaryEventId,
263
- eventIds: m.ids.slice(0, 5),
264
- score,
265
- sourceCounts,
266
- params: queryKeys.slice(0, 6),
267
- paths,
268
- };
269
- }),
270
- };
271
- response.addResult(JSON.stringify(structured));
272
- }
273
- catch (error) {
274
- response.addResult(`Failed to search network requests: ${error.message}`);
275
- }
276
- },
277
- });
278
- export default [networkSearch];
package/lib/tools/pdf.js DELETED
@@ -1,41 +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
- import { z } from "zod";
17
- import * as javascript from "../utils/codegen.js";
18
- import { defineTabTool } from "./tool.js";
19
- const pdfSchema = z.object({
20
- filename: z
21
- .string()
22
- .optional()
23
- .describe("File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified."),
24
- });
25
- const pdf = defineTabTool({
26
- capability: "pdf",
27
- schema: {
28
- name: "browser_pdf_save",
29
- title: "Save as PDF",
30
- description: "Save page as PDF",
31
- inputSchema: pdfSchema,
32
- type: "readOnly",
33
- },
34
- handle: async (tab, params, response) => {
35
- const fileName = await tab.context.outputFile(params.filename ?? `page-${new Date().toISOString()}.pdf`);
36
- response.addCode(`await page.pdf(${javascript.formatObject({ path: fileName })});`);
37
- response.addResult(`Saved page as ${fileName}`);
38
- await tab.page.pdf({ path: fileName });
39
- },
40
- });
41
- export default [pdf];