Closed Bug 2027926 (mcp-js-generate-expr) Opened 16 days ago Closed 13 days ago

MCP eval in chrome statements abort because LLMs sending statements where expressions are required.

Categories

(Developer Infrastructure :: AI for Development, defect)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: dmosedale, Assigned: dmosedale)

References

(Blocks 1 open bug)

Details

When I'm doing complicated stuff with the MCP, it often generates JavaScript statements for context where the JS interpreter in Firefox is expecting a JavaScript expression, causing the eval to abort. I've got a patch that makes this situation much better.

Example:

⏺ firefox-devtools - screenshot_page (MCP)(saveTo: "/tmp/ai-window.png")
  ⎿  Screenshot saved to: /tmp/ai-window.png (463.0KB)

⏺ firefox-devtools - take_snapshot (MCP)(includeAttributes: true, maxLines: 150)
  ⎿  Error: Failed to take snapshot: Failed to generate snapshot: Unknown error

     The page may not be fully loaded or accessible.

  Read 1 file (ctrl+o to expand)

⏺ I can see the AI window with the smartbar. The snapshot failed because this is a chrome
  context. Let me try snapshotting via the content area, and also look at the DOM by
  evaluating scripts.

⏺ firefox-devtools - evaluate_privileged_script (MCP)(expression: "\n// Find the
                                                     smartbar-related elements in the AI
                                                     window\nconst doc = document;\nconst
                                                     browser = doc.getElementById(\"ai-window
                                                     -browser\");\nif (browser &&
                                                     browser.contentDocument) {\n  const cdoc
                                                      = browser.contentDocument;\n  // Look
                                                     for smartbar-related elements\n  const
                                                     smartbar =
                                                     cdoc.querySelector(\".smartbar,
                                                     [class*='smartbar'],
                                                     [id*='smartbar']\");\n  const dropdown =

                                                     cdoc.querySelector(\".smartbar-dropdown,
                                                      [class*='dropdown'],
                                                     [id*='dropdown']\");\n  const all =
                                                     cdoc.querySelectorAll(\"*\");\n  const
                                                     tags = new Set();\n  const classes = new
                                                      Set();\n  all.forEach(el => {\n
                                                     tags.add(el.tagName.toLowerCase());\n
                                                      el.classList.forEach(c =>
                                                     classes.add(c));\n  });\n
                                                     JSON.stringify({\n    smartbarFound:
                                                     !!smartbar,\n    dropdownFound:
                                                     !!dropdown,\n    smartbarTag:
                                                     smartbar?.tagName,\n    smartbarClasses:
                                                      smartbar?.className,\n    dropdownTag:
                                                     dropdown?.tagName,\n    dropdownClasses:
                                                      dropdown?.className,\n    allTags:
                                                     [...tags].sort(),\n    allClasses:
                                                     [...classes].sort().slice(0, 80)\n
                                                     });\n} else {\n  \"No ai-window-browser
                                                     or no contentDocument
                                                     accessible\";\n}\n")
  ⎿  Error: Script execution failed: SyntaxError: expected expression, got keyword 'const'
You need to log in before you can comment on or make changes to this bug.