Repository navigation
Connect inspector.Session to inspector in another process or thread. #28828
Description
Activity
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.
- added a commit that references this issue
on Sep 20, 2019 - added a commit that references this issue
on Sep 25, 2019 You should be able to connect to main Inspector service from a worker over the WS
@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
session.connectToMainThread()should besession.connectToThread(threadId: number). Alternatively,inspector.openOnThread(threadId: number, port, host, wait)would accomplish the same result for me.Presently my approach is to change all of my entry points to call
inspector.openand then send the result to a dedicated debugger thread. This is problematic as it requires me to be able to change all of the entry points of worker threads I wish to debug.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
connectToMainThreadis supposed to work: test-inspector-connect-main-thread.js. Specifically, focus onchildMainfunction. It verifies that only one session can be connected (ignore that in your code) and then sets a breakpoint and makes the main thread hit it.- added a commit that references this issue
on Jul 27, 2026
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.Sessiondoesn't support connecting to the inspector of a different thread or process.Describe the solution you'd like
urlparameter toinspector.Sessioninspectorto be transferedDescribe alternatives you've considered
The v8 inspector API is not complicated and I have written a client using the
wsnpm 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_threadsandinspectorare experimental.