chrome-devtools-mcp-for-extension 0.9.3 → 0.9.4

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.
@@ -49,24 +49,60 @@ export async function waitForExtensionChildTarget(cdp, pattern, timeoutMs = 8000
49
49
  });
50
50
  }
51
51
  export async function inspectIframe(cdp, urlPattern, waitMs = 8000) {
52
- // Enable OOPIF auto-attach
53
- await enableOopifAutoAttach(cdp);
54
- // Wait for child target (extension iframe)
55
- const child = await waitForExtensionChildTarget(cdp, urlPattern, waitMs);
56
- // Enable Page/Runtime in child session
57
- await sendToChildSession(cdp, child.sessionId, 'Page.enable', {});
58
- await sendToChildSession(cdp, child.sessionId, 'Runtime.enable', {});
59
- // Evaluate outerHTML in child session
60
- const htmlResult = await sendToChildSession(cdp, child.sessionId, 'Runtime.evaluate', {
61
- expression: 'document.documentElement.outerHTML',
62
- returnByValue: true,
63
- });
64
- const html = String(htmlResult?.result?.value ?? '');
65
- return {
66
- frameId: child.targetId, // Use targetId as frameId for OOPIF
67
- frameUrl: child.url,
68
- html,
69
- };
52
+ // Try OOPIF detection first
53
+ try {
54
+ await enableOopifAutoAttach(cdp);
55
+ const child = await waitForExtensionChildTarget(cdp, urlPattern, waitMs);
56
+ // Enable Page/Runtime in child session
57
+ await sendToChildSession(cdp, child.sessionId, 'Page.enable', {});
58
+ await sendToChildSession(cdp, child.sessionId, 'Runtime.enable', {});
59
+ // Evaluate outerHTML in child session
60
+ const htmlResult = await sendToChildSession(cdp, child.sessionId, 'Runtime.evaluate', {
61
+ expression: 'document.documentElement.outerHTML',
62
+ returnByValue: true,
63
+ });
64
+ const html = String(htmlResult?.result?.value ?? '');
65
+ return {
66
+ frameId: child.targetId,
67
+ frameUrl: child.url,
68
+ html,
69
+ };
70
+ }
71
+ catch (oopifError) {
72
+ // Fallback: Try regular iframe via Page.getFrameTree
73
+ await cdp.send('Page.enable');
74
+ const { frameTree } = await cdp.send('Page.getFrameTree');
75
+ const findFrame = (node) => {
76
+ if (urlPattern.test(node.frame.url)) {
77
+ return node.frame;
78
+ }
79
+ if (node.childFrames) {
80
+ for (const child of node.childFrames) {
81
+ const found = findFrame(child);
82
+ if (found)
83
+ return found;
84
+ }
85
+ }
86
+ return null;
87
+ };
88
+ const frame = findFrame(frameTree);
89
+ if (!frame) {
90
+ throw new Error(`Iframe not found (tried both OOPIF and regular iframe): ${urlPattern}`);
91
+ }
92
+ // Execute in the frame context
93
+ await cdp.send('Runtime.enable');
94
+ const htmlResult = await cdp.send('Runtime.evaluate', {
95
+ expression: 'document.documentElement.outerHTML',
96
+ returnByValue: true,
97
+ contextId: frame.id,
98
+ });
99
+ const html = String(htmlResult?.result?.value ?? '');
100
+ return {
101
+ frameId: frame.id,
102
+ frameUrl: frame.url,
103
+ html,
104
+ };
105
+ }
70
106
  }
71
107
  async function sendToChildSession(cdp, sessionId, method, params) {
72
108
  const id = Math.floor(Math.random() * 1000000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp-for-extension",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
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",