Can Node.js invoke Chrome?

后端 未结 8 1401
长发绾君心
长发绾君心 2021-02-04 09:54

Is it possible for Node.js running on a desktop to spawn a Chrome Browser window? I would like to start a Chrome Browser providing the window size and location when Node.js rece

相关标签:
8条回答
  • 2021-02-04 10:31

    Checkout https://www.npmjs.com/package/chrome-launcher:

    Launch chrome:

    const chromeLauncher = require('chrome-launcher');
    
    chromeLauncher.launch({
      startingUrl: 'https://google.com'
    }).then(chrome => {
      console.log(`Chrome debugging port running on ${chrome.port}`);
    });
    

    Launching headless chrome:

    const chromeLauncher = require('chrome-launcher');
    
    chromeLauncher.launch({
      startingUrl: 'https://google.com',
      chromeFlags: ['--headless', '--disable-gpu']
    }).then(chrome => {
      console.log(`Chrome debugging port running on ${chrome.port}`);
    });
    

    chrome-launcher opens a remote debugging port so you can also control browser instance using the DevTools protocol.

    Puppeteer is another way to launch Chrome and interact with it using high level APIs.

    0 讨论(0)
  • 2021-02-04 10:32

    Yeah, I would think you would need to escape out to shell and then open up chrome.

    0 讨论(0)
提交回复
热议问题