{"record":{"id":"ab86c0064ef42e7e","repo":"MagicMirrorOrg/MagicMirror","slug":"could-not-get-display-size-using-defaults","errorCode":null,"errorMessage":"Could not get display size, using defaults ...","messagePattern":"Could not get display size, using defaults \\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"js/electron.js","lineNumber":44,"sourceCode":" * Keep a global reference of the window object, if you don't, the window will\n * be closed automatically when the JavaScript object is garbage collected.\n */\nlet mainWindow;\n\n/**\n *\n */\nfunction createWindow () {\n\n\t/*\n\t * see https://www.electronjs.org/docs/latest/api/screen\n\t * Create a window that fills the screen's available work area.\n\t */\n\tlet electronSize = { width: 800, height: 600 };\n\ttry {\n\t\telectronSize = electron.screen.getPrimaryDisplay().workAreaSize;\n\t} catch {\n\t\tLog.warn(\"Could not get display size, using defaults ...\");\n\t}\n\n\tapplyElectronSwitches(app.commandLine, config.electronSwitches);\n\tlet electronOptionsDefaults = {\n\t\twidth: electronSize.width,\n\t\theight: electronSize.height,\n\t\ticon: \"favicon.svg\",\n\t\tx: 0,\n\t\ty: 0,\n\t\tdarkTheme: true,\n\t\twebPreferences: {\n\t\t\tcontextIsolation: true,\n\t\t\tnodeIntegration: false,\n\t\t\tzoomFactor: config.zoom\n\t\t},\n\t\tbackgroundColor: \"#000000\"\n\t};\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/MagicMirrorOrg/MagicMirror/blob/4b4a59534f7da01e4030e46029fe9dd649a7675e/js/electron.js#L26-L62","documentation":"In the Electron main process, createWindow queries the primary display's work area size to size the mirror window. If electron.screen.getPrimaryDisplay() throws — e.g. no display is attached or Electron cannot access screen information (common on headless systems or when the app is not ready) — the code falls back to a default 800x600 window and logs this warning.","triggerScenarios":"MagicMirror run with Electron on a machine with no attached/active display (headless server, X not running), or getPrimaryDisplay() called before the app 'ready' event so screen info is unavailable.","commonSituations":"Running the full MagicMirror (not serveronly) on a Raspberry Pi with no monitor or via SSH; Docker containers without a display; broken X/Wayland sessions where the screen module reports no primary display.","solutions":["Attach/enable a display or start the X server so the system has a primary display.","If no display is intended, run in server-only mode: node serveronly (or MM_SERVERONLY=true) instead of the Electron app.","For headless setups, use a virtual display (e.g. xserver-xorg with a dummy driver, or run inside a real desktop session).","Ensure Electron starts after app 'ready' (this is handled by the app; just don't remove the ready listener).","Ignore the warning if the 800x600 default is acceptable — the window can be resized via electronOptions in config.js."],"exampleFix":"// before (headless)\nnpm start   # Electron fails to find display, 800x600 window\n// after\nnode serveronly   # or attach a display / configure a dummy X screen","handlingStrategy":"fallback","validationCode":"// Before launching Electron, detect a usable display\nconst hasDisplay = !!process.env.DISPLAY || !!process.env.WAYLAND_DISPLAY;\nif (!hasDisplay) console.warn(\"No display detected; run 'node serveronly' instead of the Electron app.\");","typeGuard":"function displayAvailable(electron) {\n  try { return Boolean(electron.screen.getPrimaryDisplay()); }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  const size = electron.screen.getPrimaryDisplay().workAreaSize;\n} catch {\n  Log.warn(\"No display; using default 800x600 window size\");\n}","preventionTips":["On headless machines, run 'node serveronly' instead of npm start (Electron).","Configure a dummy/virtual X display if a GUI session is required remotely.","Set explicit electronOptions width/height in config.js so a missing screen doesn't matter."],"tags":["electron","display","headless","fallback"],"backgroundTag":"no-display-available","analyzedSha":"4b4a59534f7da01e4030e46029fe9dd649a7675e","analyzedAt":"2026-08-31T21:49:42.591Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}