I run my nodejs 8.9.4 app (which is not a server) in a remote Kubernetes cluster with node --inspect=0.0.0.0:9229 app.js. I then port-forward 9229 on my machine. Finally, I access to chrome inspector and I can see my source code. I tried to run with --inspect-brk and I successfuly debugged my app. But I can't take heap snapshot: the button is disabled. I can't understand why.
Disabled take snapshot button
My advice is to :
Update chrome to latest version and relaunched it (also it is good to download Chrome Canary )
Restart node
Open chrome://inspect and added localhost: port number -9229 update connection in chrome.
Take a look: debugging-nodejs, memory-leaks-nodejs.
Related
I am writing a nodejs application and I am relying heavily on the node inspector (specific the Node Inspector Manager (NiM). I would like to work on my application and use the inspector in Chrome, even without a live wifi or internet connection. Its a given of course that the rest of my app can indeed be worked on without a live internet connection.
When I disconnect my internet on my mac, and try to load the inspector, I get chrome's "no internet" page from within the devtools:
However I can see that my application is running just fine when I view it in the terminal.
My script to run my app with the inspector on is node --inspect -r tsconfig-paths/register -r ts-node/register ./src/server.ts (some extras in there for typescript and babel). When I run it, I see Debugger listening on ws://127.0.0.1:9229/4478a0d7-e8a3-4315-8d2e-069a4e1e6389. I then navigate to https://chrome-devtools-frontend.appspot.com/serve_file/#a6b12dfad6663f13a7e16e9a42a6a4975374096b/inspector.html?experiments=true&v8only=true&ws=localhost:9229/4478a0d7-e8a3-4315-8d2e-069a4e1e6389 (not manually, I've set up NiM to open this open automatically).
Is this a known bug? Is there some setting I need to adjust? How can I utilize the node-inspector in Chrome with applications running locally, even if wifi is not present?
When I start an Express server with the --inspect option, I can navigate to chrome://inspect/#devices and launch a debug console for the appropriate Remote Target. But, when I start the process without the --inspect option, then try to initiate the inspector with kill -10 $PID, Chrome does not detect the Remote Target, even though the server indicates that the debugger was started. Is there anything I can do to connect to this process by Chrome or some other means?
This is the output from the server after running kill -10 $PID:
Attaching to nodejs
nodejs | Running version 3 on http://0.0.0.0:5000
nodejs | Debugger listening on ws://127.0.0.1:9229/c948d085-0491-4cd9-9832-a0f0cf120e11
nodejs | For help, see: https://nodejs.org/en/docs/inspector
Another note: I am running this app in a container with a Docker bridge network, but I don't see why that should make a difference because the --inspect option registers the same output when I start the server with it.
Versions:
Docker version 19.03.13, build 4484c46d9d
Node v12.22.1
express#4.17.1
Additional note: the procedure I'm describing (starting debug session after server start) is described here: nodejs.org/en/docs/guides/debugging-getting-started
But, when I start the process without the --inspect option, Chrome does not detect the Remote Target
If you started a process without --inspect it is expected that you won't be able to debug your code. Make sure that that logs you are talking about are the latest and some junk from past runs before you removed --inspect flag
Is there a way to launch chrome in non headless mode from a docker container?
I have a node application inside a docker container and a headless chrome container where i can connect to. All works fine so far. To demonstrate what puppeteer is doing i want to launch a chrome in non headless mode on the host system. Is this possible?
You can start Chromium manually on your host machine and then connect to its WebSocket port using puppeteer.connect() - https://pptr.dev/#?product=Puppeteer&version=v1.8.0&show=api-puppeteerconnectoptions . Don't forgot to open the WS port to container.
We also experimented with running Puppeteer in non-headless mode inside the Docker container using XVFB (X virtual framebuffer) and noVNC (https://github.com/novnc/noVNC) to display whats on the screen at HTML page served from the container. But that's not ideal for debugging.
If you just want to see which pages are opened and their screenshots you could use live-view https://github.com/apifytech/apify-js#puppeteer-live-view we build exactly for this use case.
tl;dr: Getting "Debugging connection was closed. Reason: websocket_closed.
" when trying to debug using Chrome Dev Tools with Node.
I want to do some code-stepping of a Node app. I thought I'd give Chrome Dev Tools a try.
I'm having a few issues that are preventing me from using CDT, and I'd appreciate any help.
1) When I do the following commands in Terminal
node --inspect myFile.js
or
nodemon --inspect myFile.js
the server seems to start fine, but when I pull up the CDT Node tools through
about://inspect
nothing appears in the CDT Node debugger, no sources, nada. If instead I access the tools by pasting in the URL that the above commands produce in the terminal into Chrome -- something like
chrome-devtools://devtools/remote/serve_file/#521e5b7/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
I get in the CDT Node debugger an announcement
Debugging connection was closed. Reason: websocket_closed.
What gives?
2) When I add the flag "--debug-brk" thusly
node --inspect --debug-brk
the server doesn't even start normally.
I'm using MacOS 10.12.4, Node v6.3.1. The server is running on port 9999, there is a client app that hits the server on that port, the client app runs on port 4200. I'm trying to debug the server code here.
(By the way, if you have another better tool than CDT to recommend for debugging Node I'd be keen to hear of it -- I have WebStorm but the process to debug Node seemed more complicated than that for CDT.)
Any help much appreciated --
Perhaps it was the weather? : following the same procedures as before, same code, I've gotten the CDT to work with the app I wanted to debug. The warning
Debugging connection was closed. Reason: websocket_closed.
was signaling that the app had stopped and thus there was no connection open.
I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code.
I'm using the following,
Node.js : v0.10.26
Express : 4.0.0
Node Inspector : v0.7.3
Google Chrome version : 34.0.1847.131
This is what I'm doing to start the debugger..
$ node-inspector
Node Inspector v0.7.3
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
In another console,
$ node --debug app.js
debugger listening on port 5858
$
Then started Google Chrome and went to
http://127.0.0.1:8080/debug?port=5858
It opens up node-inspector but without any code..all windows are empty.
Noticed that I'm not getting 'Express server listening on port 3000'
Tried all as per node-inspector fails to connect to node but no luck
Couldn't work out what I'm missing. Would be great of you have any suggestions..so I can debug my Node.js apps in Google Chrome.
Try to run node --debug-brk app.js instead of just --debug. Your application may not be pausing before node inspector hooks into the node process. Using --debug-brk will force node to break on the first line of your app and wait for a debugger to attach to the process. Loading the node-inspector web interface is what causes node-inspector to attach to your node process; that's why you include the node debug port in the query string (localhost:8080/debug?port=5858). You're telling node-inspector what port it should reach out and attach to.
Here's an animated gif I put together showing a complete install and run of node-inspector.
In the gif I use the --debug flag because I'm not debugging any code that runs right at startup. I'm debugging inside a request handler, which only fires when the page is requested. Thus, refreshing the page causes node-inspector to break on that line.
I also put together a 15 minute YouTube tutorial a while ago.
http://youtu.be/03qGA-GJXjI
node-inspector by default tries to pre-load all the code before initiating the debug window. I have had instances, node-inspector just hangs for ever because of this pre-loading. Luckily the newer versions have an option to stop the pre-load thereby making the inspector load faster.
Try node-inspector --no-preload
Standard remote debugging is broken entirely in node 6.5. It's replaced however by a new internal node feature
$ node --inspect --debug-brk build/server/server.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/#62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
Debugger attached.
See here - http://arveknudsen.com/?p=346%3Fpage_id%3D346&print=pdf - for more info
--debug-brk is now deprecated
try node --inspect-brk <your starting file name>
and then go to chrome and type url
chrome://inspect and click on Open dedicated DevTools for Node,
the debugger will start, no need of node-inspector
On the left of Node Inspector, "Sources" tab, there is "a box with a triangle in it" - highlighting says "Show Navigator". (See it in the picture above). Open that to find the files you want to debug, and put a break point on code that has yet to run.
Also note, if you want to debug code that runs on starting node, you'll need to use the --debug-brk option when starting. Then, in Node Inspector, you you'll have to kick off the app (F8 to run all). You'll need this option if you want to debug all the initialization code, like starting a web browser.
node-debug --no-preload app.js
This what's working for me. Accoriding to this:
My script runs too fast to attach the debugger.
The debugged process must be started with --debug-brk, this way the
script is paused on the first line.
Note: node-debug adds this option for you by default.