{"id":8372,"date":"2020-07-08T19:47:47","date_gmt":"2020-07-08T19:47:47","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8372"},"modified":"2024-11-12T16:49:30","modified_gmt":"2024-11-12T16:49:30","slug":"visual-code-debugging-in-chrome","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/visual-code-debugging-in-chrome\/","title":{"rendered":"Visual Code debugging in Chrome"},"content":{"rendered":"<p>I&#8217;m using Visual Code for my React development and I&#8217;m using Chrome as my browser &#8211; I want to debug my React code in Chrome using Visual Code, so let&#8217; see how it&#8217;s done.<\/p>\n<p>First off, check out <a href=\"https:\/\/code.visualstudio.com\/blogs\/2016\/02\/23\/introducing-chrome-debugger-for-vs-code\" rel=\"noopener noreferrer\" target=\"_blank\">Introducing Chrome Debugging for VS Code<\/a>, secondly <a href=\"https:\/\/github.com\/Microsoft\/vscode-chrome-debug\" rel=\"noopener noreferrer\" target=\"_blank\">VS Code &#8211; Debugger for Chrome<\/a>.<\/p>\n<p>Or, if you prefer, here&#8217;s the steps<\/p>\n<ul>\n<li>Ctrl+Shift+X within Visual Code to load the Extensions list<\/li>\n<li>Search for Debugger for Chrome and install it (if not already installed)<\/li>\n<\/ul>\n<p>You&#8217;re going to need a launch.json file in the .vscode folder, here&#8217;s a minimal example<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n{\r\n    \/\/ Use IntelliSense to learn about possible attributes.\r\n    \/\/ Hover to view descriptions of existing attributes.\r\n    \/\/ For more information, visit: https:\/\/go.microsoft.com\/fwlink\/?linkid=830387\r\n    &quot;version&quot;: &quot;0.2.0&quot;,\r\n    &quot;configurations&quot;: &#x5B;\r\n        {\r\n            &quot;type&quot;: &quot;chrome&quot;,\r\n            &quot;request&quot;: &quot;launch&quot;,\r\n            &quot;name&quot;: &quot;Launch Chrome&quot;,\r\n            &quot;url&quot;: &quot;http:\/\/localhost:3000&quot;,\r\n            &quot;webRoot&quot;: &quot;${workspaceFolder}&quot;\r\n        },\r\n        {\r\n            &quot;type&quot;: &quot;chrome&quot;,\r\n            &quot;request&quot;: &quot;attach&quot;,\r\n            &quot;name&quot;: &quot;Attach to Chrome&quot;,\r\n            &quot;port&quot;: 9222,\r\n            &quot;webRoot&quot;: &quot;${workspaceFolder}&quot;\r\n        }\r\n   ]\r\n}\r\n<\/pre>\n<p>In the above we have two configurations, both for Chrome, one launches Chrome with the supplied URL, the second attaches to an existing instance of Chrome.<\/p>\n<p>If you now choose the option Run | Start Debugging, Chrome will launch with your URL loaded. You can place breakpoints in your code (before or after you start debugging) and you&#8217;re application will break at these breakpoints as you&#8217;d expect and you can inspect variables etc. So basically a full debugging experience.<\/p>\n<p>Default commands within debug mode are as follows<\/p>\n<ul>\n<li>F5 Continue<\/li>\n<li>F10 Step Over<\/li>\n<li>F11 Step Into<\/li>\n<li>Shift+F11 Step Out<\/li>\n<li>Ctrl+Shift+F5 Restart<\/li>\n<li>Shift+F5 Stop<\/li>\n<\/ul>\n<p>To attach to an existing running instance of Chrome, ensure you start Chrome with the following command line parameters <em>&#8211;remote-debugging-port=9222<\/em>, for example create a shortcut link with Target <em>&#8220;C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe&#8221; &#8211;remote-debugging-port=9222<\/em>.<\/p>\n<p>You&#8217;ll also need to ensure only this instance of Chrome is open\/running and then you can run the &#8220;Attach to Chrome&#8221; option.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using Visual Code for my React development and I&#8217;m using Chrome as my browser &#8211; I want to debug my React code in Chrome using Visual Code, so let&#8217; see how it&#8217;s done. First off, check out Introducing Chrome Debugging for VS Code, secondly VS Code &#8211; Debugger for Chrome. Or, if you prefer, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[246],"tags":[],"class_list":["post-8372","post","type-post","status-publish","format-standard","hentry","category-visual-code"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8372"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8372\/revisions"}],"predecessor-version":[{"id":11125,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8372\/revisions\/11125"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}