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
- // First quick scan
16
- const tree = await cdp.send('Page.getFrameTree');
17
- const hit = scanTree(tree.frameTree, pattern);
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
- return await new Promise((resolve, reject) => {
23
- function onNav(ev) {
24
- const { frame } = ev;
25
- if (frame?.url && pattern.test(frame.url)) {
26
- cleanup();
27
- resolve({ frameId: frame.id, frameUrl: frame.url });
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
- function onTimeout() {
31
- cleanup();
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
- cdp.on('Page.frameNavigated', onNav);
38
- const left = Math.max(0, timeoutMs - (Date.now() - start));
39
- setTimeout(onTimeout, left);
40
- });
41
- function scanTree(node, rx) {
42
- if (node?.frame?.url && rx.test(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 = scanTree(c, rx);
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.0",
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",