How to take screenshot of Chromebook in Linux command-line?

745 views Asked by At

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!

2

There are 2 answers

1
asdf3.14159 On BEST ANSWER

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"));
1
grandrew On

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