chrome-devtools-mcp-for-extension 0.9.0 → 0.9.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.
|
@@ -12,38 +12,56 @@ export async function findExtensionIdViaTargets(cdp) {
|
|
|
12
12
|
}
|
|
13
13
|
export async function waitForFrameByUrlMatch(cdp, pattern, timeoutMs = 5000) {
|
|
14
14
|
await cdp.send('Page.enable');
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (hit)
|
|
19
|
-
return hit;
|
|
20
|
-
// Then wait for navigation events
|
|
15
|
+
await cdp.send('Runtime.enable');
|
|
16
|
+
await cdp.send('DOM.enable');
|
|
17
|
+
// Strategy: Find iframe in DOM, then match Frame ID
|
|
21
18
|
const start = Date.now();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
while (Date.now() - start < timeoutMs) {
|
|
20
|
+
try {
|
|
21
|
+
// Get document root
|
|
22
|
+
const { root } = await cdp.send('DOM.getDocument', { depth: -1 });
|
|
23
|
+
// Query all iframes
|
|
24
|
+
const { nodeIds } = await cdp.send('DOM.querySelectorAll', {
|
|
25
|
+
nodeId: root.nodeId,
|
|
26
|
+
selector: 'iframe',
|
|
27
|
+
});
|
|
28
|
+
// Check each iframe's src
|
|
29
|
+
for (const nodeId of nodeIds) {
|
|
30
|
+
const attrs = await cdp.send('DOM.getAttributes', { nodeId });
|
|
31
|
+
const srcIndex = attrs.attributes.indexOf('src');
|
|
32
|
+
if (srcIndex >= 0 && srcIndex + 1 < attrs.attributes.length) {
|
|
33
|
+
const src = attrs.attributes[srcIndex + 1];
|
|
34
|
+
if (pattern.test(src)) {
|
|
35
|
+
// Get contentDocument frame ID
|
|
36
|
+
const { node } = await cdp.send('DOM.describeNode', { nodeId });
|
|
37
|
+
if (node.contentDocument) {
|
|
38
|
+
const frameId = node.contentDocument.frameId || node.frameId;
|
|
39
|
+
if (frameId) {
|
|
40
|
+
return { frameId, frameUrl: src };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Fallback: try Frame Tree match
|
|
44
|
+
const tree = await cdp.send('Page.getFrameTree');
|
|
45
|
+
const hit = findFrameByUrl(tree.frameTree, src);
|
|
46
|
+
if (hit)
|
|
47
|
+
return hit;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
28
50
|
}
|
|
29
51
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
reject(new Error(`Timeout waiting for frame by url match: ${pattern}`));
|
|
33
|
-
}
|
|
34
|
-
function cleanup() {
|
|
35
|
-
cdp.off('Page.frameNavigated', onNav);
|
|
52
|
+
catch (e) {
|
|
53
|
+
// DOM may not be ready yet, continue waiting
|
|
36
54
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
function
|
|
42
|
-
if (node?.frame?.url
|
|
55
|
+
// Wait a bit before retry
|
|
56
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Timeout waiting for iframe by url match: ${pattern}`);
|
|
59
|
+
function findFrameByUrl(node, url) {
|
|
60
|
+
if (node?.frame?.url === url) {
|
|
43
61
|
return { frameId: node.frame.id, frameUrl: node.frame.url };
|
|
44
62
|
}
|
|
45
63
|
for (const c of node.childFrames ?? []) {
|
|
46
|
-
const r =
|
|
64
|
+
const r = findFrameByUrl(c, url);
|
|
47
65
|
if (r)
|
|
48
66
|
return r;
|
|
49
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-devtools-mcp-for-extension",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "MCP server for Chrome extension development with Web Store automation. Fork of chrome-devtools-mcp with extension-specific tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./build/src/index.js",
|