Use puppeteer for screenshots

Change-Id: Iac4f8c021ea57406b6ac085106217307d9f8357d
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4158920..3d9430f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -24,17 +24,19 @@
 
     - start_section install_linux_packages "Installing missing Linux packages"
     - apt-get update
-    - apt-get install -y libvulkan1 libu2f-udev fonts-liberation build-essential libglpk40 libcurl4-gnutls-dev libxml2-dev libsodium-dev libsecret-1-dev libfontconfig1-dev libssl-dev libxt6 libpq-dev imagemagick
-    - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
-    - dpkg -i google-chrome-stable_current_amd64.deb || apt-get install -y -f
+    - apt-get install -y libvulkan1 libu2f-udev fonts-liberation build-essential libglpk40 libcurl4-gnutls-dev libxml2-dev libsodium-dev libsecret-1-dev libfontconfig1-dev libssl-dev libxt6 libpq-dev imagemagick libnss3 libgbm-dev libxss1 libappindicator3-1 libasound2 libatk-bridge2.0-0 libgtk-3-0 libnspr4 libnss3 libgbm-dev ca-certificates curl gnupg
+    - curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
+    - NODE_MAJOR=20
+    - echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
+    - apt-get update && apt-get install nodejs -y
+    - node --version
+    - npm install puppeteer
     - locale-gen de_DE.utf8 en_GB.utf8 en_US.utf8
     - end_section install_linux_packages
 
-
-    - start_section install_fonts "Installing Libertinus and Fira fonts"
-    - wget -O- https://github.com/mozilla/Fira/archive/refs/tags/4.202.tar.gz | tar -C /usr/share/fonts -zx --wildcards "*.otf"
-    - fc-cache
-    - end_section install_fonts
+    - start_section test_puppeteer "Testing puppeteer"
+    - ./ci/screenshot https://www.google.com /tmp/google.png
+    - end_section test_puppeteer
 
     - start_section install_r_packages "Installing missing R packages"
     - R -e "install.packages(c('devtools', 'RKorAPClient', 'httr', 'tidytext', 'httpuv', 'scales', 'sp', 'raster', 'kableExtra', 'DT', 'svglite', 'qrcode', 'rsvg', 'highcharter'))"
@@ -45,8 +47,8 @@
   script:
     - start_section render "Running scripts"
     - R_CACHE_ROOTPATH=./cache R -e "require(rmarkdown); render('examples/ids.Rmd', output_format='revealjs::revealjs_presentation', output_dir='target')"
-    - ./ci/screenshot target/ids.html target/title.png
-    - ./ci/screenshot file://`pwd`/target/ids.html#/light-verb-constructions target/lvc.png
-    - ./ci/screenshot file://`pwd`/target/ids.html#/registered-users target/users.png
-    - ./ci/screenshot file://`pwd`/target/ids.html#/references target/references.png
+    - ./ci/screenshot file://`pwd`/target/ids.html target/title.png
+          file://`pwd`/target/ids.html#/light-verb-constructions target/lvc.png
+          file://`pwd`/target/ids.html#/registered-users target/users.png
+          file://`pwd`/target/ids.html#/references target/references.png
     - end_section render
diff --git a/ci/screenshot b/ci/screenshot
index 7b2acb5..9963559 100755
--- a/ci/screenshot
+++ b/ci/screenshot
@@ -1,3 +1,32 @@
-#!/bin/sh -eu
-in=$1 out=$2 page0=${3:-} page1=${4:-$page0}
-google-chrome --disable-web-security --user-data-dir="./" --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-startup-window --disable-gpu --run-all-compositor-stages-before-draw --no-pdf-header-footer --window-size=1024,576 --timeout=6000 --screenshot="$out" "$in"
+#!/usr/bin/env node
+
+const puppeteer = require('puppeteer');
+
+function delay(time) {
+  return new Promise(function (resolve) {
+    setTimeout(resolve, time)
+  });
+}
+
+(async () => {
+  const browser = await puppeteer.launch({
+    headless: "new",
+    args: ['--no-sandbox'],
+    defaultViewport: {
+      width: 1024,
+      height: 600,
+      isLandscape: true,
+      deviceScaleFactor: 1
+    }
+  });
+
+  const page = await browser.newPage();
+
+  for (var i = 2; i < process.argv.length; i += 2) {
+    await page.goto(process.argv[i], { waitUntil: 'networkidle2' });
+    await delay(1000);
+    await page.screenshot({ path: process.argv[i+1] });
+  }
+
+  await browser.close();
+})();