From 8f4034a5cf9dcbbd8c45083304b05585b25b6f74 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Tue, 23 Mar 2021 23:29:05 +0100 Subject: [PATCH] Add debug.headless option to allow debugging of puppeteer --- source/app/metrics/index.mjs | 2 ++ source/app/metrics/utils.mjs | 19 ++++++++++++++++--- source/app/web/settings.example.json | 1 + source/plugins/music/index.mjs | 2 +- source/plugins/skyline/index.mjs | 2 +- source/plugins/topics/index.mjs | 2 +- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/source/app/metrics/index.mjs b/source/app/metrics/index.mjs index 19525b6c..7b5c4321 100644 --- a/source/app/metrics/index.mjs +++ b/source/app/metrics/index.mjs @@ -27,6 +27,8 @@ const data = {animated:true, base:{}, config:{}, errors:[], plugins:{}, computed:{}} const imports = {plugins:Plugins, templates:Templates, metadata:conf.metadata, ...utils} const experimental = new Set(decodeURIComponent(q["experimental.features"] ?? "").split(" ").map(x => x.trim().toLocaleLowerCase()).filter(x => x)) + if (conf.settings["debug.headless"]) + imports.puppeteer.headless = false //Partial parts { diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs index 2964d3d7..c2397e6d 100644 --- a/source/app/metrics/utils.mjs +++ b/source/app/metrics/utils.mjs @@ -6,7 +6,7 @@ import util from "util" import processes from "child_process" import axios from "axios" - import puppeteer from "puppeteer" + import _puppeteer from "puppeteer" import git from "simple-git" import twemojis from "twemoji-parser" import jimp from "jimp" @@ -15,13 +15,26 @@ import nodechartist from "node-chartist" //Exports - export {fs, os, paths, url, util, processes, axios, puppeteer, git, opengraph, rss} + export {fs, os, paths, url, util, processes, axios, git, opengraph, rss} /**Returns module __dirname */ export function __module(module) { return paths.join(paths.dirname(url.fileURLToPath(module))) } +/**Puppeteer instantier */ + export const puppeteer = { + async launch() { + return _puppeteer.launch({ + headless:this.headless, + executablePath:process.env.PUPPETEER_BROWSER_PATH, + args:this.headless ? ["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"] : [], + ignoreDefaultArgs:["--disable-extensions"] + }) + }, + headless:true + } + /**Plural formatter */ export function s(value, end = "") { return value !== 1 ? {y:"ies", "":"s"}[end] : end @@ -158,7 +171,7 @@ async resize(rendered, {paddings, convert}) { //Instantiate browser if needed if (!svg.resize.browser) { - svg.resize.browser = await puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"], ignoreDefaultArgs:["--disable-extensions"]}) + svg.resize.browser = await puppeteer.launch() console.debug(`metrics/svg/resize > started ${await svg.resize.browser.version()}`) } //Format padding diff --git a/source/app/web/settings.example.json b/source/app/web/settings.example.json index 6bb3a44c..5f792747 100644 --- a/source/app/web/settings.example.json +++ b/source/app/web/settings.example.json @@ -10,6 +10,7 @@ "port": 3000, "//": "Listening port", "optimize": true, "//": "SVG optimization", "debug": false, "//": "Debug logs", + "debug.headless": false, "//": "Debug puppeteer process", "mocked": false, "//": "Use mocked data instead of live APIs (use 'force' to use mocked token even if real token are defined)", "repositories": 100, "//": "Number of repositories to use", "padding": ["6%", "13%"], "//": "Image padding (default)", diff --git a/source/plugins/music/index.mjs b/source/plugins/music/index.mjs index 163aca41..e498262e 100644 --- a/source/plugins/music/index.mjs +++ b/source/plugins/music/index.mjs @@ -74,7 +74,7 @@ case "playlist":{ //Start puppeteer and navigate to playlist console.debug(`metrics/compute/${login}/plugins > music > starting browser`) - const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"], ignoreDefaultArgs:["--disable-extensions"]}) + const browser = await imports.puppeteer.launch() console.debug(`metrics/compute/${login}/plugins > music > started ${await browser.version()}`) const page = await browser.newPage() console.debug(`metrics/compute/${login}/plugins > music > loading page`) diff --git a/source/plugins/skyline/index.mjs b/source/plugins/skyline/index.mjs index 135a676b..7986f39f 100644 --- a/source/plugins/skyline/index.mjs +++ b/source/plugins/skyline/index.mjs @@ -17,7 +17,7 @@ //Start puppeteer and navigate to skyline.github.com console.debug(`metrics/compute/${login}/plugins > skyline > starting browser`) - const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"], ignoreDefaultArgs:["--disable-extensions"]}) + const browser = await imports.puppeteer.launch() console.debug(`metrics/compute/${login}/plugins > skyline > started ${await browser.version()}`) const page = await browser.newPage() await page.setViewport({width, height}) diff --git a/source/plugins/topics/index.mjs b/source/plugins/topics/index.mjs index be38c4e6..fa48cc91 100644 --- a/source/plugins/topics/index.mjs +++ b/source/plugins/topics/index.mjs @@ -14,7 +14,7 @@ console.debug(`metrics/compute/${login}/plugins > topics > searching starred topics`) let topics = [] console.debug(`metrics/compute/${login}/plugins > topics > starting browser`) - const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"], ignoreDefaultArgs:["--disable-extensions"]}) + const browser = await imports.puppeteer.launch() console.debug(`metrics/compute/${login}/plugins > topics > started ${await browser.version()}`) const page = await browser.newPage()