Google's Undocumented "chrome.send" Command

While tinkering around with Chrome's Extensions and Javascript, I found some interesting code in some of Chrome's special pages' source.

It turns out that these special pages get an extra function to perform many of their normal activities. This function is: "chrome.send(command_name, [arg1, arg2, ...] )"

Searching through the Chrome source, it seems that Google added a function called "RegisterMessageCallback" to their DOM model, so that special pages could have a few extra commands to achieve the necessary extra functionality found in these special pages. (For example, I doubt that standard Javascript has an API for packaging Extensions, or to cancel downloads...)

A (I believe) full list of these extra functions appears here:

./chrome/browser/extensions/extensions_ui.cc:
dom_ui_->RegisterMessageCallback("requestExtensionsData",
dom_ui->RegisterMessageCallback("toggleDeveloperMode",
dom_ui->RegisterMessageCallback("inspect",
dom_ui->RegisterMessageCallback("reload",
dom_ui->RegisterMessageCallback("enable",
dom_ui->RegisterMessageCallback("uninstall",
dom_ui->RegisterMessageCallback("options",
dom_ui->RegisterMessageCallback("load",
dom_ui->RegisterMessageCallback("pack",
dom_ui->RegisterMessageCallback("autoupdate",
dom_ui->RegisterMessageCallback("selectFilePath",

./chrome/browser/dom_ui/html_dialog_ui.cc:
RegisterMessageCallback("DialogClose",

./chrome/browser/dom_ui/new_tab_ui.cc:
dom_ui_->RegisterMessageCallback("stopPromoLineMessage",
dom_ui->RegisterMessageCallback("getRecentlyClosedTabs",
dom_ui->RegisterMessageCallback("reopenTab",
dom_ui->RegisterMessageCallback("metrics",
dom_ui->RegisterMessageCallback("logEventTime",
dom_ui->RegisterMessageCallback("setHomePage",

./chrome/browser/dom_ui/shown_sections_handler.cc:
dom_ui_->RegisterMessageCallback("getShownSections",
dom_ui_->RegisterMessageCallback("setShownSections",

./chrome/browser/dom_ui/filebrowse_ui.cc:
dom_ui_->RegisterMessageCallback("getRoots",
dom_ui_->RegisterMessageCallback("getChildren",
dom_ui_->RegisterMessageCallback("getMetadata",
dom_ui_->RegisterMessageCallback("openNewPopupWindow",
dom_ui_->RegisterMessageCallback("openNewFullWindow",

./chrome/browser/dom_ui/new_tab_page_sync_handler.cc:
dom_ui_->RegisterMessageCallback("GetSyncMessage",
dom_ui_->RegisterMessageCallback("SyncLinkClicked",

./chrome/browser/dom_ui/tips_handler.cc:
dom_ui_->RegisterMessageCallback("getTips",

./chrome/browser/dom_ui/history_ui.cc:
dom_ui_->RegisterMessageCallback("getHistory",
dom_ui_->RegisterMessageCallback("searchHistory",
dom_ui_->RegisterMessageCallback("deleteDay",

./chrome/browser/dom_ui/downloads_dom_handler.cc:
dom_ui_->RegisterMessageCallback("getDownloads",
dom_ui_->RegisterMessageCallback("openFile",
dom_ui_->RegisterMessageCallback("drag",
dom_ui_->RegisterMessageCallback("saveDangerous",
dom_ui_->RegisterMessageCallback("discardDangerous",
dom_ui_->RegisterMessageCallback("show",
dom_ui_->RegisterMessageCallback("togglepause",
dom_ui_->RegisterMessageCallback("resume",
dom_ui_->RegisterMessageCallback("remove",
dom_ui_->RegisterMessageCallback("cancel",
dom_ui_->RegisterMessageCallback("clearAll",

./chrome/browser/dom_ui/most_visited_handler.cc:
dom_ui_->RegisterMessageCallback("getMostVisited",
dom_ui_->RegisterMessageCallback("blacklistURLFromMostVisited",
dom_ui_->RegisterMessageCallback("removeURLsFromMostVisitedBlacklist",
dom_ui_->RegisterMessageCallback("clearMostVisitedURLsBlacklist",
dom_ui_->RegisterMessageCallback("addPinnedURL",
dom_ui_->RegisterMessageCallback("removePinnedURL",

./chrome/browser/sync/sync_setup_flow.cc:
dom_ui_->RegisterMessageCallback("SubmitAuth",
dom_ui_->RegisterMessageCallback("SubmitMergeAndSync",

For example, looking at downloads_dom_handler.cc, we see that it registered "togglepause" as a function. Let's try it out!

Start a large download. (Something that will take a few minutes to download, so we have time to test this function out.) Now go to the Download Page. Press CTRL+SHIFT+J to launch the Javascript console.

Try running: chrome.send("togglepause", ["0"]); If all went properly (and the id of the download was indeed 0) then the download should be paused. All functions can be invoked in such a way, with the first string being the command name, and the second being a list of arguments to that command, which are all strings. Try looking at the page's source code for examples of how each command is supposed to be called.

Google's official Extension API says that they only support Content-Scripts on http, https, file, and ftp url schemes. However, Chrome's source says that they are considering adding the 'chrome' scheme:

src/chrome/common/extensions/url_pattern.h:
// <url-pattern> := <scheme>://<host><path>
// <scheme> := 'http' | 'https' | 'file' | 'ftp' | 'chrome'

src/chrome/common/extensions/url_pattern.cc:
// TODO(aa): Consider adding chrome-extension? What about more obscure ones
// like data: and javascript: ?
static const char* kValidSchemes[] = {
chrome::kHttpScheme,
chrome::kHttpsScheme,
chrome::kFileScheme,
chrome::kFtpScheme,
};

I sure hope they do. Then, you would be able to use these functions from Extensions by loading that page in a new tab, injecting your own code into the page using a Content Script, and then accessing that code with message-passing. As it is, calling chrome.send() functions is just a nifty trick that has no real use for us.

Unfortunately, I couldn't find the special command I needed. I was hoping to find a way to queue up a download using Javascript, but I didn't see any chrome.send() commands for that. If Google could add that, that would be awesome, since I was working on an extension that would scrape a page for all images/links, and queue every one of them for download. (Similar to DownThemAll! for Firefox.) But without a way to queue a download, my effort is doomed. :(

Google Chrome

Ok, so I was probably the last one to hear about Google Chrome FINALLY being released for Linux. (And for Macs, but the Linux version is the more important one... ;) )

Thus far, I'm liking it. It gets 100/100 on the ACID3, and as well it should. I mean, it uses the same WebKit core that Epiphany uses, and Epiphany gets 100/100. The interesting bit, though, is that the Javascript performance is slightly better:

============================================
RESULTS (means and 95% confidence intervals)
--------------------------------------------
Total: 776.6ms +/- 5.2%
--------------------------------------------
3d: 130.8ms +/- 7.6%
access: 66.0ms +/- 5.5%
bitops: 51.0ms +/- 26.1%
controlflow: 4.2ms +/- 13.2%
crypto: 30.6ms +/- 10.6%
date: 116.2ms +/- 5.8%
math: 78.8ms +/- 4.7%
regexp: 19.6ms +/- 3.5%
string: 279.4ms +/- 3.3%

The tests show a slight-to-moderate improvement over Epiphany's WebKit in every category, except 3d and math. 3d slowed down by 22ms, and math is slowed down by only 6ms.

Also, looking at Chrome's about:memory page shows:

Browser    Private   Proportional
Chrome 23,464k 29,094k
Firefox 100,780k 102,472k

Interesting statistics there, given that I had 3 tabs open in Chrome, and firefox had 0 tabs open. (I only had its Download list open, and I had no active downloads.) Dang it, Firefox. Why must you always need so much memory? D:

Also, I've had Wireshark open the whole time that Chrome has been open. I don't see any particularly egregious calls to google. I only saw safesearch url hashes, and auto-complete search results coming from google, and neither of those is all that bad. For a more complete list of Chrome-Google communications, check out this site: http://www.mattcutts.com/blog/google-chrome-communication/.

Anyway, that's all for today. Oh, and Faraaz, update ur blog! :)

Edit:I have 16 tabs open in Chrome, and it's been open all day. I started Firefox up 30 minutes ago, and it has 2 tabs open, one of which is about:blank. I wonder what the memory usage is now....

Browser   Private   Proportional
Chrome 56,072k 63,359k
Firefox 123,292k 130,943k

Dammit, Firefox.

Utility Mill

It's 3:17AM, and I'm getting tired, but I just wanted to point out this awesome site I just ran across:

http://utilitymill.com/

Loads of fun utilities in thar! All scripts in there are written in Python, and GPL'ed! My current fav: http://utilitymill.com/utility/Markov_Chain_Parody_Text_Generator.

The revision histories seem to date back to at least 2007, though... HOW DO I NEVER HEAR OF THESE THINGS EARLIER!? D:

Google's SPDY Protocol

Wow, how didn't I see this earlier?

http://dev.chromium.org/spdy/spdy-whitepaper

That is Google's new protocol that they are currently working on, which they hope will replace HTTP. It supposedly has 50% better performance over its predecessor, uses SSL by default, has native support for Server Push, defaults to using connection compression, among many other features.

You know, even if Google is trying to take over the world and enslave all of humanity(lol, conspiracies), I like how they are never satisfied with the status quo. They find something that is lacking, and they make a better version. Even if their newest product isn't the most used in the end, it always stirs things up enough to help cure stagnation. Remember how email was before gmail? Yahoo! had just reduced their storage space to 3MB, and then Google released gmail, complete with a full gig of storage space. All of a sudden all the email services are playing catch-up.

And the consumer wins. :)

Google Wave

Google Wave screenshot

Just got my invitation to Google Wave a short bit ago. From the looks of things, I've got 20 invitations. If you want one, email me. :)

-Ray

← Previous  1 … 7 8 9 10 11 … 13 Next →

About

User