29

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?

1
  • Thanks. I think I knew I could write a line there. Is there a way I can write multiple lines of JavaScript? Commented Dec 10, 2012 at 2:31

4 Answers 4

55
  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.
Sign up to request clarification or add additional context in comments.

8 Comments

Using Chromium Version 20.0.1132.47 Ubuntu 12.04 (144678), I found steps 2, 4, and 5 to be slightly different: 2) Open Developer Tools (Tools > Developer Tools - or Shift + Ctrl + I), click the settings icon (a small gear in the lower right), then scroll down to the Experiments section. 3 is the same. 4) Switch to the Scripts panel. Click the small tree-like icon if necessary. Now you'll see three tabs, Scripts, Content Scripts, and Snippets. Switch to the Snippets` tab. 5) Right click in the [empty] tree in this tab, select the Create snippet context menu item.
However, nothing seems to happen after I click Create snippet. Perhaps this is a bug with this version of Chromium.
How come you are still using Chromium 20? You should definitely update, as it has a lot of security vulnerabilities.
I am surprised that Google makes it that hard to type JS in Dev Tools, but this worked.
As of August 2015, this feature is supported in the stable version
|
22

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.

Comments

8

Recent Chrome Using Chrome 50, juste open the "Console" tab and start typing and executing your code at the bottom of the console.

Arrow up, recalls the code, ctrl-enter gives you a new line:

enter image description here

Comments

0

You can't debug Javascript, but you can execute it (including jquery) in a REPL in the chrome inspector.

  1. Open the inspector
  2. Click the button at the bottom left with 3 lines - its tooltip is "show console"
  3. Type your javascript and press enter

Note you usually have to go to the Sources tab and click the "pause script execution" button for your javascript to get evaluated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.