mxsdev / nvim-dap-vscode-js

nvim-dap adapter for vscode-js-debug
266 stars 24 forks source link

Need Help.How to languch chrome in wsl #44

Open GinmusWJQ opened 1 year ago

GinmusWJQ commented 1 year ago

My environment is wsl2 and Ubuntu 20.04.4LTS My neovim configuration is extened by LazyVim.And I want to debug React or Vue in neovim.

The error message is:"unable to find an installation of the browser on your system.Try installing it,or providing an absolute path to the browser in the 'runtimeExecutable' in your launch.json"

I think I have the right debugger_path.So I doubt it is a problem with wsl.But I can run the react project perfectly in the wsl2 and open the chrome directly by click the terminal website address when i run npm run dev.And i saw vscode-js-debug/blob/main/OPTIONS.md#browserlaunchlocation says

In a remote workspace (through ssh or WSL, for example) this can be used to open the browser on the remote machine rather than locally.

I don't know where the problem is?

Here is my configuration

 {
    "mxsdev/nvim-dap-vscode-js",
    event = "VeryLazy",
    dependencies = {
      "mfussenegger/nvim-dap",
      {
        "microsoft/vscode-js-debug",
        lazy = true,
        build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out"
      }
    },
    config = function()
      local dap = require("dap")
      local dap_js = require("dap-vscode-js")
      -- vscode-js configuration for debugging support
      local DEBUG_PATH = vim.fn.stdpath("data") .. "/lazy/vscode-js-debug"
      dap_js.setup({
        node_path = "node",
        debugger_path = DEBUG_PATH,
        adapters = { "pwa-node", "node-terminal", "pwa-chrome" }, -- which adapters to register in nvim-dap
      })
      for _, language in ipairs({ "typescript", "javascript", }) do
        dap.configurations[language] = {
          {
            type = "pwa-node",
            request = "launch",
            name = "launch file (" .. language .. ")",
            program = "${file}",
            cwd = "${workspacefolder}",
          },
          {
            type = "pwa-node",
            request = "attach",
            name = "attach (" .. language .. ")",
            processid = require("dap.utils").pick_process,
            cwd = "${workspacefolder}",
          }
        }
      end
      for _, language in ipairs { "typescriptreact", "javascriptreact" } do
        require("dap").configurations[language] = {
          {
            type = "pwa-chrome",
            name = "Attach - Remote Debugging",
            request = "attach",
            program = "${file}",
            cwd = vim.fn.getcwd(),
            sourceMaps = true,
            protocol = "inspector",
            port = 9222,
            webRoot = "${workspaceFolder}",
          },
          {
            type = "pwa-chrome",
            name = "Launch Chrome",
            request = "launch",
            url = "http://localhost:3005",
            browserLaunchLocation = "workspace",
          },
        }
      end
    end
  },