Introducing Scratchpad

The latest Firefox release includes a new tool for web developers: Scratchpad. The idea behind Scratchpad is simple: the browser is a fantastic place to experiment with JavaScript. Most JavaScript developers already know this and they use tools like the Web Console or Firebug’s command line to take advantage of the one environment that knows everything about their web page.

Tools like the Web Console are optimized for entering a single line of code. (ProTip: you can use shift-enter to put multiple lines of code into the Web Console.) Firebug has a button you can click to get into a multi-line input mode. Even with that multi-line input, the workflow is still centered around performing operations step-by-step and linearly.

Interaction with Scratchpad is quite different. It throws away the “one line of input gives you a line of output” interaction in favor of a text editor that knows how to run JavaScript.

Rob Campbell's Scratchpad+Canvas Demo

Using Scratchpad

To use Scratchpad, go to the “Web Developer” menu (hint for Mac users: look for the “Web Developer” menu under “Tools”). Select “Scratchpad” from that menu, and you’ll get a text editor window. The window starts out with a helpful hint about using Scratchpad.

The basic flow with Scratchpad could hardly be simpler:

  1. Enter some code
  2. Select a portion of the code
  3. Choose one of the three commands from the Execute or right-click context menu

The three ways to run code with Scratchpad are:

  • Run
  • Inspect
  • Display

They all have keyboard shortcuts, because you don’t want to have to reach for your mouse when you’re writing code.

Run just executes the selected code. This is what you’d use if you’re defining a function or running some code that manipulates your page.

Code in Scratchpad that creates an alert

JavaScript being run in the Scratchpad

Inspect executes the code as Run does, but it also opens up an object inspector on the value returned. For example, if you select window and choose Inspect, you will have an object inspector that lets you drill into the window object.

Finally, Display executes the selected code and puts the result right into your editor. This could be handy for using Scratchpad as a calculator. Or, more likely, it’s handy for keeping track of results while you’re testing something your page is supposed to do for you.

Interesting historical aside: Scratchpad was heavily inspired by the Workspaces feature of Smalltalk environments. Thirty years in, we’re still reinventing Smalltalk 😉

To really get a feel for Scratchpad, you need to see it in action. Fire it up yourself, or watch Rob Campbell’s video which steps through experimentation with Scratchpad.

Trying New Code with Scratchpad

Scratchpad is a great way to try out code in a live browser environment. For example, imagine you have a function called calculatePosition, and it’s just not working quite right. Load up your page, copy the function into Scratchpad and type out a couple lines of code that make use of calculatePosition. You very quickly get into a flow of tweaking the function and re-running the code.

Once you have the result you want, just copy the code back into your main file. This whole time, you didn’t have to reload the page even once.

Using Common Snippets

Scratchpad also has a way to save its contents or load a JavaScript file. Using this feature, you could save Scratchpads with collections of commonly used functions. For example, maybe you have a site that you work on that has various bits of data that get loaded via Ajax requests. Save a file with a handful of those calls and you can always get the data you want when you’re working on that app.

A Word about Scopes

When you run code in Scratchpad, it runs in a sandbox that has access to everything on your page, but keeps you from accidentally leaking variables onto your page. This is very similar to how the Web Console works. If you want to put a variable onto your page, just set it on window. will give your page a variable foo that is accessible to scripts on the page.

Scratchpad, unlike Web Console, follows you around as you switch tabs. When you execute code, it runs against the current tab in your browser. This makes it easy to try the same code against your development and staging servers, for example.

Finally, if you’re doing development work on Firefox itself or on Firefox add-ons, you can set Scratchpad up so that it has access to all of the browser’s internals. Go to about:config and set the preference to true. This will allow you to change the “Environment” from “Content” to “Browser”. Just don’t blame me if you enter some code that forces your browser to send cat pictures to Google+.

More to Come

Scratchpad is a simple tool, and we want it to stay that way. We’re planning a handful of improvements to Scratchpad that will show up in Firefox over the coming months, but the simple “text editor that runs JavaScript” core will remain.

We’d love your feedback on Scratchpad! Tell us on the dev-apps-firefox mailing list what you think. You can also get involved and make Scratchpad and other developer tools even better.

Kevin Dangoor, Developer Tools Product Manager

38 responses

  1. starwed wrote on :

    It seems to parse relative URLs in an unexpected context. I tried code like
    window.location = “page.php”
    And the location was set to a chrome URL.

    Is this a bug (in 8.0a) or an expected result?

    1. kdangoor wrote on :

      That looks like a bug. I’m sure it’s a side effect of the execution context, but it’s still certainly not the behavior that one would expect.

  2. Colin wrote on :

    Syntax highlighting. You need it.

    1. kdangoor wrote on :

      We just committed a new code editor to the tree. Syntax highlighting (and better editing in general) is coming in Firefox 8 (entering Aurora this week). However, it may be turned off initially while we work out some accessibility and internationalization issues.

  3. Pingback from New Tools in Mozilla Firefox Help Developers Drive the Web Forward « Blog id-Mozilla on :

    […] help developers build and debug websites directly in the browser. Developers will enjoy the new Scratchpad tool, which makes it simple to quickly enter, execute, test and refine JavaScript snippets in […]

  4. Pingback from New Tools in Mozilla Firefox Help Developers Drive the Web Forward | The Mozilla Blog on :

    […] help developers build and debug websites directly in the browser. Developers will enjoy the new Scratchpad tool, which makes it simple to quickly enter, execute, test and refine JavaScript snippets in […]

  5. Pingback from Mozilla Slovenija on :

    […] ki razvijalcu pomagajo pri gradnji in odkrivanju napak. Razvijalci bodo veseli tudi novega orodja Scratchpad s katerim lahko hitro vnesemo, izvršimo, testiramo ali dodelamo JavaScript, ki se nahaja na […]

  6. Pingback from Download Mozilla Firefox 6 Official | TechnoBolt on :

    […] to get a quick glance at open tabs from an elegant bird’s eye view. Developers will enjoy the new Scratchpad tool, which makes it simple to quickly enter, execute, test and refine JavaScript snippets in […]

  7. Levan wrote on :

    Nice tool.
    Yes, syntax highlighting and line numbers would be really cool )

  8. Michael wrote on :

    Hm… nice, but a way to hook in a text editor of my own choice may suit me better… OR, after syntax highlighting and line numbers… vim keys!

    1. kdangoor wrote on :

      I agree that hooking into your own text editor would be great. The challenge there is that Scratchpad has access to your running browser tabs. Extending that access to external applications requires some work for Firefox *and* work for each editor. It’s not insurmountable, though, and it would be very cool.

      In the meantime, we are working on improving the editing experience within Firefox and I think we’ll ultimately be able to provide great usability there.

      vim keybindings would be great.

  9. Web design consulting wrote on :


    this is a interesting tool for developer. and syntax highlighting and line number is really cool

  10. Oyeme wrote on :

    Very useful article.
    Thanks for the video.

  11. Serkan Yerşen wrote on :

    It would be great to have a toolbar button option for scratchpad. Maybe a “developer controls” button for all tools in one place. I would like to access them quickly.

    Thanks for the great addition.

    1. kdangoor wrote on :

      We have a plan for this (a “Developer Toolbar”) that will offer some nice quick access features for the tools we’re building.

  12. Chris Coleman wrote on :

    This is great.

    I use a ton for various reasons some similar to what I can achieve with ScratchPad.

    One feature that I would love to see added similarly is that I can save my code to an online repository and share it. Integration with jsFiddle or some other repository that I could share the code with others would be awesome.

    1. kdangoor wrote on :

      Thanks, I’m glad you like it!

      I definitely see integrating Scratchpad with external services like that being a useful feature. I had been thinking of gist myself previously, but jsfiddle is even more natural. Thanks for the suggestion

  13. Pingback from Mozilla Hacks Weekly, August 18th 2011 ✩ Mozilla Hacks – the Web developer blog on :

    […] tool for Web devs, a bit like the Web Console on steroids. Kevin Dangoor has a great post on this: Introducing ScratchPad. Web devs who want to know what is coming in this department with future Firefox versions should […]

  14. Don wrote on :

    Awesome work! Thank you.

    Pad window tabable?
    Have the debugger screen split with the code editor window instead of in another window?
    Code completion/intellisense?

    Great work thus far and will definitely use it!

    1. kdangoor wrote on :

      Yeah, all of that in time!


  15. Pingback from Episode 19 – So, we went to PyOhio and all I got was this t-shirt « on :

    […] ScratchPad in Firefox 6.0 […]

  16. Ben Barber wrote on :

    I’d love a CSS scratchpad also. Something similar to my CSS Terminal bookmarklet,

    1. kdangoor wrote on :

      We’ve got a Style Editor in development now that can very easily be used as a CSS Scratchpad.

  17. Pingback from Scratchpad – a tool for JS developers in Firefox : Max Ivak Personal Site on :

    […] Read more about features of Scratchpad here. […]

  18. Bob wrote on :

    super-awesome, thank you for this. my little suggestion (and maybe it exists and I don’t know it) is a keyboard shortcut to toggle focus between the browser window and scratchpad window.

  19. Lance wrote on :

    This is AWESOME !

    I’ve just returned to Firefox after a few months with Chrome and this kind of thing is why Firefox will likely become the *leading* web development platform – it is already number 1 at w3schools by the way (

    As for suggestions, I don’t need to make any. This is exactly what I have been looking for the past few months and I know that you are already planning to implement the features we are all looking for – because you are developers yourselves 🙂

    Keep the good work !

  20. Pingback from JavaScript Magazine Blog for JSMag » Blog Archive » News roundup: vintageJS, accounting.js, spin.js on :

    […] now has Scratchpad: a place to experiment with JavaScript in the […]

  21. Rob Crowther wrote on :

    > If you want to put a variable onto your page, just set it on window.

    Just a note after I spent ten minutes trying to figure it out how to get the scratchpad to write an object in the console:


    Probably it was just too obvious for anyone else to mention 🙂

  22. Franklin Davis wrote on :

    Insanely great tool!* Please post Rob’s demo code from the video. Thanks.

    * In honor of Steve Jobs…

  23. Pingback from Do you write right-to-left? Help us test the code editor! « devtools on :

    […] you haven’t tried Scratchpad before, you might want to check out the Introducing Scratchpad blog post to learn more about the […]

  24. Pingback from Firefox 7 available! | Stefano Paganini: mining for web, marketing, technology, fun on :

    […] the way, has anyone appreciated the Firefox 6 (yes, still fiddling with that) Scratchpad? The new Scratchpad tool makes it simple to quickly enter, execute, test and refine JavaScript […]

  25. Jon wrote on :

    If the web console tells me what line the error is on – I WANT LINE NUMBERS in the editor!

    1. kdangoor wrote on :

      It’s coming.

  26. gz wrote on :

    Great, but when i save a file with utf-8 characters in it (greek)
    it comes back with strange characters….
    How can i save a file from scratchpad with utf-8 or other
    encodings ?



    1. kdangoor wrote on :

      I’m not sure which encoding is used now. I filed a bug, because it does seem like we should at least be using utf-8

  27. David Guthrie wrote on :

    I love this, but would like to see some syntax highlighting, numbered lines, and like gedit and notepad++, some “themes” (like cobalt, my favorite )

    1. kdangoor wrote on :

      The current Firefox beta, coming out early November, has an about:config preference you can set devtools.editor.component to “orion” that gets you much of this. (Not themes yet). We’re still working on getting that editor whipped into shape to be on by default, likely in February’s release.

  28. Pingback from Orion Editor Ships in Firefox 8 | Orion News on :

    […] on successfully installing part of Orion! Firefox 8 now includes the Orion code editor in its scratchpad feature. The Orion editor is currently disabled by default, but it can be enabled as […]