How to execute JavaScript modules in the browser console

No need to copy and paste huge pieces of code

Marian C.
3 min readSep 21, 2024

Sometimes it is necessary to execute a script in a context of some web site, for example to collect the data displayed on the web page, to automatically perform many actions such as clicking buttons or to change some behavior of the web site. So it is possible to log in to the web site, open the console in the DevTools, paste and execute the script. The working script can be easily converted into a browser extension, merely by adding the manifest.json file, but for occasional executions, development and debugging the best execution environment is the console.

There are two inconveniences in executing scripts in the console:

  • modified code needs to be repeatedly copied from the editor and pasted into the console.
  • normally JavaScript code is built of multiple modules. JavaScript modules cannot be directly executed in the browser console.

It is possible to bundle the modules, bundling can be automatic, but iterative copying and pasting is annoying. And error-prone, you might press the nearby keys instead of Ctrl+C.

So how to conveniently build code of reusable modules and execute in the console without copy pasting?

--

--

Marian C.
Marian C.

Written by Marian C.

Java, JavaScript and SQL developer. Interested in data collection and visualization.

Responses (5)