VSCode can seamlessly debug the browser. Let's take a look at the usage and principle analysis!

青灯夜游
Release: 2021-10-19 18:55:11
forward
2771 people have browsed it

VSCodeEpic update, you can seamlessly debug the browser. The following article will take you to understand this function, see how to use it, and briefly analyze the principle. I hope it will be helpful to you!

VSCode can seamlessly debug the browser. Let's take a look at the usage and principle analysis!

2021-07-16 Microsoft published a blog specifically introducing this feature, VSCODE is awesome!

Prior to this, if you want to debug chrome or edge in vscode, you need to use Chrome Debugger or the Microsoft Edge Debugger extension, two vscode extensions.

And more importantly, it can only provide the most basic console functions. Others such as network and element cannot be viewed. We still need to view it in the browser. [Recommended learning: "vscode tutorial"]

What is this function

After the update, we canopen directly in vscode linkin chrome or edge, andcomplete almost all common debugging functionssuch as viewing element, network, etc. directly within vscode.

Effect screenshot:

VSCode can seamlessly debug the browser. Lets take a look at the usage and principle analysis!(edge devtools)

VSCode can seamlessly debug the browser. Lets take a look at the usage and principle analysis!(debug console)

How to use

Use The method is very simple. You only need to press F5 in the front-end project to trigger debugging and perform simple configuration. Here is a lauch.json configuration for everyone. With it, you can directly open the debugging browser.

{ "version": "0.2.0", "configurations": [ { "type": "pwa-msedge", "request": "launch", "name": "Launch Microsoft Edge and open the Edge DevTools", "url": "http://localhost:8080", "webRoot": "${workspaceFolder}" } ] }
Copy after login

Everyone needs to modify parameters such as url and webRoot according to their own situation.

Principle

The principle is actually similar to the chrome debugger extension principle. It is also based on Chrome's devtool protocol to establish awebsocket link. Interact by sending formatted json data, so that vscode can dynamically get some runtime information. For example, requests sent by the browser network thread and DOM node information.

You can get a lot of information throughchrome devtool protocol, such as the network request mentioned above.

Since it is a two-way link established by websocket, it is easy to change the dom in VSCODE and trigger browser modifications. We only need to operate in VSCODE (websocket client) and then send a piece of JSON data to the browser (websocket server) through websocket. The browser will perform some operations based on the received JSON data. In terms of effect, it is no different from the user's direct manual operation in the browser.

It is worth noting that there are many clients for the chrome devtool protocol, not just the NodeJS client, but also Python, Java, PHP and other clients.

For more programming-related knowledge, please visit:

Introduction to Programming! !

The above is the detailed content of VSCode can seamlessly debug the browser. Let's take a look at the usage and principle analysis!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!