Call a JavaScript Function from Chrome Console
Last Updated :
23 Apr, 2024
Improve
Google Chrome does not allow JavaScript to run from URLs due to security issues. The following are the steps and instructions to follow to Call a JavaScript Function from Chrome Console.
Steps to call a JavaScript Function from Chrome Console
You can follow the below steps to call and write a JavaScript function in the Chrome console.
- Step 1: Open the Google Chrome website or any webpage to run JavaScript code.
- Step 2: From the Google Chrome menu, locate the three dots on the top right of the browser window.
- Step 3: Then go to > More Tools > Developer Tools to open the Chrome Console. Notice the red-coloured box options.
- Step 4: Once the JavaScript Console opens, clear the console by clicking Ctrl+L.
NOTE: You can also open the Chrome Console by right-clicking on your webpage, selecting Inspect from the context menu, and then clicking on the Console tab. Alternatively, you can use the keyboard shortcut Ctrl+Shift+I in Windows or Cmd+Opt+I on Mac to open the Developer Tools and then click on the Console tab.
- Step 5: Go to the Sources tab. Navigate to the Snippets option in the submenu below.
- Step 6: Now, Create a new snippet by clicking the +New snippet tab to work around JavaScript code or functions. Name the JavaScript snippet as file1.js or whatever you want.
- Step 7: Type the script you want to run inside the created JavaScript snippet.
- Step 8: Click Ctrl + Enter ( as shown in the red-colored box in the below image) to see the output of the above JavaScript Code snippet.