Miramac / vscode-exec-node

Execute your current file or your selected code with node.js
ISC License
12 stars 8 forks source link

F9 won't call process.exit in the code? #21

Open QinghuaGit opened 7 years ago

QinghuaGit commented 7 years ago

Hi,

I'm trying to run following code which copied from Getting Started with Headless Chrome

const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');

function launchChrome(headless = true) {
  return chromeLauncher.launch({
    port: 9222, 
    chromeFlags: [
      '--remote-debugging-port=9222',
      '--window-size=1300,1000',
      '--disable-gpu',
      headless ? '--headless' : ''
    ]
  });
}

(async function () {

  const chrome = await launchChrome();
  const protocol = await CDP({ port: chrome.port });

  const { Page, Runtime, Network, DOM } = protocol;
  await Promise.all([Page.enable(), Runtime.enable(), Network.enable(), DOM.enable()]);

  Page.navigate({ url: 'https://www.google.com/' });

  Page.loadEventFired(async (params) => {
    console.log(JSON.stringify(params));
  });

  process.on('exit', function () {
    console.log('exxxxxxiiiitttt....');
  })

})();

When I hit F9 after F8, the exit handler won't be called. But if I run the code in terminal then press Ctrl + C to quit, the handler would be called.

I'm new to NodeJS but my code seems good to me :) Please let me know if it is my fault. Thank you.

Miramac commented 7 years ago

hi @QinghuaGit, your code looks good. I guess it has something to do with the different processes (vscode, node, chrome). When you end a process in the terminal, all child processes are automatically terminated.

I'm afraid I do not know how I can change the behavior at the moment... :(