Skip to content

fix(computer): add PowerShell screenshot fallback for Windows Claude Code environments#2175

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-midscene-trigger-error
Draft

fix(computer): add PowerShell screenshot fallback for Windows Claude Code environments#2175
Copilot wants to merge 2 commits intomainfrom
copilot/fix-midscene-trigger-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

npx @midscene/computer connect fails during health check on Windows when invoked from Claude Code (or similar MCP hosts), while the same command works fine in a standalone terminal. The screenshot step crashes with a garbled error—the Chinese "command not recognized" message in GBK encoding read as UTF-8:

Error: Failed to take screenshot: Error: Command failed: cmd.exe /c ...\screenCapture_1.3.2.bat ...\screenshot.png
'screenCapture_1.3.2.exe' ♦♦♦♦♦ζ♦♦♦♦н♦♦♦♦Χ♦♦♦♦б♦♦♦♦еij♦♦♦

Root cause: screenshot-desktop compiles a .NET exe at runtime from a polyglot .bat/C# file and runs it from %TEMP%\screenCapture\. Claude Code's environment (UTF-8 code page 65001 and/or AppLocker/WDAC policies) prevents that dynamically-compiled, unsigned exe from being located or executed.

Changes — packages/computer/src/device.ts

  • New screenshotViaWindowsPowerShell() method: takes a screenshot via powershell.exe using System.Windows.Forms.Screen + System.Drawing.Graphics.CopyFromScreen. The script is passed via -EncodedCommand (UTF-16LE base64), sidestepping shell-quoting and code-page issues entirely. PowerShell is a signed Microsoft binary not subject to the same execution restrictions.
  • Fallback in screenshotBase64(): on Windows, if screenshot-desktop throws, the PowerShell path is tried automatically; both errors are surfaced if both fail.
  • Security: displayId is sanitized ([a-zA-Z0-9\\.\-_:] only) before interpolation into the PowerShell string to prevent injection.
  • Temp file uniqueness: process.pid + Date.now() + random suffix avoids collisions under concurrent calls.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.npmjs.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Error occurs when triggering Midscene with skills in Claude Code</issue_title>
<issue_description>### Version

System:
    OS: Windows 11 10.0.26200
    CPU: (20) x64 Intel(R) Core(TM) i5-14600KF
    Memory: 15.88 GB / 31.84 GB
  Browsers:
    Edge: Chromium (141.0.3537.57)

Details

在单独的命令行可正常执行

Image

但是在Claude Code中执行报错

Image

Reproduce link

NA

Reproduce Steps

在Claude Code中执行npx @midscene/computer@1 connect或直接使用工具触发。
我试了我自己的电脑,还有阿里的云电脑都不行。</issue_description>

Comments on the Issue (you are @copilot in this section)

@quanru Please upload the completed log.

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…de Code

Co-authored-by: quanru <11739753+quanru@users.noreply.github.com>
Copilot AI changed the title [WIP] [Bug] Fix error when triggering Midscene in Claude Code fix(computer): add PowerShell screenshot fallback for Windows Claude Code environments Mar 18, 2026
Copilot AI requested a review from quanru March 18, 2026 10:17
@cloudflare-workers-and-pages
Copy link

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: 493cd48
Status: ✅  Deploy successful!
Preview URL: https://4993e06d.midscene.pages.dev
Branch Preview URL: https://copilot-fix-midscene-trigger.midscene.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Error occurs when triggering Midscene with skills in Claude Code

2 participants