Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If screen.getPrimaryDisplay() is undefined, the call is usually running in the renderer process (or DevTools) instead of Electron’s main process, or it runs before Electron has emitted ready. Import screen in the main process and call it after app.whenReady() resolves.

The documented fix

Electron classifies the screen module as main-process only. The smallest working pattern is:

const { app, BrowserWindow, screen } = require('electron/main')

app.whenReady().then(() => {
  const primaryDisplay = screen.getPrimaryDisplay()
  const { width, height } = primaryDisplay.workAreaSize

  const mainWindow = new BrowserWindow({ width, height })
  mainWindow.loadURL('https://electronjs.org')
})

This follows Electron’s documented example. Adapt the window options and page URL to your application. The important parts are the process, import, and timing: the call is in the main process, and it executes only after app.whenReady().

Why the value is undefined

The line is running in the wrong process

Renderer JavaScript executes inside a browser window. DevTools code executes in that same renderer context. Neither context owns Electron’s main-process screen module. If the failing file is loaded by a window, preload, or DevTools console, move the actual display query to the main process.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Electron’s screen documentation also warns that, in the renderer and DevTools, window.screen is a reserved DOM property. Consequently, writing let { screen } = require('electron') there does not give you Electron’s screen API. A browser’s window.screen describes the web page’s screen-related properties; it is not the Electron screen module.

The call runs before app readiness

The screen module cannot be used until the app emits its ready event. Calling it at top level, before the event, can fail even when the code is in the correct file. Put the call inside app.whenReady().then(...), or run it from a code path that you know executes after readiness. Electron exposes app.isReady() when you need to check the current state.

Move display information across the process boundary

A renderer should not import or call Electron’s main-only screen API. Instead, have the main process obtain the display and return only the values the user interface needs. The exact IPC arrangement depends on your security model; the following CommonJS example keeps the screen query in the main process and exposes one narrowly scoped operation through a preload script.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Main process

const { app, BrowserWindow, ipcMain, screen } = require('electron/main')
const path = require('node:path')

let mainWindow

app.whenReady().then(() => {
  ipcMain.handle('display:get-primary-work-area', () => {
    const { workArea, workAreaSize, bounds, scaleFactor } = screen.getPrimaryDisplay()
    return { workArea, workAreaSize, bounds, scaleFactor }
  })

  mainWindow = new BrowserWindow({
    width: 1000,
    height: 700,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      contextIsolation: true,
      nodeIntegration: false
    }
  })

  mainWindow.loadFile('index.html')
})

Register the handler after readiness so a renderer cannot ask for display data before Electron has initialized the module. The returned object contains a snapshot; if monitors are added, removed, or repositioned later, request a new snapshot rather than assuming the old values remain current.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Preload script

const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('displayAPI', {
  getPrimaryWorkArea: () => ipcRenderer.invoke('display:get-primary-work-area')
})

Renderer code

document.querySelector('#read-display').addEventListener('click', async () => {
  try {
    const display = await window.displayAPI.getPrimaryWorkArea()
    document.querySelector('#output').textContent =
      JSON.stringify(display, null, 2)
  } catch (error) {
    document.querySelector('#output').textContent = error.message
  }
})

This pattern prevents the renderer from trying to resolve screen.getPrimaryDisplay itself. If your project already has an IPC or preload abstraction, add an equivalent method there instead of exposing the entire Electron API.

Check your project in the right order

  1. Identify the executing file. Follow the stack trace to the JavaScript file that contains the failing expression. Determine whether that file is your main entry point, a preload script, a renderer bundle, or DevTools input.
  2. Confirm the import. In the main process, compare your import with the documented require('electron/main') pattern. Verify that the variable you call screen is the imported module, not a local variable or the browser’s window.screen.
  3. Confirm readiness. Move the call into app.whenReady(). If you use a helper function, call that helper from the readiness callback rather than invoking it while the module is being loaded.
  4. Check the installed Electron version. Read the version from the project’s package configuration and compare its API documentation with the rolling documentation for a different release. Behavior or import guidance can differ between versions.
  5. Reduce the case. Temporarily replace your window setup with the short documented example. If that works, restore your application code incrementally; the first change that reintroduces the error identifies the incorrect process or lifecycle path.

Or skip the browser setup

If your actual task is capturing a website for a test, report, preview, or AI workflow—not reading the user’s physical monitors—ScreenshotNeo is a separate website screenshot API. It does not repair Electron’s screen import; it removes the need to launch and manage a browser solely to capture a URL.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

One GET request returns PNG, JPEG, WebP, or PDF. Before capture, ScreenshotNeo accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers identify the page verdict and whether the request was billed.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for authentication, output formats, and all request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://stripe.com'
})
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`)
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`)
const file = Buffer.from(await res.arrayBuffer())
require('node:fs').writeFileSync('shot.webp', file)

ScreenshotNeo also provides an MCP server for Claude, Cursor, and other MCP clients, with take_screenshot, get_page_info, and capture_pdf tools. Its 63 options include full-page capture with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper size and page ranges, custom CSS and JavaScript, pre-capture clicks, selector or network-idle waits, ad/tracker/request blocking, custom headers and cookies, user-agent and Authorization values, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous jobs with signed webhooks, bulk capture for 100 URLs per call, a usage API, an OpenAPI specification, and familiar parameter names for easier migration.

Plan Allowance Price
Free 1,000 shots per month $0, no card
Starter 3,000 shots $5
Growth 15,000 shots $15
Pro 60,000 shots $39
Scale 250,000 shots $99
Business 1,000,000 shots $249

Every feature is included on every plan, and yearly billing gives two months free. Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Common errors and their fixes

Symptom Likely cause Fix
screen is undefined in a renderer bundle The code is executing in the renderer, where Electron’s main-process module is unavailable. Move the query to the main process and return the result through preload and IPC.
let { screen } = require('electron') produces an unexpected value In renderer or DevTools, screen collides with the reserved DOM property window.screen. Do not destructure Electron’s screen module in that context. Use a main-process handler.
The import exists, but the call fails during startup The call occurs before the app’s ready event. Put it inside app.whenReady() or after a readiness check.
The minimal example works but the application does not A wrapper, preload boundary, renamed variable, or alternate entry point changes the process or call order. Compare the working example with your actual entry file and restore changes one at a time.
The error remains after moving the call The installed Electron release, import syntax, or stack trace may differ from the assumptions above. Record the Electron version, exact import, executing file, complete error text, and stack trace, then consult the documentation for that release.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Lifecycle and display details that affect results

Readiness is not window creation

You can query the primary display after the app is ready and before creating a BrowserWindow; the documented example does exactly that. Creating a window first does not make the screen module available earlier. Conversely, creating a window does not automatically make renderer code authorized to call the main-only module.

Use the right display fields

screen.getPrimaryDisplay() returns Electron’s Display object for the primary display. Its workAreaSize excludes areas reserved by system UI, while bounds describes the display rectangle. Choose the field that matches your goal: sizing a window for usable desktop space is different from measuring the full display bounds.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Expect a snapshot, not a permanent subscription

The value returned by getPrimaryDisplay() represents the display state at the time of the call. If your application supports monitor changes or resolution changes, request fresh data when your own display-change handling runs. Do not cache the initial dimensions indefinitely.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Final verification checklist

  • The failing expression is executed by the main process, not a renderer or DevTools.
  • The main entry imports screen using the syntax appropriate for the installed Electron version.
  • The query runs after app.whenReady() resolves or after the ready event.
  • Renderer code receives values through your existing preload/IPC boundary instead of importing screen.
  • Your test records the Electron version and the complete stack trace if the minimal pattern still fails.

Frequently Asked Questions

Does `getPrimaryDisplay()` return the monitor where my window is currently located?

No. It returns the `Display` object Electron designates as the primary display. If you need the display containing a particular window, use the appropriate display-selection logic in the main process rather than assuming the primary display is the window’s display.

Can a renderer use the browser’s `window.screen` instead?

It can read the browser DOM property, but that is a different API and does not provide Electron’s `Display` object. Use the main-process query when you need Electron display bounds, work-area dimensions, or scale information.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.