Skip to content

Instantly share code, notes, and snippets.

@vdeturckheim
Created January 21, 2021 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdeturckheim/ef0e698803c75837b89df5c813eeea27 to your computer and use it in GitHub Desktop.
Save vdeturckheim/ef0e698803c75837b89df5c813eeea27 to your computer and use it in GitHub Desktop.
'use strict';
const CDP = require('chrome-remote-interface');
const main = async function () {
const client = await CDP({
port: 9229
});
await client.Runtime.enable();
const ServerPrototypeResult = await client.Runtime.evaluate({expression:"require('http').Server.prototype", includeCommandLineAPI: true, returnByValue: false});
const ServerInstanceListResult = await client.Runtime.queryObjects({ prototypeObjectId: ServerPrototypeResult.result.objectId });
const ServerInstancesResult = await client.Runtime.getProperties({ objectId: ServerInstanceListResult.objects.objectId });
const serverInstance = ServerInstancesResult.result[0].value.objectId;
await client.Runtime.evaluate({expression:"process.patchListeners = require(`./toInject.js`).patchListeners", includeCommandLineAPI: true, returnByValue: false});
// in the injected function, the value for `this` will be the instance of the server
await client.Runtime.callFunctionOn({ objectId: serverInstance, functionDeclaration: 'function() { process.patchListeners(this) }', returnByValue: true });
await client.Runtime.evaluate({expression:"delete process.patchListeners", includeCommandLineAPI: true, returnByValue: false});
await client.Runtime.evaluate({"expression":"require('inspector').close()","includeCommandLineAPI":true});
await client.close();
};
main(); // on Node 15, an error will stop the process
@flzxsqc200
Copy link

hi,I try the demo on a centos system,but it can't print GET info .Is there any other configuration here.

@flzxsqc200
Copy link

can you tell me your node version?

@vdeturckheim
Copy link
Author

Did you make sure the other process has its debug port open on 9229? The node version should not have impact for anything fairly recent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment