@pyrokine/mcp-chrome 3.0.0 → 3.0.1
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.
- package/README.md +119 -38
- package/README_zh.md +165 -110
- package/dist/core/browser-driver.d.ts +5 -4
- package/dist/core/browser-driver.d.ts.map +1 -1
- package/dist/core/browser-driver.js.map +1 -1
- package/dist/core/errors.d.ts +6 -4
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +14 -8
- package/dist/core/errors.js.map +1 -1
- package/dist/core/locator.d.ts +7 -0
- package/dist/core/locator.d.ts.map +1 -1
- package/dist/core/locator.js +48 -25
- package/dist/core/locator.js.map +1 -1
- package/dist/core/session.d.ts +6 -4
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +58 -23
- package/dist/core/session.js.map +1 -1
- package/dist/core/unified-session.d.ts +11 -8
- package/dist/core/unified-session.d.ts.map +1 -1
- package/dist/core/unified-session.js +71 -27
- package/dist/core/unified-session.js.map +1 -1
- package/dist/extension/bridge.d.ts +3 -3
- package/dist/extension/bridge.d.ts.map +1 -1
- package/dist/extension/bridge.js +50 -20
- package/dist/extension/bridge.js.map +1 -1
- package/dist/extension/http-server.d.ts.map +1 -1
- package/dist/extension/http-server.js +9 -0
- package/dist/extension/http-server.js.map +1 -1
- package/dist/tools/browse.d.ts.map +1 -1
- package/dist/tools/browse.js +10 -4
- package/dist/tools/browse.js.map +1 -1
- package/dist/tools/challenge.d.ts.map +1 -1
- package/dist/tools/challenge.js +12 -15
- package/dist/tools/challenge.js.map +1 -1
- package/dist/tools/evaluate.d.ts.map +1 -1
- package/dist/tools/evaluate.js +10 -0
- package/dist/tools/evaluate.js.map +1 -1
- package/dist/tools/extract.d.ts.map +1 -1
- package/dist/tools/extract.js +30 -22
- package/dist/tools/extract.js.map +1 -1
- package/dist/tools/input.d.ts.map +1 -1
- package/dist/tools/input.js +83 -57
- package/dist/tools/input.js.map +1 -1
- package/dist/tools/manage.d.ts.map +1 -1
- package/dist/tools/manage.js +16 -30
- package/dist/tools/manage.js.map +1 -1
- package/dist/tools/post-condition.d.ts.map +1 -1
- package/dist/tools/post-condition.js +23 -9
- package/dist/tools/post-condition.js.map +1 -1
- package/dist/tools/target-diagnostics.d.ts +9 -1
- package/dist/tools/target-diagnostics.d.ts.map +1 -1
- package/dist/tools/target-diagnostics.js +60 -17
- package/dist/tools/target-diagnostics.js.map +1 -1
- package/dist/tools/wait.d.ts.map +1 -1
- package/dist/tools/wait.js +19 -7
- package/dist/tools/wait.js.map +1 -1
- package/extension/dist/assets/{content.ts-loader-CnJuCGhl.js → content.ts-loader-DUWbDHRS.js} +1 -1
- package/extension/dist/assets/{content.ts-C4imZ6A9.js → content.ts-qe6IB5DK.js} +1 -1
- package/extension/dist/assets/{index.ts-GeHNZBml.js → index.ts-D7_LCUoV.js} +559 -212
- package/extension/dist/assets/{page-scripts-CMIY1zhd.js → page-scripts-D508WLkW.js} +50 -51
- package/extension/dist/assets/{popup.html-CgtWL6Py.js → popup.html-B-eVq48O.js} +6 -4
- package/extension/dist/manifest.json +4 -4
- package/extension/dist/service-worker-loader.js +1 -1
- package/extension/dist/src/popup/popup.html +1 -1
- package/package.json +12 -6
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
//#region src/background/page-scripts.ts
|
|
2
2
|
function installFrameProbeListener() {
|
|
3
3
|
const probeWindow = window;
|
|
4
|
-
if (probeWindow.
|
|
5
|
-
|
|
4
|
+
if (probeWindow.__mcpFrameProbeListenerV2) return;
|
|
5
|
+
const onMessage = async (event) => {
|
|
6
6
|
const data = event.data;
|
|
7
|
-
if (event.source !== window.parent || data?.type !== "mcp-frame-probe" || typeof data.token !== "string" || data.token.length > 100 || !Number.isInteger(data.index) || (data.index ?? -1) < 0) return;
|
|
7
|
+
if (event.source !== window.parent || data?.type !== "mcp-frame-probe-v2" || typeof data.token !== "string" || data.token.length > 100 || !Number.isInteger(data.index) || (data.index ?? -1) < 0) return;
|
|
8
8
|
const source = event.source;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
try {
|
|
10
|
+
const runtime = typeof chrome === "undefined" ? void 0 : chrome.runtime;
|
|
11
|
+
if (typeof runtime?.sendMessage !== "function") throw new Error("Extension context invalidated: runtime messaging is unavailable");
|
|
12
|
+
if ((await runtime.sendMessage({
|
|
13
|
+
type: "MCP_FRAME_PROBE",
|
|
14
|
+
token: data.token,
|
|
15
|
+
index: data.index
|
|
16
|
+
}))?.accepted) source.postMessage({
|
|
17
|
+
type: "mcp-frame-probe-ack-v2",
|
|
17
18
|
token: data.token,
|
|
18
19
|
index: data.index
|
|
19
20
|
}, "*");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
23
|
+
if (/Extension context invalidated/i.test(message)) {
|
|
24
|
+
if (probeWindow.__mcpFrameProbeListenerV2 !== onMessage) return;
|
|
25
|
+
window.removeEventListener("message", onMessage);
|
|
26
|
+
delete probeWindow.__mcpFrameProbeListenerV2;
|
|
27
|
+
}
|
|
28
|
+
console.warn("[MCP] iframe identity probe failed:", message);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener("message", onMessage);
|
|
32
|
+
probeWindow.__mcpFrameProbeListenerV2 = onMessage;
|
|
25
33
|
}
|
|
26
34
|
function generateAccessibilityTree(filter, maxDepth, maxLength, refId, expectedUrl) {
|
|
27
35
|
if (expectedUrl != null && location.href !== expectedUrl) throw new Error("页面 URL 已变化,未读取");
|
|
@@ -85,8 +93,10 @@ function generateAccessibilityTree(filter, maxDepth, maxLength, refId, expectedU
|
|
|
85
93
|
if (tag === "input") {
|
|
86
94
|
const input = element;
|
|
87
95
|
const inputType = input.type || "";
|
|
88
|
-
if (inputType
|
|
89
|
-
|
|
96
|
+
if (inputType !== "hidden" && inputType !== "password") {
|
|
97
|
+
const value = input.value;
|
|
98
|
+
if (value && (inputType === "submit" || value.length < 50)) return value.trim();
|
|
99
|
+
}
|
|
90
100
|
}
|
|
91
101
|
if ([
|
|
92
102
|
"button",
|
|
@@ -710,39 +720,25 @@ function simulateMouseClick(x, y, button, clickCount = 1, refId) {
|
|
|
710
720
|
bubbles: false
|
|
711
721
|
}));
|
|
712
722
|
element.dispatchEvent(new MouseEvent("mousemove", released));
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
detail: 1
|
|
716
|
-
}));
|
|
717
|
-
if ("focus" in element && typeof element.focus === "function") element.focus();
|
|
718
|
-
element.dispatchEvent(new MouseEvent("mouseup", {
|
|
719
|
-
...released,
|
|
720
|
-
detail: 1
|
|
721
|
-
}));
|
|
722
|
-
if (button === "right") element.dispatchEvent(new MouseEvent("contextmenu", released));
|
|
723
|
-
else element.dispatchEvent(new MouseEvent("click", {
|
|
724
|
-
...released,
|
|
725
|
-
detail: 1
|
|
726
|
-
}));
|
|
727
|
-
for (let i = 2; i <= clickCount; i++) {
|
|
723
|
+
const clickType = button === "right" ? "contextmenu" : button === "middle" ? "auxclick" : "click";
|
|
724
|
+
for (let detail = 1; detail <= clickCount; ++detail) {
|
|
728
725
|
element.dispatchEvent(new MouseEvent("mousedown", {
|
|
729
726
|
...pressed,
|
|
730
|
-
detail
|
|
727
|
+
detail
|
|
731
728
|
}));
|
|
729
|
+
if (detail === 1 && "focus" in element && typeof element.focus === "function") element.focus();
|
|
732
730
|
element.dispatchEvent(new MouseEvent("mouseup", {
|
|
733
731
|
...released,
|
|
734
|
-
detail
|
|
732
|
+
detail
|
|
733
|
+
}));
|
|
734
|
+
element.dispatchEvent(new MouseEvent(clickType, {
|
|
735
|
+
...released,
|
|
736
|
+
detail
|
|
737
|
+
}));
|
|
738
|
+
if (button === "left" && detail === 2) element.dispatchEvent(new MouseEvent("dblclick", {
|
|
739
|
+
...released,
|
|
740
|
+
detail
|
|
735
741
|
}));
|
|
736
|
-
if (button !== "right") {
|
|
737
|
-
element.dispatchEvent(new MouseEvent("click", {
|
|
738
|
-
...released,
|
|
739
|
-
detail: i
|
|
740
|
-
}));
|
|
741
|
-
if (i === 2) element.dispatchEvent(new MouseEvent("dblclick", {
|
|
742
|
-
...released,
|
|
743
|
-
detail: i
|
|
744
|
-
}));
|
|
745
|
-
}
|
|
746
742
|
}
|
|
747
743
|
return { success: true };
|
|
748
744
|
}
|
|
@@ -807,7 +803,8 @@ async function simulateKeyboardType(text, delay, deadline) {
|
|
|
807
803
|
activeElement.dispatchEvent(new Event("change", { bubbles: true }));
|
|
808
804
|
return { success: true };
|
|
809
805
|
}
|
|
810
|
-
function simulateKeyEvent(key, type, modifiers) {
|
|
806
|
+
function simulateKeyEvent(key, type, modifiers, deadline) {
|
|
807
|
+
if (deadline !== void 0 && Date.now() >= deadline) throw new Error("input timeout before event dispatch");
|
|
811
808
|
const activeElement = document.activeElement || document.body;
|
|
812
809
|
const keyEventOptions = {
|
|
813
810
|
bubbles: true,
|
|
@@ -843,8 +840,10 @@ function simulateMouseEvent(type, x, y, button, deadline) {
|
|
|
843
840
|
};
|
|
844
841
|
element.dispatchEvent(new MouseEvent(type, eventOptions));
|
|
845
842
|
if (type === "mousedown" && "focus" in element && typeof element.focus === "function") element.focus();
|
|
846
|
-
if (type === "mouseup")
|
|
847
|
-
|
|
843
|
+
if (type === "mouseup") {
|
|
844
|
+
const clickType = button === "right" ? "contextmenu" : button === "middle" ? "auxclick" : "click";
|
|
845
|
+
element.dispatchEvent(new MouseEvent(clickType, eventOptions));
|
|
846
|
+
}
|
|
848
847
|
return { success: true };
|
|
849
848
|
}
|
|
850
849
|
function injectStealthScripts() {
|
|
@@ -1296,13 +1295,13 @@ function inspectChallengePage(options) {
|
|
|
1296
1295
|
return rect.width >= 250 && rect.width <= 340 && rect.height >= 50 && rect.height <= 85;
|
|
1297
1296
|
}) || candidates[0];
|
|
1298
1297
|
};
|
|
1299
|
-
const turnstileBox = findVisibleTurnstileBox();
|
|
1300
1298
|
const hostVerify = Array.from(document.querySelectorAll(options.verifyButtonSelectors.join(","))).find(isVisible) || Array.from(document.querySelectorAll("button")).find((el) => {
|
|
1301
1299
|
const text = (el.textContent || "").trim();
|
|
1302
1300
|
return isVisible(el) && (text === "Verify you are human" || text === "请验证您是真人");
|
|
1303
1301
|
});
|
|
1304
|
-
const
|
|
1305
|
-
const turnstilePresent = widgetHits.length > 0 ||
|
|
1302
|
+
const turnstileBox = !originResponsePending && (interstitialPending || widgetHits.length > 0) ? findVisibleTurnstileBox() : null;
|
|
1303
|
+
const turnstilePresent = widgetHits.length > 0 || Boolean(hostVerify) || !originResponsePending && interstitialPending && (cloudflareFramePresent || frameHits.length > 0 || Boolean(turnstileBox));
|
|
1304
|
+
const useIframeClick = turnstilePresent && (cloudflareFramePresent || !hostVerify && interstitialPending && Boolean(document.querySelector("input[name=\"cf-turnstile-response\"]")));
|
|
1306
1305
|
const pointFromRect = (rect, kind) => {
|
|
1307
1306
|
if (!rect || rect.width < 8 || rect.height < 8) return null;
|
|
1308
1307
|
const y = Math.round(rect.top + Math.min(rect.height, 65) / 2);
|
|
@@ -131,15 +131,16 @@ connectBtn.addEventListener("click", async () => {
|
|
|
131
131
|
saveTokenBtn.addEventListener("click", async () => {
|
|
132
132
|
saveTokenBtn.disabled = true;
|
|
133
133
|
try {
|
|
134
|
-
await chrome.runtime.sendMessage({
|
|
134
|
+
const response = await chrome.runtime.sendMessage({
|
|
135
135
|
type: "SET_PAIRING_TOKEN",
|
|
136
136
|
token: pairingTokenInput.value
|
|
137
137
|
});
|
|
138
|
+
if (response?.error || response?.success !== true) throw new Error(response?.error ?? "保存 token 失败");
|
|
138
139
|
pairingTokenInput.value = "";
|
|
139
140
|
await updateStatus();
|
|
140
141
|
} catch (error) {
|
|
141
142
|
console.error("Save token failed:", error);
|
|
142
|
-
authHelp.textContent =
|
|
143
|
+
authHelp.textContent = `保存 token 失败:${error instanceof Error ? error.message : String(error)}`;
|
|
143
144
|
} finally {
|
|
144
145
|
saveTokenBtn.disabled = false;
|
|
145
146
|
}
|
|
@@ -147,14 +148,15 @@ saveTokenBtn.addEventListener("click", async () => {
|
|
|
147
148
|
allowInsecureNoTokenInput.addEventListener("change", async () => {
|
|
148
149
|
allowInsecureNoTokenInput.disabled = true;
|
|
149
150
|
try {
|
|
150
|
-
await chrome.runtime.sendMessage({
|
|
151
|
+
const response = await chrome.runtime.sendMessage({
|
|
151
152
|
type: "SET_ALLOW_INSECURE_NO_TOKEN",
|
|
152
153
|
allow: allowInsecureNoTokenInput.checked
|
|
153
154
|
});
|
|
155
|
+
if (response?.error || response?.success !== true) throw new Error(response?.error ?? "保存无 token 连接设置失败");
|
|
154
156
|
await updateStatus();
|
|
155
157
|
} catch (error) {
|
|
156
158
|
console.error("Save insecure mode failed:", error);
|
|
157
|
-
authHelp.textContent =
|
|
159
|
+
authHelp.textContent = `保存无 token 连接设置失败:${error instanceof Error ? error.message : String(error)}`;
|
|
158
160
|
} finally {
|
|
159
161
|
allowInsecureNoTokenInput.disabled = false;
|
|
160
162
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "MCP Chrome",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"description": "Browser automation for Claude Code via MCP protocol",
|
|
6
6
|
"permissions": [
|
|
7
7
|
"alarms",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"content_scripts": [
|
|
39
39
|
{
|
|
40
40
|
"js": [
|
|
41
|
-
"assets/content.ts-loader-
|
|
41
|
+
"assets/content.ts-loader-DUWbDHRS.js"
|
|
42
42
|
],
|
|
43
43
|
"matches": [
|
|
44
44
|
"<all_urls>"
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"<all_urls>"
|
|
56
56
|
],
|
|
57
57
|
"resources": [
|
|
58
|
-
"assets/page-scripts-
|
|
59
|
-
"assets/content.ts-
|
|
58
|
+
"assets/page-scripts-D508WLkW.js",
|
|
59
|
+
"assets/content.ts-qe6IB5DK.js"
|
|
60
60
|
],
|
|
61
61
|
"use_dynamic_url": false
|
|
62
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import './assets/index.ts-
|
|
1
|
+
import './assets/index.ts-D7_LCUoV.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
|
6
6
|
<title>MCP Chrome</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/popup.html-
|
|
7
|
+
<script type="module" crossorigin src="/assets/popup.html-B-eVq48O.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/popup-BwuBB9Cz.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyrokine/mcp-chrome",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Chrome browser automation MCP Server using Chrome DevTools Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"dev": "node node_modules/typescript7/bin/tsc -w",
|
|
13
13
|
"prepare": "npm run build",
|
|
14
14
|
"prepack": "npm run build && npm run build:extension",
|
|
15
|
-
"lint": "eslint \"src
|
|
16
|
-
"lint:fix": "
|
|
17
|
-
"format": "prettier -w --prose-wrap=always src extension/src
|
|
18
|
-
"format:check": "prettier -c --prose-wrap=always src extension/src
|
|
15
|
+
"lint": "eslint \"{src,extension/src}/**/*.ts\" \"{test,extension/test}/**/*.js\" \"extension/vite*.ts\"",
|
|
16
|
+
"lint:fix": "npm run lint -- --fix",
|
|
17
|
+
"format": "prettier -w --prose-wrap=always src test \"extension/{src/**,test/**,vite*.ts}\" \"*.md\"",
|
|
18
|
+
"format:check": "prettier -c --prose-wrap=always src test \"extension/{src/**,test/**,vite*.ts}\" \"*.md\"",
|
|
19
19
|
"test": "npm run build && node --test test/*.test.js",
|
|
20
20
|
"test:extension": "npm --prefix extension test"
|
|
21
21
|
},
|
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
],
|
|
30
30
|
"author": "Pyrokine",
|
|
31
31
|
"license": "MIT",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/Pyrokine/claude-tools.git",
|
|
35
|
+
"directory": "mcp-chrome"
|
|
36
|
+
},
|
|
32
37
|
"dependencies": {
|
|
33
38
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
34
39
|
"ws": "^8.21.1",
|
|
@@ -57,5 +62,6 @@
|
|
|
57
62
|
"README.md",
|
|
58
63
|
"README_zh.md",
|
|
59
64
|
"LICENSE"
|
|
60
|
-
]
|
|
65
|
+
],
|
|
66
|
+
"gitHead": "8ecb805b68619692cf9b1a72eb0bc58e5e3f8b26"
|
|
61
67
|
}
|