Visual Studio Code View In Browser Mac



View in Browser If you like viewing your HTML in a browser frequently for feedback as you code, this Visual Studio code extension will help you do it. It renders HTML files in your system’s default browser. Download Visual Studio Code for macOS. Open the browser's download list and locate the downloaded archive. Select the 'magnifying glass' icon to open the archive in Finder. Drag Visual Studio Code.app to the Applications folder, making it available in the macOS Launchpad. IOS Web Debugging on Windows and Mac. August 24, 2016 by Kenneth Auchenberg. The iOS Web debugger has been deprecated and we now recommend that you use the RemoteDebug iOS WebKit Adapter together with Visual Studio Code.

-->

For information about keyboard accessibility, see How to: Use Keyboard Navigation.

You can access a variety of commands in Visual Studio for Mac by using the appropriate keyboard shortcut. This document lists the default shortcuts for the Visual Studio for Mac key binding scheme. For more information about how to change the key binding scheme, see Customizing the IDE. You can also customize shortcuts for a command using the Visual Studio for Mac > Preferences menu item and choosing Environment > Key Bindings in the Preferences window.

Tip

The keyboard shortcuts displayed in this document, and the key binding preferences in Visual Studio for Mac, are presented using the symbols commonly used in macOS. If you are unsure of a symbol, review the macOS key symbols loopkup table.

Downloadable quick ref pdfs

We have compiled the most used, and most useful, keyboard shortcuts into a downloadable pdf file. We have two versions,one that shows shortcuts for Visual Studio for Mac, and a version that shows Visual Studio shorts side-by-side for usersthat have prior experience with Visual Studio when using Windows.

Code Navigation

CommandsKeyboard shortcuts
Find References⇧⌘R, F12
Go to Declaration⌘D, F12
Next Error⌥⇧⇟, ⇧⌘F12
Next Issue in File⌥⇟
Previous Error⌥⇧⇞
Previous Issue in File⌥⇞

Debug

CommandsKeyboard shortcuts
Enable or Disable Breakpoint⌥⌘/, ⌘F9
Pause⌥⌘P, ⌥⌘L5
Remove All Breakpoints⇧⌘F9
Run To Cursor⌘F10
Set Next Statement⇧⌘F10
Show Next Statement⌥*
Step Into⇧⌘I, ⌘F11
Step Out⇧⌘U, ⇧⌘F11
Step Over⇧⌘O, F10
Toggle Breakpoint, F9
View Breakpoints⌥⌘B

Designer

CommandsKeyboard shortcuts
Switch between related files⌃⌘↑

Edit

CommandsKeyboard shortcuts
Constraint Editing Mode⌘E
Copy⌘C
Cut⌘X
Delete⌘⌫
Format Document⌃I
Indent Selection⌘]
Paste⌘V
Preferences⌘,
Redo⇧⌘Z
Rename⌘R, F2
Select All⌘A
Show Code Generation⌘I
Toggle All Folds⌥⇧⌘↑
Toggle Definitions⌥⇧⌘↓
Toggle Fold⌥⇧⌘←
Toggle Line Comment(s)⌘/
Undo⌘Z
Unindent Selection⌘[
Update Frame from Constraints⇧⌘R

F# Integration

CommandsKeyboard shortcuts
Clear F# Interactive⌃⌥C
F# Interactive⌃⌥F
Restart F# Interactive⌃⌥R
Send line to F# Interactive⌃⌥L
Send references to F# Interactive⌃⌥P
Send selection to F# Interactive⌃⏎

File

CommandsKeyboard shortcuts
Close All⇧⌘W
Close File⌘W
Close Workspace⌥⌘W
New File⌘N
New Solution⇧⌘N
Open⌘O
Print⌘P
Quit⌘Q
Revert⌘U
Save⌘S
Save All⇧⌘S

Help

CommandsKeyboard shortcuts
API Documentation⌥⌘?
Unity API Reference⌘'

Other

CommandsKeyboard shortcuts
Implement Unity Messages⇧⌘M
Inspect⌥⌘I

Project

CommandsKeyboard shortcuts
Add Files⌥⌘A
Build⌘K, ⇧F6
Build All⌘B, F6
Clean⇧⌘K
Rebuild⌃⌘K
Rebuild All⌃⌘B
Start Debugging⌘⏎, F5
Start Without Debugging⌥⌘⏎, ⌃F5
Stop⇧⌘⏎, ⇧F5

Refactoring

CommandsKeyboard shortcuts
Import Symbol⌃⌥␣
Quick Fix⌥⏎

Search

CommandsKeyboard shortcuts
Command⇧⌘P
Find in Files⇧⌘F
Find Next⌘G, F3
Find Next Like Selection⌘E, ⌘F3
Find Previous⇧⌘G, ⇧F3
Find Previous Like Selection⇧⌘F3
Find⌘F
Go to File⇧⌘D
Go to Line⌘L
Go to Type⇧⌘T
Navigate To⌘.
Replace in Files⌥⇧⌘F
Replace⌥⌘F

How To Open Browser Or Run Program Directly From Visual ...

Text Editor

CommandsKeyboard shortcuts
Complete Word⌃␣
Delete left character⌃H
Delete next subword⌃⌦
Delete next word⌥⌦
Delete previous subword⌃⌫
Delete previous word⌥⌫
Delete right character⌃D
Delete to end of line⌃K
Dynamic abbrev⌃/
Expand selection⌥⇧↓
Expand selection⌥⇧↑
Expand selection to document end⇧⌘↓, ⇧⌘↘
Expand selection to document start⇧⌘↑, ⇧⌘↖
Expand selection to line end⇧↘, ⇧⌘→
Expand selection to line start⇧↖, ⇧⌘←
Expand selection to next line⇧↓
Expand selection to next word⌥⇧→
Expand selection to page down⇧⇟
Expand selection to page up⇧⇞
Expand selection to previous line⇧↑
Expand selection to previous word⌥⇧←
Expand selection to the left⇧←
Expand selection to the right⇧→
Find caret⌘|
Go left one character⌃B
Go right one character⌃F
Go to beginning of document⌘↑
Go to beginning of line⌘←, ⌃A
Go to end of document⌘↓
Go to end of line⌘→, ⌃E
Go to Matching Brace⇧⌘
Go to next line⌃N
Go to next word⌥→
Go to previous line⌃P
Go to previous word⌥←
Insert line break after the caret⌃O
Move caret to EOL and insert new line⇧⏎
Move the line or highlighted selection down⌥↓
Move the line or highlighted selection up⌥↑
Move to next usage⌃⌥⌘↓
Move to prev usage⌃⌥⌘↑
Show Parameter List⌃⇧␣
Show quick info⌘F1
Show Scopes⌥⇧⌘P
Transpose characters⌃T
Wrap with <div>⌥⇧W

View

CommandsKeyboard shortcuts
Center and Focus Document⌃L
Focus DocumentF7
Full Screen⌃⌘F
Move to Next Notebook⌥⌘→
Move to Previous Notebook⌥⌘←
Navigate Back⌃⌘←
Navigate Forward⌃⌘→
Normal Size⌘0
One Editor Column⌥⌘1
Show Next⌥⌘↓, F8
Show Previous⌥⌘↑, ⇧F8
Two Editor Columns⌥⌘2
Zoom In⌘+, ⌘=
Zoom Out⌘-, ⌘_

Window

Visual Studio Code View In Browser Mac
CommandsKeyboard shortcuts
Activate 1⌘1
Activate 2⌘2
Activate 3⌘3
Activate 4⌘4
Activate 5⌘5
Activate 6⌘6
Activate 7⌘7
Activate 8⌘8
Activate 9⌘9
Hide Others⌥⌘H
Hide Visual Studio⌘H
Minimize⌘M
Next Document⌘}, ⌘F6
Previous Document⌘{, ⇧⌘F6
Switch to next document⌃⇥
Switch to next tool window⌃⌥⇥
Switch to previous document⌃⇧⇥
Switch to previous tool window⌃⌥⇧⇥

macOS key symbols lookup

SymbolKey
Command (cmd)
Option (alt)
Shift
Control (ctrl)
Page Up (Pg Up)
Page Down (Pg Dn)
Delete (Backspace)
Forward Delete
Return
←→↑↓Arrow Keys
Home
End
Space Bar
Tab

See also

-->

Blazor WebAssembly apps can be debugged using the browser dev tools in Chromium-based browsers (Edge/Chrome). You can also debug your app using the following integrated development environments (IDEs):

  • Visual Studio
  • Visual Studio for Mac
  • Visual Studio Code

Available scenarios include:

  • Set and remove breakpoints.
  • Run the app with debugging support in IDEs.
  • Single-step through the code.
  • Resume code execution with a keyboard shortcut in IDEs.
  • In the Locals window, observe the values of local variables.
  • See the call stack, including call chains between JavaScript and .NET.

For now, you can't:

  • Break on unhandled exceptions.
  • Hit breakpoints during app startup before the debug proxy is running. This includes breakpoints in Program.Main (Program.cs) and breakpoints in the OnInitialized{Async} lifecycle methods of components that are loaded by the first page requested from the app.
  • Debug in non-local scenarios (for example, Windows Subsystem for Linux (WSL) or Visual Studio Codespaces).
  • Automatically rebuild the backend *Server* app of a hosted Blazor WebAssembly solution during debugging, for example by running the app with dotnet watch run.

Prerequisites

Debugging requires either of the following browsers:

  • Google Chrome (version 70 or later) (default)
  • Microsoft Edge (version 80 or later)

Ensure that firewalls or proxies don't block communication with the debug proxy (NodeJS process). For more information, see the Firewall configuration section.

Visual Studio Code users require the following extensions:

  • Blazor WASM Debugging Extension (when using the C# for Visual Studio Code Extension version 1.23.9 or later)

After opening a project in VS Code, you may receive a notification that additional setup is required to enable debugging. If requested, install the required extensions from the Visual Studio Marketplace. To inspect the installed extensions, open View > Extensions from the menu bar or select the Extensions icon in the Activity sidebar.

Visual Studio for Mac requires version 8.8 (build 1532) or later:

  1. Install the latest release of Visual Studio for Mac by selecting the Download Visual Studio for Mac button at Microsoft: Visual Studio for Mac.
  2. Select the Preview channel from within Visual Studio. For more information, see Install a preview version of Visual Studio for Mac.

Note

Apple Safari on macOS isn't currently supported.

Visual Studio Code View In Browser Mac

Enable debugging

To enable debugging for an existing Blazor WebAssembly app, update the launchSettings.json file in the startup project to include the following inspectUri property in each launch profile:

Once updated, the launchSettings.json file should look similar to the following example:

The inspectUri property:

  • Enables the IDE to detect that the app is a Blazor WebAssembly app.
  • Instructs the script debugging infrastructure to connect to the browser through Blazor's debugging proxy.

The placeholder values for the WebSockets protocol (wsProtocol), host (url.hostname), port (url.port), and inspector URI on the launched browser (browserInspectUri) are provided by the framework.

To debug a Blazor WebAssembly app in Visual Studio:

  1. Create a new hosted Blazor WebAssembly solution.

  2. Press F5 to run the app in the debugger.

    Note

    Start Without Debugging (Ctrl+F5) isn't supported. When the app is run in Debug configuration, debugging overhead always results in a small performance reduction.

  3. In the *Client* app, set a breakpoint on the currentCount++; line in Pages/Counter.razor.

  4. In the browser, navigate to Counter page and select the Click me button to hit the breakpoint.

  5. In Visual Studio, inspect the value of the currentCount field in the Locals window.

  6. Press F5 to continue execution.

While debugging a Blazor WebAssembly app, you can also debug server code:

  1. Set a breakpoint in the Pages/FetchData.razor page in OnInitializedAsync.
  2. Set a breakpoint in the WeatherForecastController in the Get action method.
  3. Browse to the Fetch Data page to hit the first breakpoint in the FetchData component just before it issues an HTTP request to the server.
  4. Press F5 to continue execution and then hit the breakpoint on the server in the WeatherForecastController.
  5. Press F5 again to let execution continue and see the weather forecast table rendered in the browser.

Note

Breakpoints are not hit during app startup before the debug proxy is running. This includes breakpoints in Program.Main (Program.cs) and breakpoints in the OnInitialized{Async} lifecycle methods of components that are loaded by the first page requested from the app.

If the app is hosted at a different app base path than /, update the following properties in Properties/launchSettings.json to reflect the app's base path:

  • applicationUrl:

  • inspectUri of each profile:

The placeholders in the preceding settings:

  • {INSECURE PORT}: The insecure port. A random value is provided by default, but a custom port is permitted.
  • {APP BASE PATH}: The app's base path.
  • {SECURE PORT}: The secure port. A random value is provided by default, but a custom port is permitted.
  • {PROFILE 1, 2, ... N}: Launch settings profiles. Usually, an app specifies more than one profile by default (for example, a profile for IIS Express and a project profile, which is used by Kestrel server).

In the following examples, the app is hosted at /OAT with an app base path configured in wwwroot/index.html as <base href='/OAT/'>:

For information on using a custom app base path for Blazor WebAssembly apps, see Host and deploy ASP.NET Core Blazor.

Debug standalone Blazor WebAssembly

For information on configuring VS Code assets in the .vscode folder, see the Linux operating system guidance in Tooling for ASP.NET Core Blazor.

  1. Open the standalone Blazor WebAssembly app in VS Code.

    You may receive a notification that additional setup is required to enable debugging:

    Additional setup is required to debug Blazor WebAssembly applications.

    If you receive the notification:

    • Confirm that the latest C# for Visual Studio Code Extension is installed. To inspect the installed extensions, open View > Extensions from the menu bar or select the Extensions icon in the Activity sidebar.
    • When using the C# for Visual Studio Code Extensionversion 1.23.9 or later, confirm that the latest Blazor WASM Debugging Extension is installed. To inspect the installed extensions, open View > Extensions from the menu bar or select the Extensions icon in the Activity sidebar.
    • Confirm that JavaScript preview debugging is enabled. Open the settings from the menu bar (File > Preferences > Settings). Search using the keywords debug preview. In the search results, set or confirm that the check box for Debug > JavaScript: Use Preview is checked. If the option to enable preview debugging isn't present, either upgrade to the latest version of VS Code or install the JavaScript Debugger Extension (VS Code versions 1.46 or earlier).
    • Reload the window.
  2. Start debugging using the F5 keyboard shortcut or the menu item.

    Note

    Start Without Debugging (Ctrl+F5) isn't supported. When the app is run in Debug configuration, debugging overhead always results in a small performance reduction.

  3. When prompted, select the Blazor WebAssembly Debug option to start debugging.

  4. The standalone app is launched, and a debugging browser is opened.

  5. In the *Client* app, set a breakpoint on the currentCount++; line in Pages/Counter.razor.

  6. In the browser, navigate to Counter page and select the Click me button to hit the breakpoint.

Note

Breakpoints are not hit during app startup before the debug proxy is running. This includes breakpoints in Program.Main (Program.cs) and breakpoints in the OnInitialized{Async} lifecycle methods of components that are loaded by the first page requested from the app.

Debug hosted Blazor WebAssembly

  1. Open the Client project folder of the hosted Blazor solution folder in VS Code.

  2. If there's no launch configuration set for the project, the following notification appears. Select Yes.

    Required assets to build and debug are missing from '{APPLICATION NAME}'. Add them?

    For information on configuring VS Code assets in the .vscode folder, see the Linux operating system guidance in Tooling for ASP.NET Core Blazor.

  3. In the command palette at the top of the window, select the Server project within the hosted solution.

Visual Studio Open Web Browser

A launch.json file is generated with the launch configuration for launching the debugger.

Attach to an existing debugging session

To attach to a running Blazor app, create a launch.json file with the following configuration:

Note

Attaching to a debugging session is only supported for standalone apps. To use full-stack debugging, you must launch the app from VS Code.

Visual studio set browser

Launch configuration options

The following launch configuration options are supported for the blazorwasm debug type (.vscode/launch.json).

OptionDescription
requestUse launch to launch and attach a debugging session to a Blazor WebAssembly app or attach to attach a debugging session to an already-running app.
urlThe URL to open in the browser when debugging. Defaults to https://localhost:5001.
browserThe browser to launch for the debugging session. Set to edge or chrome. Defaults to chrome.
traceUsed to generate logs from the JS debugger. Set to true to generate logs.
hostedMust be set to true if launching and debugging a hosted Blazor WebAssembly app.
webRootSpecifies the absolute path of the web server. Should be set if an app is served from a sub-route.
timeoutThe number of milliseconds to wait for the debugging session to attach. Defaults to 30,000 milliseconds (30 seconds).
programA reference to the executable to run the server of the hosted app. Must be set if hosted is true.
cwdThe working directory to launch the app under. Must be set if hosted is true.
envThe environment variables to provide to the launched process. Only applicable if hosted is set to true.

Example launch configurations

Launch and debug a standalone Blazor WebAssembly app

Attach to a running app at a specified URL

Launch and debug a hosted Blazor WebAssembly app with Microsoft Edge

Browser configuration defaults to Google Chrome. When using Microsoft Edge for debugging, set browser to edge. To use Google Chrome, either don't set the browser option or set the option's value to chrome.

In the preceding example, MyHostedApp.Server.dll is the Server app's assembly. The .vscode folder is located in the solution's folder next to the Client, Server, and Shared folders.

To debug a Blazor WebAssembly app in Visual Studio for Mac:

Visual Studio In Browser

View
  1. Create a new ASP.NET Core hosted Blazor WebAssembly app.

  2. Press + to run the app in the debugger.

    Note

    Start Without Debugging (++) isn't supported. When the app is run in Debug configuration, debugging overhead always results in a small performance reduction.

    Important

    Google Chrome or Microsoft Edge must be the selected browser for the debugging session.

  3. In the *Client* app, set a breakpoint on the currentCount++; line in Pages/Counter.razor.

  4. In the browser, navigate to Counter page and select the Click me button to hit the breakpoint:

  5. In Visual Studio, inspect the value of the currentCount field in the Locals window.

  6. Press + to continue execution.

While debugging a Blazor WebAssembly app, you can also debug server code:

  1. Set a breakpoint in the Pages/FetchData.razor page in OnInitializedAsync.
  2. Set a breakpoint in the WeatherForecastController in the Get action method.
  3. Browse to the Fetch Data page to hit the first breakpoint in the FetchData component just before it issues an HTTP request to the server.
  4. Press + to continue execution and then hit the breakpoint on the server in the WeatherForecastController.
  5. Press + again to let execution continue and see the weather forecast table rendered in the browser.
Default browser visual studio

Note

Breakpoints are not hit during app startup before the debug proxy is running. This includes breakpoints in Program.Main (Program.cs) and breakpoints in the OnInitialized{Async} lifecycle methods of components that are loaded by the first page requested from the app.

For more information, see Debugging with Visual Studio for Mac.

Debug in the browser

Cached

The guidance in this section applies to Google Chrome and Microsoft Edge running on Windows.

  1. Run a Debug build of the app in the Development environment.

  2. Launch a browser and navigate to the app's URL (for example, https://localhost:5001).

  3. In the browser, attempt to commence remote debugging by pressing Shift+Alt+d.

    The browser must be running with remote debugging enabled, which isn't the default. If remote debugging is disabled, an Unable to find debuggable browser tab error page is rendered with instructions for launching the browser with the debugging port open. Follow the instructions for your browser, which opens a new browser window. Close the previous browser window.

Visual Studio Set Browser

  1. Once the browser is running with remote debugging enabled, the debugging keyboard shortcut in the previous step opens a new debugger tab.

  2. After a moment, the Sources tab shows a list of the app's .NET assemblies within the file:// node.

  3. In component code (.razor files) and C# code files (.cs), breakpoints that you set are hit when code executes. After a breakpoint is hit, single-step (F10) through the code or resume (F8) code execution normally.

Blazor provides a debugging proxy that implements the Chrome DevTools Protocol and augments the protocol with .NET-specific information. When debugging keyboard shortcut is pressed, Blazor points the Chrome DevTools at the proxy. The proxy connects to the browser window you're seeking to debug (hence the need to enable remote debugging).

Browser source maps

Browser source maps allow the browser to map compiled files back to their original source files and are commonly used for client-side debugging. However, Blazor doesn't currently map C# directly to JavaScript/WASM. Instead, Blazor does IL interpretation within the browser, so source maps aren't relevant.

Firewall configuration

If a firewall blocks communication with the debug proxy, create a firewall exception rule that permits communication between the browser and the NodeJS process.

Warning

Modification of a firewall configuration must be made with care to avoid creating security vulnerablities. Carefully apply security guidance, follow best security practices, and respect warnings issued by the firewall's manufacturer.

Permitting open communication with the NodeJS process:

  • Opens up the Node server to any connection, depending on the firewall's capabilities and configuration.
  • Might be risky depending on your network.
  • Is only recommended on developer machines.

Debug ASP.NET Core Blazor WebAssembly | Microsoft Docs

If possible, only allow open communication with the NodeJS process on trusted or private networks.

For Windows Firewall configuration guidance, see Create an Inbound Program or Service Rule. For more information, see Windows Defender Firewall with Advanced Security and related articles in the Windows Firewall documentation set.

Troubleshoot

If you're running into errors, the following tips may help:

  • In the Debugger tab, open the developer tools in your browser. In the console, execute localStorage.clear() to remove any breakpoints.
  • Confirm that you've installed and trusted the ASP.NET Core HTTPS development certificate. For more information, see Enforce HTTPS in ASP.NET Core.
  • Visual Studio requires the Enable JavaScript debugging for ASP.NET (Chrome, Edge and IE) option in Tools > Options > Debugging > General. This is the default setting for Visual Studio. If debugging isn't working, confirm that the option is selected.
  • If your environment uses an HTTP proxy, make sure that localhost is included in the proxy bypass settings. This can be done by setting the NO_PROXY environment variable in either:
    • The launchSettings.json file for the project.
    • At the user or system environment variables level for it to apply to all apps. When using an environment variable, restart Visual Studio for the change to take effect.
  • Ensure that firewalls or proxies don't block communication with the debug proxy (NodeJS process). For more information, see the Firewall configuration section.

Breakpoints in OnInitialized{Async} not hit

The Blazor framework's debugging proxy takes a short time to launch, so breakpoints in the OnInitialized{Async} lifecycle methods might not be hit. We recommend adding a delay at the start of the method body to give the debug proxy some time to launch before the breakpoint is hit. You can include the delay based on an if compiler directive to ensure that the delay isn't present for a release build of the app.

OnInitialized:

OnInitializedAsync:

Visual Studio (Windows) timeout

If Visual Studio throws an exception that the debug adapter failed to launch mentioning that the timeout was reached, you can adjust the timeout with a Registry setting:

Visual Studio Code Browser Preview

The {TIMEOUT} placeholder in the preceding command is in milliseconds. For example, one minute is assigned as 60000.