Can I get node --inspect to open Chrome automatically

前端 未结 9 1940
孤城傲影
孤城傲影 2020-12-13 03:41

In the new versions of node, node-inspector is built in and can be fired using the command node --inspect index.js. However, this always provides a command line

相关标签:
9条回答
  • 2020-12-13 04:18

    Yes!! Use Node.js V8 --inspector Manager (NiM) Chrome plugin, it opens Chrome automagically when I run node --inspect-brk app

    On a side note - debugging with Visual Studio Code has become a breeze

    0 讨论(0)
  • 2020-12-13 04:19
    npm install express
    npm install esm
    npm install open
    npm install --save-dev node-key-sender
    

    package.json

    {
      "name": "open-browser",
      "version": "1.0.0",
      "description": "browser",
      "main": "server.js",
      "type": "module",
      "scripts": {
        "esm": "node -r esm server.js"
      },
      "author": "",
      "license": "ISC",
      "dependencies": {
        "express": "^4.17.1",
        "esm": "^3.2.25",
        "open": "^7.0.0",
      },
      "devDependencies": {
        "node-key-sender": "^1.0.11"
      }
    }
    

    server.js

    import express from 'express'
    import http from 'http'
    import open from 'open'
    import keysender from 'node-key-sender'
    
    const webApp = express()
    const webServer = http.createServer(webApp)
    
    webServer.listen(3000, function(){
      console.log('> Server listening on port:',3000)
      open('http://localhost:3000')
      keysender.sendCombination(['control', 'shift', 'i'])
    })
    

    the browser must already be open, then run

    node -r esm server.js
    
    0 讨论(0)
  • 2020-12-13 04:22

    This is not possible, for multiple reasons.

    1. Starting the Chrome (or other "desktop" application) is platform dependent. Core Node can't do it and it would add unnecessary complexity (e.g. think about discovering the install location, dealing with Chrome not installed, etc).
    2. This would tie Node to Chrome, which is not desirable.
    3. Chrome does not provide a way to pass devtools URL from the command line.
    0 讨论(0)
提交回复
热议问题