draw-image-export2 icon indicating copy to clipboard operation
draw-image-export2 copied to clipboard

npm install fails in node_modules/puppeteer

Open VVD opened this issue 2 years ago • 7 comments

node 18.2.0 npm 8.12.2 FreeBSD 13.1 amd64

[/tmp]$ git clone https://github.com/jgraph/draw-image-export2.git
…
[/tmp/draw-image-export2]$ cd draw-image-export2
[/tmp/draw-image-export2]$ npm install
npm notice 
npm notice New minor version of npm available! 8.12.2 -> 8.13.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.13.1
npm notice Run npm install -g [email protected] to update!
npm notice 
npm ERR! code 1
npm ERR! path /tmp/draw-image-export2/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! /tmp/draw-image-export2/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26
npm ERR!         throw new Error(message);
npm ERR!               ^
npm ERR! 
npm ERR! Error: Unsupported platform: freebsd
npm ERR!     at assert (/tmp/draw-image-export2/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26:15)
npm ERR!     at BrowserFetcher.setPlatform (/tmp/draw-image-export2/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:184:36)
npm ERR!     at new BrowserFetcher (/tmp/draw-image-export2/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserFetcher.js:168:14)
npm ERR!     at PuppeteerNode.createBrowserFetcher (/tmp/draw-image-export2/node_modules/puppeteer/lib/cjs/puppeteer/node/Puppeteer.js:188:16)
npm ERR!     at downloadBrowser (/tmp/draw-image-export2/node_modules/puppeteer/lib/cjs/puppeteer/node/install.js:51:46)
npm ERR!     at download (/tmp/draw-image-export2/node_modules/puppeteer/install.js:86:3)
npm ERR! 
npm ERR! Node.js v18.2.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-06-27T18_54_59_374Z-debug-0.log

Do you need log-file?

VVD avatar Jun 27 '22 19:06 VVD

Workaround: export PUPPETEER_SKIP_DOWNLOAD=yes before npm install.

VVD avatar Jun 27 '22 19:06 VVD

Other steps (hacks). Edit export.js:

 browser = await puppeteer.launch({
+                                                platform: 'linux',
+                                                executablePath: '/usr/local/bin/chrome',
                                                 headless: true,

In tomcat/webapps/draw/js/PreConfig.js (https://github.com/jgraph/drawio/blob/dev/src/main/webapp/js/PreConfig.js):

-window.EXPORT_URL = 'REPLACE_WITH_YOUR_IMAGE_SERVER';
+window.EXPORT_URL = 'http://IP:8000/node/export';

Tried export in PDF - files always have 11 bytes: "BAD REQUEST".

VVD avatar Jun 28 '22 07:06 VVD

Run log:

$ npm start

> [email protected] start
> node export.js

draw.io export server worker 1 listening on port 8000...
draw.io export server worker 2 listening on port 8000...
info: Success xml=1403 embed=1 format=pdf dt=4113
CLIENT_IP - - [28/Jun/2022:08:01:55 +0000] "POST /node/export HTTP/1.1" 200 58548 "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:99.0) Gecko/20100101 Firefox/99.0"
CLIENT_IP - - [28/Jun/2022:08:02:20 +0000] "GET /node/export HTTP/1.1" 400 - "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:99.0) Gecko/20100101 Firefox/99.0"

VVD avatar Jun 28 '22 08:06 VVD

Tried different urls and different files: http://IP:8000/node/export http://IP:8000/node http://IP:8000/export http://IP:8000/node

info: Success xml=2227 embed=1 format=pdf dt=3750
CLIENT_IP - - [28/Jun/2022:08:52:44 +0000] "POST /node/export HTTP/1.1" 200 30262 "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
CLIENT_IP - - [28/Jun/2022:08:53:03 +0000] "GET /node/export HTTP/1.1" 400 - "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
info: Success xml=6667 embed=1 format=pdf dt=5728
CLIENT_IP - - [28/Jun/2022:09:02:33 +0000] "POST /export HTTP/1.1" 200 220330 "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
CLIENT_IP - - [28/Jun/2022:09:02:45 +0000] "GET /export HTTP/1.1" 400 - "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
info: Success xml=1403 embed=1 format=pdf dt=3886
CLIENT_IP - - [28/Jun/2022:09:04:03 +0000] "POST /node HTTP/1.1" 200 58546 "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
CLIENT_IP - - [28/Jun/2022:09:04:19 +0000] "GET /node HTTP/1.1" 400 - "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
info: Success xml=6667 embed=1 format=pdf dt=4943
CLIENT_IP - - [28/Jun/2022:09:06:23 +0000] "POST / HTTP/1.1" 200 220332 "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"
CLIENT_IP - - [28/Jun/2022:09:06:32 +0000] "GET / HTTP/1.1" 400 - "-" "Mozilla/5.0 (X11; Linux x86_64; FreeBSD amd64; rv:199.0) Gecko/20100101 Firefox/199.0"

VVD avatar Jun 28 '22 09:06 VVD

It (export server) doesn't work via http if server with nextcloud and/or drawio are on https! Probably it's a browser fault.

VVD avatar Jun 28 '22 09:06 VVD

Is it possible to bind on specific IP:PORT without hardcode export.js? Is this the description:

Then add export=http://localhost:8000/ (hostname and port as needed) as an URL parameter to use that service for development and testing.

How to use it?

VVD avatar Jun 28 '22 13:06 VVD

Work for me PORT=my_port HOST=my_host_or_IP node export.js with my patches:

--- export.js.orig
+++ export.js
@@ -47,7 +47,9 @@
        const PNG_CHUNK_IDAT = 1229209940;
        const { JSDOM } = require("jsdom");
 
-       const PORT = process.env.PORT || 8000
+       const PORT = process.env.PORT || 8000;
+       const HOST = process.env.HOST || "127.0.0.1";
+       const EXECUTABLE = process.env.EXECUTABLE || "/usr/local/bin/chrome";

        const app = express();
 
@@ -374,6 +376,8 @@
                                                                Buffer.from(decodeURIComponent(html), 'base64')).toString());
 
                                        browser = await puppeteer.launch({
+                                               platform: 'linux',
+                                               executablePath: EXECUTABLE,
                                                headless: true,
                                                args: ['--disable-gpu', '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
                                        });
@@ -552,6 +556,8 @@
                                                var t0 = Date.now();
 
                                                browser = await puppeteer.launch({
+                                                       platform: 'linux',
+                                                       executablePath: EXECUTABLE,
                                                        headless: true,
                                                        args: ['--disable-gpu', '--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
                                                });
@@ -823,7 +829,7 @@
                }
        };
 
-       app.listen(PORT, function () 
+       app.listen(PORT, HOST, function () 
        {
                if (NO_CLUSTER)
                {
@@ -834,4 +840,4 @@
                        console.log(`draw.io export server worker ${cluster.worker.id} listening on port ${PORT}...`);
                }
        });
-}
\ No newline at end of file
+}

Also start script /usr/local/etc/rc.d/draw:

#!/bin/sh

# PROVIDE: draw
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

case $0 in
/etc/rc*)
        # during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
        # so get the name of the script from $_file
        name=$_file
        ;;
*)
        name=$0
        ;;
esac

name=${name##*/}
rcvar=${name}_enable

load_rc_config "${name}"

eval "${rcvar}=\${${rcvar}:-'NO'}"
eval "${name}_user=\${${name}_user:-'${name}'}"
eval "_log=\${${name}_log:-'/var/log/${name}.log'}"
eval "_js=\${${name}_js:-'export.js'}"
eval "HOST=\${${name}_host:-'127.0.0.1'}"
eval "PORT=\${${name}_port:-'8000'}"
eval "EXECUTABLE=\${${name}_executable:-'/usr/local/bin/chrome'}"
eval "pidfile=\${${name}_pid:-'/var/run/${name}/${name}.pid'}"

export HOST PORT EXECUTABLE

command="/usr/sbin/daemon"
command_args="-f -P '${pidfile}' -o '${_log}' /usr/local/bin/node '${_js}'"

run_rc_command "$1"

$ grep draw /etc/rc.conf

draw_enable="YES"
draw_user="draw"
draw_host="127.0.0.1"
draw_ports="8000"
draw_chdir="/opt/draw-image-export2"
draw_log="/opt/log/draw-image-export2.log"
draw_js="export.js"
draw_pid="/var/run/draw-image-export2/draw-image-export2.pid"
draw_executable="/usr/local/bin/ungoogled-chromium"

VVD avatar Aug 20 '22 16:08 VVD