Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I recently switched from Firefox to Chrome and I (probably) missed an important feature. I was used to test javascript snippets on FF from within the Firebug console this way: open the console, write the script and finally press CTRL + Return to execute the code.

It seems not possible to do the same in Chrome console, as when I type some code there and press return to start a new line the code is executed immediatly.

Is there a way to replicate the Firefox behavior on Chrome?

Thanks.

like image 236
Paolo Avatar asked Apr 02 '11 18:04

Paolo


People also ask

How do I run a JavaScript file in console?

To enter JavaScript statements and expressions interactively in the Console: Right-click in a webpage and then select Inspect. DevTools opens. Or, press Ctrl + Shift + J (Windows, Linux) or Command + Option + J (macOS), to directly open the DevTools console.

How do I edit and run JavaScript in Chrome?

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 run a script in Developer Console?

Focus your cursor anywhere inside of DevTools. Press Control + Shift + P (Windows/Linux) or Command + Shift + P (Mac) to open the Command Menu. Start typing Snippet , select Create new snippet, then press Enter to run the command.


1 Answers

It seems that there is no explicit “multiline mode”. But you can:

  • Paste code (it will preserve multiline)
  • Shift + Return to add a new line without executing the script

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

like image 148
bpierre Avatar answered Sep 23 '22 18:09

bpierre