I am looking for a way to capture a screenshot of a VS Code extension host window. This window is opened when my extension’s tests are being run (this is coming from the default Yeoman template for VS Code extensions).
I cannot use my extension’s context as the extension only has access to the VS Code API and VS Code runs extensions in a different Node process from the Electron one (main or renderer). IPC is used through the API instead of running extensions in-process.
I Node package, such as
process-list could be used to enumerate processes running on the system from the extension to find the window of the VS Code extension host (it’s okay to assume the only running VS Code instance is that extension host as running the tests requires no other instances of VS Code to run).
From there, however, I don’t know how to obtain the NodeJS process’ JS context of that Electron window or if that’s even possible in Node. Are there ways to pick an arbitrary system process (by PID for example), test it for being a Node process and prod into that process’ JS context to be able to invoke the JS APIs in it?
Update: I have figured I can try listing all running processes and then calling
process._debugProcess(proc.pid); for all of them, which is a Windows way of saying
kill -s SIGUSR1 . This works in the sense that all Node processes respond successfully to this call, i.e. do not throw an error.
However, compared to a fully successful invocation of this, lines are these are not printed out for almost all of the processes:
Debugger listening on ws://127.0.0.1:9229/cf49bcfe-d922-4f89-b438-57755d254198 For help see https://nodejs.org/en/docs/inspector
These lines show when connecting to only some Node processes. The lines would tell me which port and UUID to connect to using CDP so that I could run