kartik468 / grafana-generate-pdf-nodejs

Generate pdf for grafana dashboards using nodejs and puppeteer
18 stars 6 forks source link

Evaluation failed: TypeError: Cannot read property 'getBoundingClientRect' of undefined #3

Closed douginoz closed 1 year ago

douginoz commented 3 years ago

ubuntu 20.04, same machine as grafana is running on fresh install of google chrome: $ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb $ sudo dpkg -i google-chrome-stable_current_amd64.deb $ latest version of npm, puppeteer installed: $ npm version { 'grafana-pdf': '1.0.0', npm: '8.1.1', node: '12.21.0', v8: '7.8.279.23-node.45', uv: '1.40.0', zlib: '1.2.11', brotli: '1.0.9', ares: '1.17.1', modules: '72', nghttp2: '1.43.0', napi: '7', llhttp: '2.1.3', http_parser: '2.9.4', openssl: '1.1.1j', cldr: '37.0', icu: '67.1', tz: '2021a1', unicode: '13.0' }

$ sudo git clone https://github.com/kartik468/grafana-generate-pdf-nodejs.git
Cloning into 'grafana-generate-pdf-nodejs'...
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 38 (delta 14), reused 21 (delta 6), pack-reused 0
Receiving objects: 100% (38/38), 424.00 KiB | 1.87 MiB/s, done.
Resolving deltas: 100% (14/14), done.

Did a 'sudo npm install' (the 'npm clean install' doesn't work - 'clean' isn't a valid option)

When trying to run this, it hangs with:

$ node grafana_pdf.js "http://sophie:3000/d/iTbnha5mkasdf/sophie-plex?orgId=1&refresh=30s&kiosk" admin:admin blah.pdf
Error: Evaluation failed: TypeError: Cannot read property 'getBoundingClientRect' of undefined
    at __puppeteer_evaluation_script__:2:69
    at ExecutionContext._evaluateInternal (/opt/grafana-generate-pdf-nodejs/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:217:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async ExecutionContext.evaluate (/opt/grafana-generate-pdf-nodejs/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:106:16)
    at async /opt/grafana-generate-pdf-nodejs/grafana_pdf.js:66:21
fgeueke commented 2 years ago

Pretty late to respond but maybe it helps somebody else. I was seeing the same thing - probably for a different reason. But the thing that ultimately saved me was capturing console output.

https://github.com/puppeteer/puppeteer See item 3 under "Debugging Tips".

root@3a25c52f0402:/grafana-generate-pdf-nodejs# git diff ./grafana_pdf.js
diff --git a/grafana_pdf.js b/grafana_pdf.js
index aed8f5d..98e6634 100644
--- a/grafana_pdf.js
+++ b/grafana_pdf.js
@@ -32,6 +32,7 @@ const auth_header = 'Basic ' + new Buffer.from(auth_string).toString('base64');
     });

     const page = await browser.newPage();
+    page.on('console', (msg) => console.log('PAGE LOG:', msg.text()));

     // Set basic auth headers
     await page.setExtraHTTPHeaders({ 'Authorization': auth_header });

In my case I was running into a CORS issue.

PAGE LOG: centrifuge config JSHandle@object
PAGE LOG: client will connect to websocket endpoint
PAGE LOG: start connecting
PAGE LOG: Status disconnected -> connecting
PAGE LOG: WebSocket connection to 'wss://server1.example.com:3000/api/live/ws' failed: HTTP Authentication failed; no valid credentials available
PAGE LOG: transport level error JSHandle@object
PAGE LOG: disconnected: connection closed true
PAGE LOG: Status connecting -> disconnected
PAGE LOG: reconnect after 1937 milliseconds
PAGE LOG: Access to XMLHttpRequest at 'https://server2.example.com/login/grafana/api/new_way.cgi' from origin 'https://server1.example.com:3000' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
PAGE LOG: Failed to load resource: net::ERR_FAILED
PAGE LOG: start connecting
PAGE LOG: Status disconnected -> connecting
PAGE LOG: WebSocket connection to 'wss://server1.example.com:3000/api/live/ws' failed: HTTP Authentication failed; no valid credentials available
PAGE LOG: transport level error JSHandle@object
PAGE LOG: disconnected: connection closed true
PAGE LOG: Status connecting -> disconnected
PAGE LOG: reconnect after 3248 milliseconds
kartik468 commented 2 years ago

@douginoz Are you still facing this issue? Note: After cloning you may refer/change/debug the code of "grafana_pdf.js" this file as per your need and check if it solves your issue.

douginoz commented 2 years ago

I'm afraid I can't even recall this error. I must have moved on from the problem afterwards, as I don't use Chrome now.