11

I am using Firefox and am trying to run this code on the URL bar javascript:alert(document.cookie);.

But, when I hit go, nothing happens. In Chromium, it alerts, so what is with Firefox? Does Firefox try HTTP by default? If so, then how do I prevent this?

3 Answers 3

9

Firefox 89 and later

  1. Select Settings menu (3 horizontal lines icon in the upper right corner) More Tools -> Web Developer Tools -> Console tab.

  2. Type JavaScript code after the web console prompt » and press Enter.

The web console prompt will be located in the bottom left corner of the console pane if the console already has output in it.

Firefox 72 and later

Scratchpad is deprecated as of Firefox 70 (bug 1565380), and has been removed in Firefox 72 and later.

  1. Select Settings menu (3 horizontal lines icon in the upper right corner) -> Web Developer -> Web Console.

  2. Type JavaScript code after the web console prompt » and press Enter.

Firefox 57-71

  1. Select Settings menu (3 horizontal lines icon in the upper right corner) -> Web Developer -> Scratchpad.

  2. Click the Run button on the Scratchpad toolbar to run your JavaScript code.


Firefox 56 and earlier

  1. Open a new tab in Firefox and in the URL bar, and enter about:blank to display a blank tab so that you can see what you are doing.

  2. From the Firefox menu select Tools -> Web Developer -> Web Console.

  3. A new Web Console window will open. From the Web Console window click the JS button on the toolbar.

  4. From the Web Console window click on the Scratchpad icon in the toolbar. The Scratchpad icon looks like a notepad.

  5. A new Scratchpad window will open. Copy your javascript code: javascript:alert('Hello, World') in the Scratchpad window.

  6. Click the Run button on the Scratchpad toolbar to run your JavaScript code.

1
6

For firefox android version, you can try this bookmarklet:

javascript:var a=prompt();var f=Function(a);f();

It will open a prompt box. Type your command in it (without "javascript:") and it will run.

1
  • I'm on desktop Linux, but this worked for me: javascript:var a=function(){ alert(prompt()); }(). (Edit - added 'alert' around 'prompt' to show use of the output.)
    – John P
    Aug 14, 2017 at 18:57
1

javascript: does not appear to be working anymore since the last update (FF 71.0 Windows).
There is no output in the console either.

Note that Firefox 63 and above removes "javascript:" automatically when pasting into the address bar.

This can be changes in the settings page about:config by setting the key browser.urlbar.filter.javascriptto false.

However, while it does not filter the javascript: when pasting into the address bar any more, it does not execute it.

"Bookmarklets" remain working.

I have not found any information on this change or bug yet:


Mozilla calls the URL/address bar "unified search/address bar" / "the unified Awesome Bar" / "Firefox's URL bar":

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .