You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何配置VS Code使用基于Chromium的Opera调试Angular 2项目

Debugging Angular 2 in Opera via VS Code (Using Debugger for Chrome Extension)

Absolutely! Since Opera is built on the Chromium engine, you can leverage the Debugger for Chrome extension you already have to debug your Angular 2 project in Opera with just a few simple configuration changes. Here's how to set it up:

Step 1: Enable Remote Debugging in Opera

First, you need to launch Opera with remote debugging enabled—this lets VS Code connect to the browser for debugging:

  • Windows: Run this command (adjust the path if your Opera installation is in a different location):
    "C:\Program Files\Opera\launcher.exe" --remote-debugging-port=9222
    
  • macOS: Use this terminal command:
    /Applications/Opera.app/Contents/MacOS/Opera --remote-debugging-port=9222
    
  • Linux: Run:
    opera --remote-debugging-port=9222
    

Pro tip: Create a desktop shortcut or alias with this command to avoid typing it every time you need to debug.

Step 2: Update Your launch.json Configuration

You have two flexible options here—either launch Opera directly from VS Code, or attach to an already running Opera instance with remote debugging enabled.

Option 1: Launch Opera from VS Code

Modify your existing launch.json to point to Opera's executable and enable remote debugging:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Opera against localhost",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}",
      "runtimeExecutable": "opera", // Use full path if Opera isn't in your system PATH (e.g., "C:\\Program Files\\Opera\\launcher.exe" for Windows)
      "runtimeArgs": ["--remote-debugging-port=9222"]
    }
  ]
}

Option 2: Attach to a Running Opera Instance

If you prefer to manually launch Opera with remote debugging first, use this attach configuration instead:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Opera",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}",
      "port": 9222
    }
  ]
}

Step 3: Start Debugging

  1. Make sure your Angular project is running with ng serve (it should be accessible at http://localhost:4200).
  2. In VS Code, select your new Opera debugging configuration from the run dropdown.
  3. Start the debugger—Opera will launch (or VS Code will attach to your running instance), and you can set breakpoints, inspect variables, and debug your Angular code just like you would in Chrome.

内容的提问来源于stack exchange,提问作者rostamiani

火山引擎 最新活动