@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
- /**
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, defineTool } from "./tool.js";
19
- import { generateLocator } from "./utils.js";
20
- const snapshot = defineTool({
21
- capability: "core",
22
- schema: {
23
- name: "browser_snapshot",
24
- title: "Page snapshot",
25
- description: "Capture accessibility snapshot of the current page, this is better than screenshot",
26
- inputSchema: z.object({}),
27
- type: "readOnly",
28
- },
29
- handle: async (context, params, response) => {
30
- await context.ensureTab();
31
- response.setIncludeSnapshot("full");
32
- },
33
- });
34
- export const elementSchema = z.object({
35
- element: z
36
- .string()
37
- .describe("Human-readable element description used to obtain permission to interact with the element"),
38
- ref: z
39
- .string()
40
- .describe("Exact target element reference from the page snapshot"),
41
- });
42
- const clickSchema = elementSchema.extend({
43
- doubleClick: z
44
- .boolean()
45
- .optional()
46
- .describe("Whether to perform a double click instead of a single click"),
47
- button: z
48
- .enum(["left", "right", "middle"])
49
- .optional()
50
- .describe("Button to click, defaults to left"),
51
- modifiers: z
52
- .array(z.enum(["Alt", "Control", "ControlOrMeta", "Meta", "Shift"]))
53
- .optional()
54
- .describe("Modifier keys to press"),
55
- });
56
- const click = defineTabTool({
57
- capability: "core",
58
- schema: {
59
- name: "browser_click",
60
- title: "Click",
61
- description: "Perform click on a web page",
62
- inputSchema: clickSchema,
63
- type: "input",
64
- },
65
- handle: async (tab, params, response) => {
66
- response.setIncludeSnapshot();
67
- const locator = await tab.refLocator(params);
68
- const options = {
69
- button: params.button,
70
- modifiers: params.modifiers,
71
- };
72
- const formatted = javascript.formatObject(options, " ", "oneline");
73
- const optionsAttr = formatted !== "{}" ? formatted : "";
74
- if (params.doubleClick)
75
- response.addCode(`await page.${await generateLocator(locator)}.dblclick(${optionsAttr});`);
76
- else
77
- response.addCode(`await page.${await generateLocator(locator)}.click(${optionsAttr});`);
78
- await tab.waitForCompletion(async () => {
79
- if (params.doubleClick)
80
- await locator.dblclick(options);
81
- else
82
- await locator.click(options);
83
- });
84
- },
85
- });
86
- const drag = defineTabTool({
87
- capability: "core",
88
- schema: {
89
- name: "browser_drag",
90
- title: "Drag mouse",
91
- description: "Perform drag and drop between two elements",
92
- inputSchema: z.object({
93
- startElement: z
94
- .string()
95
- .describe("Human-readable source element description used to obtain the permission to interact with the element"),
96
- startRef: z
97
- .string()
98
- .describe("Exact source element reference from the page snapshot"),
99
- endElement: z
100
- .string()
101
- .describe("Human-readable target element description used to obtain the permission to interact with the element"),
102
- endRef: z
103
- .string()
104
- .describe("Exact target element reference from the page snapshot"),
105
- }),
106
- type: "input",
107
- },
108
- handle: async (tab, params, response) => {
109
- response.setIncludeSnapshot();
110
- const [startLocator, endLocator] = await tab.refLocators([
111
- { ref: params.startRef, element: params.startElement },
112
- { ref: params.endRef, element: params.endElement },
113
- ]);
114
- await tab.waitForCompletion(async () => {
115
- await startLocator.dragTo(endLocator);
116
- });
117
- response.addCode(`await page.${await generateLocator(startLocator)}.dragTo(page.${await generateLocator(endLocator)});`);
118
- },
119
- });
120
- const hover = defineTabTool({
121
- capability: "core",
122
- schema: {
123
- name: "browser_hover",
124
- title: "Hover mouse",
125
- description: "Hover over element on page",
126
- inputSchema: elementSchema,
127
- type: "readOnly",
128
- },
129
- handle: async (tab, params, response) => {
130
- response.setIncludeSnapshot();
131
- const locator = await tab.refLocator(params);
132
- response.addCode(`await page.${await generateLocator(locator)}.hover();`);
133
- await tab.waitForCompletion(async () => {
134
- await locator.hover();
135
- });
136
- },
137
- });
138
- const selectOptionSchema = elementSchema.extend({
139
- values: z
140
- .array(z.string())
141
- .describe("Array of values to select in the dropdown. This can be a single value or multiple values."),
142
- });
143
- const selectOption = defineTabTool({
144
- capability: "core",
145
- schema: {
146
- name: "browser_select_option",
147
- title: "Select option",
148
- description: "Select an option in a dropdown",
149
- inputSchema: selectOptionSchema,
150
- type: "input",
151
- },
152
- handle: async (tab, params, response) => {
153
- response.setIncludeSnapshot();
154
- const locator = await tab.refLocator(params);
155
- response.addCode(`await page.${await generateLocator(locator)}.selectOption(${javascript.formatObject(params.values)});`);
156
- await tab.waitForCompletion(async () => {
157
- await locator.selectOption(params.values);
158
- });
159
- },
160
- });
161
- export default [snapshot, click, drag, hover, selectOption];
package/lib/tools/tabs.js DELETED
@@ -1,62 +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 { defineTool } from "./tool.js";
18
- const browserTabs = defineTool({
19
- capability: "core-tabs",
20
- schema: {
21
- name: "browser_tabs",
22
- title: "Manage tabs",
23
- description: "List, create, close, or select a browser tab.",
24
- inputSchema: z.object({
25
- action: z
26
- .enum(["list", "new", "close", "select"])
27
- .describe("Operation to perform"),
28
- index: z
29
- .number()
30
- .optional()
31
- .describe("Tab index, used for close/select. If omitted for close, current tab is closed."),
32
- }),
33
- type: "action",
34
- },
35
- handle: async (context, params, response) => {
36
- switch (params.action) {
37
- case "list": {
38
- await context.ensureTab();
39
- response.setIncludeTabs();
40
- return;
41
- }
42
- case "new": {
43
- await context.newTab();
44
- response.setIncludeTabs();
45
- return;
46
- }
47
- case "close": {
48
- await context.closeTab(params.index);
49
- response.setIncludeSnapshot("full");
50
- return;
51
- }
52
- case "select": {
53
- if (params.index === undefined)
54
- throw new Error("Tab index is required");
55
- await context.selectTab(params.index);
56
- response.setIncludeSnapshot("full");
57
- return;
58
- }
59
- }
60
- },
61
- });
62
- export default [browserTabs];
package/lib/tools/tool.js DELETED
@@ -1,35 +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
- export function defineTool(tool) {
17
- return tool;
18
- }
19
- export function defineTabTool(tool) {
20
- return {
21
- ...tool,
22
- handle: async (context, params, response) => {
23
- const tab = await context.ensureTab();
24
- const modalStates = tab.modalStates().map((state) => state.type);
25
- if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState))
26
- response.addError(`Error: The tool "${tool.schema.name}" can only be used when there is related modal state present.\n` +
27
- tab.modalStatesMarkdown().join("\n"));
28
- else if (!tool.clearsModalState && modalStates.length)
29
- response.addError(`Error: Tool "${tool.schema.name}" does not handle the modal state.\n` +
30
- tab.modalStatesMarkdown().join("\n"));
31
- else
32
- return tool.handle(tab, params, response);
33
- },
34
- };
35
- }
@@ -1,78 +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
- // @ts-expect-error
17
- import { asLocator } from "playwright-core/lib/utils";
18
- export async function waitForCompletion(tab, callback) {
19
- const requests = new Set();
20
- let frameNavigated = false;
21
- let waitCallback = () => { };
22
- const waitBarrier = new Promise((f) => {
23
- waitCallback = f;
24
- });
25
- const requestListener = (request) => requests.add(request);
26
- const requestFinishedListener = (request) => {
27
- requests.delete(request);
28
- if (!requests.size)
29
- waitCallback();
30
- };
31
- const frameNavigateListener = (frame) => {
32
- if (frame.parentFrame())
33
- return;
34
- frameNavigated = true;
35
- dispose();
36
- clearTimeout(timeout);
37
- void tab.waitForLoadState("load").then(waitCallback);
38
- };
39
- const onTimeout = () => {
40
- dispose();
41
- waitCallback();
42
- };
43
- tab.page.on("request", requestListener);
44
- tab.page.on("requestfinished", requestFinishedListener);
45
- tab.page.on("framenavigated", frameNavigateListener);
46
- const timeout = setTimeout(onTimeout, 10000);
47
- const dispose = () => {
48
- tab.page.off("request", requestListener);
49
- tab.page.off("requestfinished", requestFinishedListener);
50
- tab.page.off("framenavigated", frameNavigateListener);
51
- clearTimeout(timeout);
52
- };
53
- try {
54
- const result = await callback();
55
- if (!requests.size && !frameNavigated)
56
- waitCallback();
57
- await waitBarrier;
58
- await tab.waitForTimeout(1000);
59
- return result;
60
- }
61
- finally {
62
- dispose();
63
- }
64
- }
65
- export async function generateLocator(locator) {
66
- try {
67
- const { resolvedSelector } = await locator._resolveSelector();
68
- return asLocator("javascript", resolvedSelector);
69
- }
70
- catch (e) {
71
- throw new Error("Ref not found, likely because element was removed. Use browser_get_snapshot to see what elements are currently on the page.");
72
- }
73
- }
74
- export async function callOnPageNoTrace(page, callback) {
75
- return await page._wrapApiCall(() => callback(page), {
76
- internal: true,
77
- });
78
- }
package/lib/tools/wait.js 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
- import { z } from "zod";
17
- import { defineTool } from "./tool.js";
18
- const wait = defineTool({
19
- capability: "core",
20
- schema: {
21
- name: "browser_wait_for",
22
- title: "Wait for",
23
- description: "Wait for text to appear or disappear or a specified time to pass",
24
- inputSchema: z.object({
25
- time: z.number().optional().describe("The time to wait in seconds"),
26
- text: z.string().optional().describe("The text to wait for"),
27
- textGone: z
28
- .string()
29
- .optional()
30
- .describe("The text to wait for to disappear"),
31
- }),
32
- type: "readOnly",
33
- },
34
- handle: async (context, params, response) => {
35
- if (!params.text && !params.textGone && !params.time)
36
- throw new Error("Either time, text or textGone must be provided");
37
- if (params.time) {
38
- response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
39
- await new Promise((f) => setTimeout(f, Math.min(30000, params.time * 1000)));
40
- }
41
- const tab = context.currentTabOrDie();
42
- const locator = params.text
43
- ? tab.page.getByText(params.text).first()
44
- : undefined;
45
- const goneLocator = params.textGone
46
- ? tab.page.getByText(params.textGone).first()
47
- : undefined;
48
- if (goneLocator) {
49
- response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
50
- await goneLocator.waitFor({ state: "hidden" });
51
- }
52
- if (locator) {
53
- response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
54
- await locator.waitFor({ state: "visible" });
55
- }
56
- response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
57
- response.setIncludeSnapshot();
58
- },
59
- });
60
- export default [wait];
package/lib/tools.js DELETED
@@ -1,68 +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 { toolNameSchema } from "./hooks/schema.js";
17
- import common from "./tools/common.js";
18
- import console from "./tools/console.js";
19
- // import tabs from './tools/tabs.js';
20
- // import screenshot from './tools/screenshot.js';
21
- // import wait from './tools/wait.js';
22
- // import javascript from './tools/javascript.js';
23
- import evaluate from "./tools/evaluate.js";
24
- import extractFrameworkState from "./tools/extractFrameworkState.js";
25
- import getSnapshot from "./tools/getSnapshot.js";
26
- import getVisibleHtml from "./tools/getVisibleHtml.js";
27
- // import dialogs from './tools/dialogs.js';
28
- // import files from './tools/files.js';
29
- // import install from './tools/install.js';
30
- import keyboard from "./tools/keyboard.js";
31
- import navigate from "./tools/navigate.js";
32
- import network from "./tools/network.js";
33
- import networkDetail from "./tools/networkDetail.js";
34
- import networkSearch from "./tools/networkSearch.js";
35
- import repl from "./tools/repl.js";
36
- import scroll from "./tools/scroll.js";
37
- // import pdf from './tools/pdf.js';
38
- import snapshot from "./tools/snapshot.js";
39
- export const allTools = [
40
- ...common,
41
- ...console,
42
- // ...dialogs(true),
43
- // ...files(true),
44
- // ...install,
45
- ...keyboard,
46
- ...navigate,
47
- ...network,
48
- ...networkSearch,
49
- ...networkDetail,
50
- // ...pdf,
51
- // ...screenshot,
52
- ...snapshot,
53
- // ...javascript,
54
- ...evaluate,
55
- // ...tabs(true),
56
- // ...testing,
57
- // ...wait,
58
- ...getVisibleHtml,
59
- ...getSnapshot,
60
- ...repl,
61
- ...extractFrameworkState,
62
- ...scroll,
63
- ];
64
- export function filteredTools(config) {
65
- return allTools.filter((tool) => (tool.capability.startsWith("core") ||
66
- config.capabilities?.includes(tool.capability)) &&
67
- toolNameSchema.safeParse(tool.schema.name).success);
68
- }
@@ -1,90 +0,0 @@
1
- import { FiltersEngine, Request } from "@ghostery/adblocker";
2
- import fs from "fs";
3
- import path, { dirname } from "path";
4
- import { fileURLToPath } from "url";
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
- class AdBlockFilter {
8
- _engine;
9
- _initialized = false;
10
- _loadFilters() {
11
- const packageRoot = path.resolve(__dirname, "../..");
12
- const libFiltersDir = path.join(packageRoot, "lib/filters");
13
- const srcFiltersDir = path.join(packageRoot, "src/filters");
14
- const filtersDir = fs.existsSync(libFiltersDir)
15
- ? libFiltersDir
16
- : srcFiltersDir;
17
- if (!fs.existsSync(filtersDir))
18
- return FiltersEngine.empty();
19
- const filterFiles = fs
20
- .readdirSync(filtersDir)
21
- .filter((f) => f.endsWith(".txt"));
22
- const allFilters = [];
23
- for (const file of filterFiles) {
24
- const filePath = path.join(filtersDir, file);
25
- const content = fs.readFileSync(filePath, "utf-8");
26
- allFilters.push(content);
27
- }
28
- const combinedFilters = allFilters.join("\n");
29
- return FiltersEngine.parse(combinedFilters);
30
- }
31
- initialize() {
32
- if (this._initialized)
33
- return;
34
- this._engine = this._loadFilters();
35
- this._initialized = true;
36
- }
37
- shouldBlockRequest(url, domain, resourceType) {
38
- if (!this._initialized)
39
- this.initialize();
40
- if (!this._engine)
41
- return false;
42
- try {
43
- const urlObj = new URL(url);
44
- const hostname = urlObj.hostname;
45
- const request = Request.fromRawDetails({
46
- url,
47
- hostname,
48
- domain,
49
- sourceUrl: url,
50
- sourceHostname: hostname,
51
- sourceDomain: domain,
52
- type: this._mapResourceType(resourceType),
53
- requestId: "",
54
- tabId: 0,
55
- });
56
- const result = this._engine.match(request);
57
- return result.match;
58
- }
59
- catch {
60
- return false;
61
- }
62
- }
63
- _mapResourceType(resourceType) {
64
- const mapping = {
65
- document: "main_frame",
66
- stylesheet: "stylesheet",
67
- image: "image",
68
- media: "media",
69
- font: "font",
70
- script: "script",
71
- texttrack: "other",
72
- xhr: "xmlhttprequest",
73
- fetch: "xmlhttprequest",
74
- websocket: "websocket",
75
- manifest: "other",
76
- other: "other",
77
- };
78
- return mapping[resourceType] || "other";
79
- }
80
- }
81
- let filterInstance;
82
- export const getAdBlockFilter = () => {
83
- if (!filterInstance)
84
- filterInstance = new AdBlockFilter();
85
- return filterInstance;
86
- };
87
- export const shouldBlockRequest = (url, domain, resourceType) => {
88
- const filter = getAdBlockFilter();
89
- return filter.shouldBlockRequest(url, domain, resourceType);
90
- };
@@ -1,55 +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
- // adapted from:
17
- // - https://github.com/microsoft/playwright/blob/76ee48dc9d4034536e3ec5b2c7ce8be3b79418a8/packages/playwright-core/src/utils/isomorphic/stringUtils.ts
18
- // - https://github.com/microsoft/playwright/blob/76ee48dc9d4034536e3ec5b2c7ce8be3b79418a8/packages/playwright-core/src/server/codegen/javascript.ts
19
- // NOTE: this function should not be used to escape any selectors.
20
- export function escapeWithQuotes(text, char = "'") {
21
- const stringified = JSON.stringify(text);
22
- const escapedText = stringified
23
- .substring(1, stringified.length - 1)
24
- .replace(/\\"/g, '"');
25
- if (char === "'")
26
- return char + escapedText.replace(/[']/g, "\\'") + char;
27
- if (char === '"')
28
- return char + escapedText.replace(/["]/g, '\\"') + char;
29
- if (char === "`")
30
- return char + escapedText.replace(/[`]/g, "\\`") + char;
31
- throw new Error("Invalid escape char");
32
- }
33
- export function quote(text) {
34
- return escapeWithQuotes(text, "'");
35
- }
36
- export function formatObject(value, indent = " ", mode = "multiline") {
37
- if (typeof value === "string")
38
- return quote(value);
39
- if (Array.isArray(value))
40
- return `[${value.map((o) => formatObject(o)).join(", ")}]`;
41
- if (typeof value === "object") {
42
- const keys = Object.keys(value)
43
- .filter((key) => value[key] !== undefined)
44
- .sort();
45
- if (!keys.length)
46
- return "{}";
47
- const tokens = [];
48
- for (const key of keys)
49
- tokens.push(`${key}: ${formatObject(value[key])}`);
50
- if (mode === "multiline")
51
- return `{\n${tokens.join(`,\n${indent}`)}\n}`;
52
- return `{ ${tokens.join(", ")} }`;
53
- }
54
- return String(value);
55
- }
@@ -1,10 +0,0 @@
1
- import { dirname, resolve } from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- // Resolve package root from this module's location
4
- // In published package: node_modules/@wordbricks/playwright-mcp/lib/utils/extensionPath.js
5
- // In development: src/utils/extensionPath.ts
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = dirname(__filename);
8
- // Go up from lib/utils/ or src/utils/ to package root
9
- const packageRoot = resolve(__dirname, "../..");
10
- export const extensionPath = resolve(packageRoot, "src/extensions/uBlockOriginLite");
@@ -1,40 +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 os from "node:os";
17
- import path from "node:path";
18
- export function cacheDir() {
19
- let cacheDirectory;
20
- if (process.platform === "linux")
21
- cacheDirectory =
22
- process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
23
- else if (process.platform === "darwin")
24
- cacheDirectory = path.join(os.homedir(), "Library", "Caches");
25
- else if (process.platform === "win32")
26
- cacheDirectory =
27
- process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local");
28
- else
29
- throw new Error("Unsupported platform: " + process.platform);
30
- return path.join(cacheDirectory, "ms-playwright");
31
- }
32
- export function sanitizeForFilePath(s) {
33
- const sanitize = (s) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, "-");
34
- const separator = s.lastIndexOf(".");
35
- if (separator === -1)
36
- return sanitize(s);
37
- return (sanitize(s.substring(0, separator)) +
38
- "." +
39
- sanitize(s.substring(separator + 1)));
40
- }