screenshot-desktop icon indicating copy to clipboard operation
screenshot-desktop copied to clipboard

LINUX Command failed: xrandr Can't open display

Open rohit5ram opened this issue 3 years ago • 3 comments

Describe the bug I used screenshot-desktop in my nodejs application which runs as a system service. The application is crashing with the below error

node:child_process:397
      ex = new Error('Command failed: ' + cmd + '\n' + stderr);
           ^
Error: Command failed: xrandr
	
    at ChildProcess.exithandler (node:child_process:397:12)
    at ChildProcess.emit (node:events:390:28)
    at ChildProcess.emit (node:domain:475:12)
    at maybeClose (node:internal/child_process:1064:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:390:28)
    at Socket.emit (node:domain:475:12)
    at Pipe.<anonymous> (node:net:687:12) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'xrandr'
}

To Reproduce Steps to reproduce the behavior: Use an example from the project and run the app as a system service in Linux

Expected behavior A clear and concise description of what you expected to happen. Should capture screenshot even when the application runs as a service Should not crash the application. The error should be handled gracefully in promise. reject.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Engine Node
  • Version 16.9.1

Additional context I tried editing listDisplays() method as 'DISPLAY=:0.0 xrandr' instead of 'xrandr' but it didn't work either

rohit5ram avatar Dec 28 '21 16:12 rohit5ram

@bencevans Please look into it. Any help is really appreciated. It works when the application is run as a user process but it doesn't when the application runs as a service

rohit5ram avatar Dec 28 '21 16:12 rohit5ram

Thanks for your report, @rohit5ram. I suspect it's a security issue that limits access from the system user to the display. Please could you share the unit/service file you're using?

bencevans avatar Dec 29 '21 13:12 bencevans

Make sure that the port that you have mentioned is open and available.

AkshayMaestro avatar Aug 13 '22 10:08 AkshayMaestro

This may also be linked to #220. Ubuntu has been switching Wayland rather than X11 as the default display server. Currently, screenshot-desktop only has x11 support. You can tell which is running echo $XDG_SESSION_TYPE in Terminal. It should print out either x11 or wayland 1.

bencevans avatar Aug 30 '22 08:08 bencevans