zed-industries/zed · error · Error

Could not get screen resolution on Windows

Error message

Could not get screen resolution on Windows

What it means

On Windows, script/zed-local asks PowerShell to load System.Windows.Forms and print PrimaryScreen.WorkingArea.Size, then extracts the numbers with /\d+/g. The throw covers any failure in that pipeline: PowerShell execution policy or constrained language blocking Add-Type, a missing .NET/Windows Forms assembly, no interactive desktop — or output that doesn't match, making .match() return null so the .map() call throws inside the try.

Source

Thrown at script/zed-local:125

    const xrandrOutput = execSync('xrandr | grep "\\*" | cut -d" " -f4', {
      encoding: "utf8",
    }).trim();
    [screenWidth, screenHeight] = xrandrOutput.split("x").map(Number);
  } catch (err) {
    console.log(err);
    throw new Error("Could not get screen resolution");
  }
} else if (platform === "win32") {
  // windows
  try {
    const resolutionOutput = execSync(
      `powershell -Command "& {Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Size}"`,
      { encoding: "utf8" },
    ).trim();
    [screenWidth, screenHeight] = resolutionOutput.match(/\d+/g).map(Number);
  } catch (err) {
    console.log(err);
    throw new Error("Could not get screen resolution on Windows");
  }
}

if (platform !== "win32") {
  screenHeight -= titleBarHeight;
}

if (isTop) {
  screenHeight = Math.floor(screenHeight / 2);
}

// Determine the window size for each instance
let rows;
let columns;
switch (instanceCount) {
  case 1:
    [rows, columns] = [1, 1];
    break;

View on GitHub (pinned to bc538def45)

Solutions

  1. Run the exact PowerShell one-liner in a terminal on the machine and inspect its output
  2. Run the script from an interactive user session, not a service
  3. If Add-Type is blocked, switch to another source, e.g. `wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution`
  4. Null-check the regex match before .map()

Example fix

// before
[screenWidth, screenHeight] = resolutionOutput.match(/\d+/g).map(Number);

// after
const digits = resolutionOutput.match(/\d+/g);
if (!digits || digits.length < 2) throw new Error("unexpected PowerShell output");
[screenWidth, screenHeight] = digits.map(Number);
Defensive patterns

Strategy: fallback

Try / catch

try {
  [screenWidth, screenHeight] = resolutionOutput.match(/\d+/g).map(Number);
} catch {
  console.warn("Windows resolution probe failed; defaulting to 1920x1080");
  [screenWidth, screenHeight] = [1920, 1080];
}

Prevention

When it happens

Trigger: Running from a Windows service or session 0 with no interactive desktop; constrained language mode rejecting Add-Type; Server Core or trimmed .NET without Windows Forms; localized/unexpected output leaving no digits.

Common situations: CI agents running as services; hardened Windows boxes; Windows Server Core containers.

Related errors


AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16). Data as JSON: /api/errors/42c1096e06052be7. Report an issue: GitHub.