How to write and run scripts in the Google Chrome Javascript console?

I recently switched from Firefox to Chrome, and I (possibly) missed an important feature. I was used to test javascript fragments on FF from the Firebug console as follows: open the console, write a script, and finally press CTRL + Return to execute the code.

It seems impossible to do the same in the Chrome console, since when I type the code there and press return to start a new line, the code is executed immediately.

Is there a way to reproduce Firefox behavior in Chrome?

Thanks.

+7
source share
5 answers

Install Firebug Lite for Google Chrome . He has a console.
Do not look for a full Firebug. You will be disappointed :)

Unfortunately, at first I did not read correctly. To blame!

In Firebug Lite, select Console . Then you will see a tiny red up arrow in the right corner .
Click on it and you will get a multi-line console . Is not it?

+2
source

There seems to be no explicit "multi-line mode." But you can:

  • Paste code (it will save multi-line)
  • Shift + Return to add a new line without executing a script

Related errors:
https://bugs.webkit.org/show_bug.cgi?id=30553
http://code.google.com/p/chromium/issues/detail?id=72739

+4
source

I recommend this:

  • Write debugger; and press Enter on the console tab
  • This will lead you to the Sources tab; if not, make sure the debugger breakpoints are active.
  • Now you can write whatever you want on the Sources tab, which acts like a full IDE with features like new line and indent
  • Select any part of your code to run and right-click, select Evaluate in console
+3
source

You can also press Shift + Enter to launch a new line without running code in the Chrome console: https://developers.google.com/chrome-developer-tools/docs/tips-and-tricks#multiline-commands

+3
source

The best way to do this is with Chrome featue, i.e. Snippets where you can write javascript and save it in chrome. Its available under the source inside developer tools when checking an item. More information about the fragments can be found at this link.

It was available in Chrome canary, and I think it is now available in Chrome’s Chrome browser.

+2
source

All Articles