0

In Linux on my Chromebook, I am trying to take a screenshot using the command line, but nothing seems to be working. I have tried ImageMagick...

sudo apt-get install imagemagick

import -window root filename.png
# "unable to read X window image 'root'"

import filename.png
# "unable to grab mouse '': No such file or directory"

And I have also tried scrot...

sudo apt-get install scrot

scrot -u filename.png
#"BadDrawable (invalid Pixmap or Window parameter)"

I tried several python methods, but the only one that I could successfully install and get to run without errors was pyscreeze (which uses scrot), and it produced nothing but a blank, black image, which is useless to me.

In terms of other python methods, I tried pyautogui which failed to install, telling me "Failed building wheel for Pillow." I tried pyscreenshot, which installed and ran but told me "All backends failed." I also tried ImageGrab, which told me "ImageGrab is MacOS and Windows only."

Does anyone know of a way to make this work?

Thanks in advance!

gcdev
  • 1,406
  • 3
  • 17
  • 30
  • Hi @gcdev, Do you find any reason why it's not working on Chromebook ChromeOS? Why do we get a black screenshots? – Nikhil Nov 01 '21 at 13:26
  • @Nikhil no, I didn't. I stopped researching this shortly after posting this question, giving up. But if someone offers a solution, I will revisit it! – gcdev Nov 02 '21 at 14:31
  • What are you trying to take a screenshot of? You can't take a screenshot of the ChromeOS desktop from the Linux container, but you can take a screenshot of a window of an app from the Linux container (eg Firefox) or a desktop environment you've installed within the Linux container (eg XFCE). – asdf3.14159 Jul 24 '22 at 20:34
  • @asdf3.14159 I wanted the entire desktop, with all open apps included. – gcdev Jul 26 '22 at 21:01
  • I'm not sure what you're making, but you can make an web app / extension to take screenshots with JavaScript, if that helps? – asdf3.14159 Aug 08 '22 at 12:38
  • @asdf3.14159 would that get screenshots that include Android apps and Linux apps, or only the Chrome browser? – gcdev Aug 09 '22 at 14:34
  • Anything on your screen. I'm adding an answer. – asdf3.14159 Aug 09 '22 at 15:03

2 Answers2

2

Javascript solution

Here is a way to take a screenshot of any part of the chromebook's screen, a chrome window, or a chrome tab.

Paste this into your browser console to take a screenshot.

async function takeScreenshot(format = "image/png") {
  const stream = await navigator.mediaDevices.getDisplayMedia({video:true});

  const video = document.createElement("video");
  video.srcObject = stream;
  video.muted = true;
  await video.play();

  const canvas = document.createElement("canvas");
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;
  const context = canvas.getContext("2d");

  context.drawImage(video, 0, 0);

  const blob = await new Promise(resolve => canvas.toBlob(resolve, format));

  stream.getTracks().forEach(track => track.stop());

  return blob;
}

function download(blob, name = "Untitled") {
  const elt = document.createElement("a");
  elt.download = name;
  elt.href = URL.createObjectURL(blob);
  elt.click();
  URL.revokeObjectURL(elt.href);
}

takeScreenshot("image/png").then(blob => download(blob, "Screenshot.png"));
asdf3.14159
  • 694
  • 3
  • 19
  • 1
    This isn't a Linux solution, which is what I was looking for, but it works. I'll mark this the answer. Thank you! – gcdev Aug 10 '22 at 19:05
0

I don't have a solution but an idea how to do this

  1. You need chromebook in developer mode to have access to the actual Linux console, not the virtual machine linux that you install via "settings" app
  2. As chromebook is on Wayland, you need to use something like grim which works on Wayland and not scrot which is for X Windows
  3. You could use native wayland-enabled Linux chroot like https://github.com/nmilosev/crouton-fedora-wayland to install grim and other wayland native tools
grandrew
  • 698
  • 7
  • 12
  • Unfortunately I was looking for a solution that didn't involve developer mode. I'm hoping to distribute an app that uses this functionality, and I cannot realistically ask all users to take the dev mode step. – gcdev Nov 02 '21 at 14:29