Thursday, August 30th, 2007

Google Gears 0.2 Developer Release

Category: Gears, Google

The Gears team has rev’d a new version aimed at developers. This release isn’t going to propagate to end-user machines yet, as we want to time to hear from the community on the new features and APIs. Speaking of which…

What’s new?

Cross Origin API

Until now, there was no way to talk past the strict same-origin security model (same protocol, same exact domain, same port). Sometimes in the real world you need to mashup data, or even talk from to Now you can do this with a simple API that adds to WorkerPool:


  1. int  createWorker(fullScript)
  2. int  createWorkerFromUrl(scriptUrl) // NEW METHOD
  3. void allowCrossOrigin()             // NEW METHOD
  4. void sendMessage(messageString, destWorkerId)
  5. [write] callback onmessage(messageText, senderId, [object:{text,sender,origin}]) // NEW 3RD PARAM


Assume wants to read and write tasks managed by

  1. hosts workerpool-service.js, which it expects to be loaded by another origin. That .js code uses:
    • LocalServer to make itself and any required resources available offline.
    • WorkerPool to respond to sendMessage() commands like “getAllTasks”
  2. calls createWorkerFromUrl() with the workerpool-service.js URL.
  3. The worker can access resources, as it runs in that origin.
  4. When calls sendMessage(‘getAllTasks’), reads the database associated with and returns the tasks.
    • Note that because only directly accesses the database, the schema can change without requiring changes to

Read more of the details.

New HttpRequest API

Workers live in their own world (by design) but what if you need a worker to grab some content. You don’t have access to XHR, but now you can use the new HttpRequest module that mimics XHR with a couple of differences.

New Timer API

The Timer module implements the WhatWG Timer specification, and makes it available in both workers and the main HTML page. This is the same timer API that is traditionally available in browsers on the window object.

  1. <script type="text/javascript" src="gears_init.js"></script>
  2. <script type="text/javascript">
  3. var timer = google.gears.factory.create("beta.timer", "1.0");
  4. timer.setTimeout(function() { alert("Hello, from the future!"); }, 1000);
  5. </script>

I got to chat with Chris Prince, an engineer on Gears, about the new release:

Let us know your thoughts. What would you like to see? If you could create a mythical Gear, what would it do? :)

Posted by Dion Almaer at 8:40 am
1 Comment

4.6 rating from 89 votes

1 Comment »

Comments feed TrackBack URI

love the cross-origin implementation from the first glance looks of it… I’ve got to find some outside time for playing around with Gears, this ball is really rolling…

Comment by Mark Holton — August 30, 2007

Leave a comment

You must be logged in to post a comment.