Jake Buck
Incognito Button For Chrome
I wanted an easier way to bring up a new incognito window in Google Chrome, and after searching the Chrome Web Store, I was unable to find an extension that met my criteria. There are a lot of “move this tab/window to an incognito window” options, but none that I found offered a simple button to open an incognito window. The built-in hotkey (Ctrl-Shift-N) seems easy, but I’m not a fan of hotkeys involving more than two keys. There’s also a built-in menu option, but that requires two clicks, and I usually have to study the menu to find the “New Incognito Window” option (I don’t have it memorized).
Why would I want an easier way to open an incognito window? I use incognito mode to test how sites I’m working on look while I’m logged in as admin versus when I’m not. I also use incognito to check email and other accounts, which I can do in incognito mode without logging out of my normal accounts on the same sites. I recommend anyone using someone else’s computer to use incognito mode for checking their account(s), leaving the computer’s owner logged in on their accounts, minimizing their inconvenience.
I decided to write my own extension to introduce the behavior I wanted. Here’s the source if you want to use it to follow along as I describe the creation of the extension.
Every Chrome extension starts with the creation of a file named “manifest.json” (you can create a new text file and rename it). Manifest.json contains information about the extension, such as the name and version. Here’s the contents of this extension’s manifest.json:
Why would I want an easier way to open an incognito window? I use incognito mode to test how sites I’m working on look while I’m logged in as admin versus when I’m not. I also use incognito to check email and other accounts, which I can do in incognito mode without logging out of my normal accounts on the same sites. I recommend anyone using someone else’s computer to use incognito mode for checking their account(s), leaving the computer’s owner logged in on their accounts, minimizing their inconvenience.
I decided to write my own extension to introduce the behavior I wanted. Here’s the source if you want to use it to follow along as I describe the creation of the extension.
Every Chrome extension starts with the creation of a file named “manifest.json” (you can create a new text file and rename it). Manifest.json contains information about the extension, such as the name and version. Here’s the contents of this extension’s manifest.json:
{
name: Incognito Button,
version: 1.0,
description: Adds a button to the toolbar that opens a new icognito window.,
background_page: background.html,
// This loads a page behind the scenes, which in turn loads the javascript for the extension
browser_action: {
default_icon: icon.png
// Points to icon file that will be shown on the toolbar. 1919 size is recommended.
},
// browser_action, together with the default_icon identifier signifies a toolbar button
permissions: [tabs]
// The type(s) of permissions the extension has access to, tabs and windows permissions are both grouped under tabs for Chrome
}
“background_page”: “background.html” loads background.html out of sight of the user, allowing the extension to execute code. For this extension, background.html only loads background.js. Here’s what background.html contains:
<!doctype html>
<html>
<head>
<title>Background Page</title>
<script src=background.js></script>
</head>
<body>
</body>
</html>
Last is background.js, where the magic happens:
chrome.browserAction.onClicked.addListener(newWindow);
// Called when the user clicks on the button, calls the function newWindow
function newWindow(win) {
chrome.windows.create({incognito: true});
// Creates a new window with the incognito flag set to true
}
To pack your files into an extension, open Chrome’s menu (looks like a wrench on the toolbar) and select “Tools->Extensions”. At the top of the page, check the “Developer Mode” box, click “Pack extension…” and point the file browser that opens to the directory containing your extension. After packing your extension, drag the *.crx file onto a chrome window to install it. You can also use the “Load unpacked extension…” option to test out your extension while you’re writing it.