@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,161 +0,0 @@
1
- import { withTimeout } from "../../utils/withTimeout.js";
2
- import { highlightMatch } from "./helpers.js";
3
- import { searchInHtml } from "./searchHtml.js";
4
- const CONTEXT_LENGTH_BODY = 400;
5
- const CONTEXT_LENGTH_DEFAULT = 300;
6
- const MAX_SEARCH_DEPTH = 20;
7
- export const searchInObject = (obj, keyword, path, matches, source, depth = 0) => {
8
- if (depth > MAX_SEARCH_DEPTH || !obj || typeof obj !== "object")
9
- return;
10
- for (const key in obj) {
11
- const newPath = path ? `${path}.${key}` : key;
12
- const value = obj[key];
13
- if (key.toLowerCase().includes(keyword)) {
14
- const highlightedKey = highlightMatch(key, keyword, CONTEXT_LENGTH_DEFAULT);
15
- const valueContext = typeof value === "object" && value !== null
16
- ? truncateJsonPreview(value)
17
- : truncateStringPreview(String(value));
18
- matches.push({
19
- path: newPath,
20
- value: typeof value === "object" && value !== null
21
- ? JSON.stringify(value)
22
- : String(value),
23
- context: `${highlightedKey}: ${valueContext}`,
24
- source,
25
- });
26
- }
27
- if (typeof value === "string" && value.toLowerCase().includes(keyword)) {
28
- matches.push({
29
- path: newPath,
30
- value: value,
31
- context: `${key}: ${highlightMatch(value, keyword, CONTEXT_LENGTH_DEFAULT)}`,
32
- source,
33
- });
34
- }
35
- else if (typeof value === "number" && String(value).includes(keyword)) {
36
- const valueStr = String(value);
37
- matches.push({
38
- path: newPath,
39
- value: valueStr,
40
- context: `${key}: ${highlightMatch(valueStr, keyword, CONTEXT_LENGTH_DEFAULT)}`,
41
- source,
42
- });
43
- }
44
- if (typeof value === "object" && value !== null)
45
- searchInObject(value, keyword, newPath, matches, source, depth + 1);
46
- }
47
- };
48
- const truncateStringPreview = (text) => text.length > CONTEXT_LENGTH_DEFAULT
49
- ? text.slice(0, CONTEXT_LENGTH_DEFAULT) + "..."
50
- : text;
51
- const truncateJsonPreview = (obj) => {
52
- try {
53
- return JSON.stringify(obj).slice(0, CONTEXT_LENGTH_BODY) + "...";
54
- }
55
- catch {
56
- return "[Object]";
57
- }
58
- };
59
- export const searchInRequestBody = (request, keyword, matches) => {
60
- const body = request.postData();
61
- if (!body || !body.toLowerCase().includes(keyword))
62
- return;
63
- const requestContentType = request.headers()["content-type"] || "";
64
- let handled = false;
65
- if (requestContentType.includes("application/json") ||
66
- body.trim().startsWith("{") ||
67
- body.trim().startsWith("[")) {
68
- try {
69
- const parsed = JSON.parse(body);
70
- searchInObject(parsed, keyword, "request.body", matches, "requestBody");
71
- handled = true;
72
- }
73
- catch { }
74
- }
75
- if (!handled &&
76
- (requestContentType.includes("text/html") || body.trim().startsWith("<"))) {
77
- searchInHtml(body, keyword, "request.body", matches, "requestBody");
78
- handled = true;
79
- }
80
- if (!handled &&
81
- requestContentType.includes("application/x-www-form-urlencoded")) {
82
- try {
83
- const sp = new URLSearchParams(body);
84
- for (const [k, v] of sp.entries()) {
85
- const vStr = v || "";
86
- if (!vStr.toLowerCase().includes(keyword))
87
- continue;
88
- const trimmed = vStr.trim();
89
- let parsedOk = false;
90
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
91
- try {
92
- const parsed = JSON.parse(trimmed);
93
- searchInObject(parsed, keyword, `request.body.form.${k}`, matches, "requestBody");
94
- parsedOk = true;
95
- }
96
- catch { }
97
- }
98
- if (!parsedOk) {
99
- matches.push({
100
- path: `request.body.form.${k}`,
101
- value: vStr,
102
- context: `${k}=${highlightMatch(vStr, keyword, CONTEXT_LENGTH_DEFAULT)}`,
103
- source: "requestBody",
104
- });
105
- }
106
- }
107
- handled = true;
108
- }
109
- catch { }
110
- }
111
- if (!handled) {
112
- matches.push({
113
- path: "request.body",
114
- value: body,
115
- context: highlightMatch(body, keyword, CONTEXT_LENGTH_BODY),
116
- source: "requestBody",
117
- });
118
- }
119
- };
120
- export const searchInResponseBody = async (response, keyword, matches) => {
121
- const contentTypeHeader = response.headers()["content-type"] || "";
122
- if (!(contentTypeHeader.startsWith("text/") ||
123
- contentTypeHeader.includes("application/json") ||
124
- contentTypeHeader.includes("application/xml")))
125
- return;
126
- try {
127
- const responseBody = await withTimeout(response.text(), 2000);
128
- if (!responseBody || !responseBody.toLowerCase().includes(keyword))
129
- return;
130
- let handled = false;
131
- const trimmed = responseBody.trimStart();
132
- const xssiPrefix = ")]}'";
133
- const hasXssi = trimmed.startsWith(xssiPrefix);
134
- const jsonCandidate = hasXssi ? trimmed.slice(xssiPrefix.length) : trimmed;
135
- if (contentTypeHeader.includes("application/json") ||
136
- jsonCandidate.startsWith("{") ||
137
- jsonCandidate.startsWith("[")) {
138
- try {
139
- const parsed = JSON.parse(jsonCandidate);
140
- searchInObject(parsed, keyword, "response.body", matches, "responseBody");
141
- handled = true;
142
- }
143
- catch { }
144
- }
145
- if (!handled &&
146
- (contentTypeHeader.includes("text/html") ||
147
- responseBody.trim().startsWith("<"))) {
148
- searchInHtml(responseBody, keyword, "response.body", matches, "responseBody");
149
- handled = true;
150
- }
151
- if (!handled) {
152
- matches.push({
153
- path: "response.body",
154
- value: responseBody,
155
- context: highlightMatch(responseBody, keyword, CONTEXT_LENGTH_BODY),
156
- source: "responseBody",
157
- });
158
- }
159
- }
160
- catch { }
161
- };
@@ -1,37 +0,0 @@
1
- export const normalizePath = (path) => {
2
- if (path.includes(" > "))
3
- return path.replace(/:nth-child\(\d+\)/g, ":nth-child(*)");
4
- return path.replace(/\.(?:\d+)(?=\.|$)/g, ".*");
5
- };
6
- export const getDepth = (path) => {
7
- const separators = path.match(/\.|>/g) || [];
8
- return separators.length;
9
- };
10
- export const mergeGroupedMatches = (a, b) => {
11
- const map = new Map();
12
- for (const g of a)
13
- map.set(g.normalized, {
14
- normalized: g.normalized,
15
- count: g.count,
16
- examples: g.examples.slice(0, 3),
17
- });
18
- for (const g of b) {
19
- const existing = map.get(g.normalized);
20
- if (existing) {
21
- existing.count += g.count;
22
- for (const e of g.examples) {
23
- if (existing.examples.length < 3 &&
24
- !existing.examples.some((x) => x.context === e.context))
25
- existing.examples.push(e);
26
- }
27
- }
28
- else {
29
- map.set(g.normalized, {
30
- normalized: g.normalized,
31
- count: g.count,
32
- examples: g.examples.slice(0, 3),
33
- });
34
- }
35
- }
36
- return Array.from(map.values());
37
- };
@@ -1,32 +0,0 @@
1
- import { truncateStringTo } from "../../utils/truncate.js";
2
- export const parseKeywordParams = (keyword) => {
3
- const out = [];
4
- try {
5
- const sp = new URLSearchParams(keyword);
6
- sp.forEach((value, key) => {
7
- if (key)
8
- out.push({ name: key, value });
9
- });
10
- }
11
- catch { }
12
- return out;
13
- };
14
- export const highlightMatch = (text, keyword, maxLength = 50) => {
15
- const lowerText = text.toLowerCase();
16
- const index = lowerText.indexOf(keyword);
17
- if (index === -1)
18
- return truncateStringTo(text, maxLength).text;
19
- const contextBefore = Math.floor((maxLength - keyword.length) / 2);
20
- const contextAfter = maxLength - keyword.length - contextBefore;
21
- const start = Math.max(0, index - contextBefore);
22
- const end = Math.min(text.length, index + keyword.length + contextAfter);
23
- let result = "";
24
- if (start > 0)
25
- result += "...";
26
- result += text.substring(start, index);
27
- result += text.substring(index, index + keyword.length);
28
- result += text.substring(index + keyword.length, end);
29
- if (end < text.length)
30
- result += "...";
31
- return result;
32
- };
@@ -1,76 +0,0 @@
1
- import * as cheerio from "cheerio";
2
- import { highlightMatch } from "./helpers.js";
3
- export const getElementPath = ($el) => {
4
- const path = [];
5
- let current = $el;
6
- while (current.length &&
7
- current[0].type === "tag" &&
8
- current[0].name !== "html") {
9
- let selector = current[0].name.toLowerCase();
10
- const id = current.attr("id");
11
- if (id) {
12
- selector += `#${id}`;
13
- path.unshift(selector);
14
- break;
15
- }
16
- const classes = current.attr("class");
17
- if (classes)
18
- selector += `.${classes.trim().split(/\s+/).join(".")}`;
19
- const tagName = current[0].type === "tag" ? current[0].name : "";
20
- const siblings = current
21
- .parent()
22
- .children()
23
- .filter((_, el) => el.type === "tag" && el.name === tagName);
24
- if (siblings.length > 1) {
25
- const index = siblings.index(current) + 1;
26
- selector += `:nth-child(${index})`;
27
- }
28
- path.unshift(selector);
29
- current = current.parent();
30
- }
31
- return path.join(" > ");
32
- };
33
- export const searchInHtml = (html, keyword, basePath, matches, source) => {
34
- const $ = cheerio.load(html);
35
- $("*")
36
- .contents()
37
- .each((_, node) => {
38
- if (node.type === "text") {
39
- const text = (node.data || "").trim();
40
- if (text && text.toLowerCase().includes(keyword)) {
41
- const parent = $(node).parent();
42
- if (parent.length) {
43
- const elPath = getElementPath(parent);
44
- const path = elPath ? `${basePath} > ${elPath}` : basePath;
45
- matches.push({
46
- path,
47
- value: text,
48
- context: highlightMatch(text, keyword, 300),
49
- source,
50
- });
51
- }
52
- }
53
- }
54
- });
55
- $("*").each((_, el) => {
56
- if (el.type === "tag") {
57
- const attrs = el.attribs;
58
- if (attrs) {
59
- Object.entries(attrs).forEach(([key, val]) => {
60
- if (typeof val === "string" && val.toLowerCase().includes(keyword)) {
61
- const elPath = getElementPath($(el));
62
- const path = elPath
63
- ? `${basePath} > ${elPath}@${key}`
64
- : `${basePath}@${key}`;
65
- matches.push({
66
- path,
67
- value: val,
68
- context: highlightMatch(val, keyword, 300),
69
- source,
70
- });
71
- }
72
- });
73
- }
74
- }
75
- });
76
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,124 +0,0 @@
1
- import { highlightMatch } from "./helpers.js";
2
- const CONTEXT_LENGTH_DEFAULT = 300;
3
- export const searchInUrls = (request, response, keyword, keywordParams, matches) => {
4
- try {
5
- const reqUrl = request.url();
6
- const reqUrlLower = reqUrl.toLowerCase();
7
- const keywordPathOnly = keyword.split("?")[0];
8
- if (reqUrlLower.includes(keyword)) {
9
- matches.push({
10
- path: "request.url",
11
- value: reqUrl,
12
- context: `url: ${highlightMatch(reqUrl, keyword, CONTEXT_LENGTH_DEFAULT)}`,
13
- source: "requestUrl",
14
- });
15
- }
16
- else if (keywordPathOnly && reqUrlLower.includes(keywordPathOnly)) {
17
- matches.push({
18
- path: "request.url",
19
- value: reqUrl,
20
- context: `url: ${highlightMatch(reqUrl, keywordPathOnly, CONTEXT_LENGTH_DEFAULT)}`,
21
- source: "requestUrl",
22
- });
23
- }
24
- else {
25
- try {
26
- const u = new URL(reqUrl);
27
- const pathnameLower = u.pathname.toLowerCase();
28
- if (pathnameLower.includes(keyword) ||
29
- (keywordPathOnly && pathnameLower.includes(keywordPathOnly)))
30
- matches.push({
31
- path: "request.url",
32
- value: reqUrl,
33
- context: `url: ${highlightMatch(reqUrl, keywordPathOnly || keyword, CONTEXT_LENGTH_DEFAULT)}`,
34
- source: "requestUrl",
35
- });
36
- }
37
- catch { }
38
- }
39
- if (keywordParams.length) {
40
- try {
41
- const u = new URL(reqUrl);
42
- for (const { name, value } of keywordParams) {
43
- if (!name)
44
- continue;
45
- const pageVal = u.searchParams.get(name);
46
- if (!pageVal)
47
- continue;
48
- const valLower = (value || "").toLowerCase();
49
- if (!valLower)
50
- continue;
51
- const pageValLower = pageVal.toLowerCase();
52
- if (pageValLower.includes(valLower))
53
- matches.push({
54
- path: `request.url.query.${name}`,
55
- value: pageVal,
56
- context: `${name}=${highlightMatch(pageVal, value, CONTEXT_LENGTH_DEFAULT)}`,
57
- source: "requestUrl",
58
- });
59
- }
60
- }
61
- catch { }
62
- }
63
- if (response) {
64
- const resUrl = response.url();
65
- const resUrlLower = resUrl.toLowerCase();
66
- if (resUrlLower.includes(keyword)) {
67
- matches.push({
68
- path: "response.url",
69
- value: resUrl,
70
- context: `url: ${highlightMatch(resUrl, keyword, CONTEXT_LENGTH_DEFAULT)}`,
71
- source: "responseUrl",
72
- });
73
- }
74
- else if (keywordPathOnly && resUrlLower.includes(keywordPathOnly)) {
75
- matches.push({
76
- path: "response.url",
77
- value: resUrl,
78
- context: `url: ${highlightMatch(resUrl, keywordPathOnly, CONTEXT_LENGTH_DEFAULT)}`,
79
- source: "responseUrl",
80
- });
81
- }
82
- else {
83
- try {
84
- const u2 = new URL(resUrl);
85
- const pathnameLower2 = u2.pathname.toLowerCase();
86
- if (pathnameLower2.includes(keyword) ||
87
- (keywordPathOnly && pathnameLower2.includes(keywordPathOnly)))
88
- matches.push({
89
- path: "response.url",
90
- value: resUrl,
91
- context: `url: ${highlightMatch(resUrl, keywordPathOnly || keyword, CONTEXT_LENGTH_DEFAULT)}`,
92
- source: "responseUrl",
93
- });
94
- }
95
- catch { }
96
- }
97
- if (keywordParams.length) {
98
- try {
99
- const u2 = new URL(resUrl);
100
- for (const { name, value } of keywordParams) {
101
- if (!name)
102
- continue;
103
- const pageVal = u2.searchParams.get(name);
104
- if (!pageVal)
105
- continue;
106
- const valLower = (value || "").toLowerCase();
107
- if (!valLower)
108
- continue;
109
- const pageValLower = pageVal.toLowerCase();
110
- if (pageValLower.includes(valLower))
111
- matches.push({
112
- path: `response.url.query.${name}`,
113
- value: pageVal,
114
- context: `${name}=${highlightMatch(pageVal, value, CONTEXT_LENGTH_DEFAULT)}`,
115
- source: "responseUrl",
116
- });
117
- }
118
- }
119
- catch { }
120
- }
121
- }
122
- }
123
- catch { }
124
- };