-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect inspector.Session to inspector in another process or thread. #28828
Comments
You should be able to connect to main Inspector service from a worker over the WS 😀 I tried implementing passing inspector session from main thread to a worker, but currently it is bit involved... I plan to revisit it at some point. This would resolve many issues with the current inspector session JS API - e.g. could be implemented with promises, could do IO, etc. It may even allow us to reimplement WS server in JS instead of current C++ code. |
This API is designed to enable worker threads use Inspector protocol on main thread (and other workers through NodeWorker domain). Note that worker can cause dead lock by suspending itself. I will work on a new API that will allow workers to be hidden from the inspector. Fixes: #28828 PR-URL: #28870 Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This API is designed to enable worker threads use Inspector protocol on main thread (and other workers through NodeWorker domain). Note that worker can cause dead lock by suspending itself. I will work on a new API that will allow workers to be hidden from the inspector. Fixes: #28828 PR-URL: #28870 Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@eugeneo Could you explain how since this is not documented in the inspector session API and there appears to be no way to configure it to connect to a different process? |
Please take a look at a inspector.Session.connectToMainThread available since 12.11. |
@eugeneo This only works for the very specific use case of using the main thread inspector from a worker thread. It doesn't allow connecting to other threads or a different process. Are there any plans for these to be supported? Having to use raw websockets is not very intuitive. |
You can connect to other worker threads by using the target domain. You can only debug other processes by using the WebSocket interface. |
@eugeneo , I am running into the same issue as @rochdev , but as this ticket is closed I'm assuming I am just misunderstanding the solution. I wish the use the inspector on other worker threads (not only the main thread). It seems like Presently my approach is to change all of my entry points to call As worker threads become more common it is more and more likely to encounter libraries which use worker threads, in which case I will not reasonably be able to change their entry points. |
5 years later nothing changed I guess. I am looking for a solution to use the inspector console of the main thread and I cant get it working. I tried multiple versions of this code inside a worker: import inspector from 'node:inspector';
const session = new inspector.Session();
session.connectToMainThread();
inspector.console.log('Test1');
process.stdout.write('Test2');
console.log('Test3'); I can't get a single line to log out in the debugger console of chrome. |
I do not have access to Node atm, but this (bit contrived) test case showcases how |
Is your feature request related to a problem? Please describe.
I want to use the inspector module in a worker thread to control the inspector in another thread.
inspector.Session
doesn't support connecting to the inspector of a different thread or process.Describe the solution you'd like
url
parameter toinspector.Session
inspector
to be transferedDescribe alternatives you've considered
The v8 inspector API is not complicated and I have written a client using the
ws
npm module instead of usinginspector.Session
.I'm open to writing a CR to implement this, but I would like feedback from a maintainer before I start, especially because both
worker_threads
andinspector
are experimental.The text was updated successfully, but these errors were encountered: