Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Chrome to debug and edit javascript embedded in HTML page

Chrome developer tools allows you to edit javascript in the browser if the javascript is in a .js file. However, it does not seem to allow me to edit javascript that is embedded in an HTML page. ie:

<script type="text/javascript>  // code here that I want to debug/edit </script>  

This is a big problem for me as I have quite a bit of embedded javascript in a certain page.

Similar to this question: Edit JavaScript blocks of web page... live but this is about firefox, not chrome.

How can I edit javascript embedded in an HTML page using Google Chrome Developer Tools?

like image 556
Mark Robinson Avatar asked Sep 21 '11 09:09

Mark Robinson


People also ask

How do I debug HTML and JavaScript in Chrome?

Press the F12 function key in the Chrome browser to launch the JavaScript debugger and then click "Scripts". Choose the JavaScript file on top and place the breakpoint to the debugger for the JavaScript code.

How do I debug HTML in Chrome?

If you want to debug it, you should press F12 on Chrome to open the developer mode. You can see that the JS code of the current page is under the Source menu, you can set a breakpoint directly at the beginning of the script. Then you can click on the UI button or menu to start debugging(both js and backend activity ).

How do I edit JavaScript while debugging?

After loading a web page completely, press the F12 key to open the developer tools, then open the 'Sources' tab. Now open any Javascript file loaded on the browser and you can directly edit it by clicking anywhere in that file. After making modifications press Ctrl+S to save the changes.


1 Answers

Actually chrome allows to do that, choose HTML files in Sources tab in Developer tools window. You will see HTML instead of javascript and simply add breakpoints in the <script> tags. Also you can add debugger; command to script what you want to debug. For example:

<script>  // some code  debugger; // This is your breakpoint  // other code you will able to debugg </script> 

Don't forget to remove debugger;'s when you want to release your website.

like image 103
antyrat Avatar answered Sep 17 '22 18:09

antyrat