Skip to content

Commit

Permalink
set XDG_CONFIG_HOME and XDG_CACHE_HOME directly in the puppeteer node…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
sni committed Sep 4, 2024
1 parent d7eef24 commit 9c7e7a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 0 additions & 4 deletions script/grafana_export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ export PATH=$PATH:$DIR
INPUT="$INPUT&from=$START&to=$END"

NODE="node"
export XDG_CONFIG_HOME=/tmp/.thruk_chromium
export XDG_CACHE_HOME=/tmp/.thruk_chromium
if [ -n "$OMD_ROOT" ]; then
if [ -d "$OMD_ROOT/node_modules/" ]; then
export NODE_PATH=$OMD_ROOT/node_modules/
elif [ -d "$OMD_ROOT/lib/node_modules/" ]; then
export NODE_PATH=$OMD_ROOT/lib/node_modules/
fi
export XDG_CONFIG_HOME=~/tmp/.thruk_chromium
export XDG_CACHE_HOME=~/tmp/.thruk_chromium
fi
if [ -z "$NODE_PATH" ] && [ -d "/var/lib/thruk/puppeteer/node_modules" ]; then
export NODE_PATH="/var/lib/thruk/puppeteer/node_modules"
Expand Down
4 changes: 0 additions & 4 deletions script/html2pdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,12 @@ IS_REPORT=$4


NODE="node"
export XDG_CONFIG_HOME=/tmp/.thruk_chromium
export XDG_CACHE_HOME=/tmp/.thruk_chromium
if [ -n "$OMD_ROOT" ]; then
if [ -d "$OMD_ROOT/node_modules/" ]; then
export NODE_PATH=$OMD_ROOT/node_modules/
elif [ -d "$OMD_ROOT/lib/node_modules/" ]; then
export NODE_PATH=$OMD_ROOT/lib/node_modules/
fi
export XDG_CONFIG_HOME=~/tmp/.thruk_chromium
export XDG_CACHE_HOME=~/tmp/.thruk_chromium
fi
if [ -z "$NODE_PATH" ] && [ -d "/var/lib/thruk/puppeteer/node_modules" ]; then
export NODE_PATH="/var/lib/thruk/puppeteer/node_modules"
Expand Down
14 changes: 14 additions & 0 deletions script/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
*/

const puppeteer = require('puppeteer');
const os = require('os');
const path = require('path');


var url = process.argv[2];
var output = process.argv[3];
Expand All @@ -17,6 +20,17 @@ var sessionid = process.argv[6];
var is_report = process.argv[7];
var waitTimeout = 20000;

// Set XDG_CONFIG_HOME and XDG_CACHE_HOME if not already set (chrome >= ~ 128 does not start otherwise)
var tempDir = "";
if(process.env['OMD_ROOT']) {
tempDir = path.join(process.env['OMD_ROOT'], 'tmp', 'thruk' `puppeteer.cache.${userId}`);
} else {
const userId = process.getuid ? process.getuid() : '0000';
tempDir = path.join(os.tmpdir(), `puppeteer.cache.${userId}`);
}
if (!process.env['XDG_CONFIG_HOME']) { process.env['XDG_CONFIG_HOME'] = tempDir; }
if (!process.env['XDG_CACHE_HOME']) { process.env['XDG_CACHE_HOME'] = tempDir; }

(async () => {
const browser = await puppeteer.launch({
headless: "1", // keep old headless mode for now but disabled deprecation warning
Expand Down

0 comments on commit 9c7e7a6

Please sign in to comment.