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!
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"]
After the update, we canopen directly in vscode link
in chrome or edge, andcomplete almost all common debugging functionssuch as viewing element, network, etc. directly within vscode.
Effect screenshot:
(edge devtools)
(debug console)
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}" } ] }
Everyone needs to modify parameters such as url and webRoot according to their own situation.
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!