Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write JavaScript in Chrome developer tools

In Firebug, I can type my own JavaScript in the console tab and execute it. Is there a way to type JavaScript in Chrome Developer Tools and execute it?

like image 924
Andrew Koper Avatar asked Dec 09 '12 22:12

Andrew Koper


People also ask

Can I edit JavaScript in Chrome dev tools?

Editing JavaScript code in real-time is possible in Chrome and Chromium based browsers. 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.

How do I use JavaScript with Developer Tools?

Select More Tools. With that open, click on the Web Developer Tools item. You can also enter into the Web Console with the keyboard shortcut CTRL + SHIFT + K on Linux and Windows, or COMMAND + OPTION + K on macOS. Now that you have accessed the Console, you can begin working within it in JavaScript.

Can we type JavaScript commands in the Developer Tools?

You can enter any JavaScript expression, statement, or code snippet in the Console, and it runs immediately and interactively as you type. This is possible because the Console tool in DevTools is a REPL environment.

How do I run JavaScript in Chrome browser console?

1. Open the web page or site, on which, you want to run the JavaScript command. 3. Click on 'Console' or use the Ctrl+Shift+ J shortcut instead or you can bring the console to the front by right-clicking on the page and selecting 'Inspect element' , … so many ways to open the JavaScript Console in Chrome.


2 Answers

  1. Go to chrome://flags/, enable the "Enable Developer Tools experiments" flag and restart Chrome (or start it with the --enable-devtools-experiments command-line flag.)
  2. Open DevTools, go to the Settings dialog, switch to the Experiments tab.
  3. Enable the "Snippets support" experiment, close and reopen DevTools.
  4. Go to the Sources panel. In the left-hand navigator sidebar, switch to the Snippets tab .
  5. Right-click in the [empty] tree in this tab, select the New context menu item.
  6. Give the new snippet any name you like and type the snippet body.
  7. Once done, click the Run (>) button in the status bar to execute the snippet body. You can set breakpoints in snippets and debug them as ordinary scripts.
like image 90
Alexander Pavlov Avatar answered Oct 11 '22 13:10

Alexander Pavlov


Step 1: Open Google chrome Dev tool [ Press f12 ]

Step 2: Click on Sources tab

Step 3: On left side panel, Click on Snippets tab (may be hidden, if so click >> and it will appear)

Step 4: To create new snippet click + New snippet or right-click within the Navigator, and then select New

Step 5: Develop your code into middle pane and save it.

Step 6: To run Snippet, there are three ways

       A: Ctrl + Enter         B: Click on Run button [ Into Right-side panel, Top-Left button ]         C: Right-click on the snippet filename (in the pane on the left that lists           all your snippets) and select Run. 
like image 37
mistertandon Avatar answered Oct 11 '22 15:10

mistertandon