[webkit-dev] GlobalScript API.

Dmitry Titov dimich at chromium.org
Mon Aug 31 18:09:49 PDT 2009

Hi WebKit-dev,

I'm hoping to get your advice on Global Script proposal and how to start
implementing it as an 'experimental API' since it's not standardized yet.

As part of work on Workers in WebKit and Chromium, we discussed them with
our web application folks (mostly gmail). We came to the idea that in
addition to workers, they need a shared script context which runs on the
same UI thread and directly scriptable.

Our previous take (with an invisible window running all the time in the
background) was not that fruitful but it indicated the way to go. We are
thankful to the members of the whatwg community for the detailed threat
analysis of 'permanently running invisible pages', it helped very much. Not
right away but it was absorbed :-) Current proposal reflects realization
that there is a less-powerful way to achieve the same benefits.

I'm looking for a way to implement it as an experimental API in WebKit and
Chromium. I'm thinking it can go the similar way as webkitNotifications -
surrounded by ENABLE(GLOBAL_SCRIPT) and prefixed with 'webkit' to keep the

I'd appreciate much your advice on the whole API and on the way to bring it
into WebKit.

Here is a link to the whatwg thread, with the proposal and use cases:

Here is an actual API:
Page-level API

var globalScript = new webkitGlobalScript(name, url, loadHandler,

This returns a global scope object for the named Global Script.
If one does not exist yet, creates a new one. The globalScript is
sharing same process and same thread as the page running the constructor
and is operational right away. No synchronization is necessary.
name - string identifying the global script. Scoped to the orogin.
url  - the JS resource to load, if it was not yet loaded. If the Global
Script is already loaded but from a different url - the error is raised.
laodHandler - a function called asynchronously when the script is loaded (or
if it was already loaded by another page)
errorHandler - handler for loading errors, like violation of same-origin
policy or network error

The GlobalScript would create its own ScriptExecutionContext-derived context
if it was not yet created, and start to load the script into it. Once the
script is loaded, it is evaluated in the global scope of the Global Script
and loadHandlers are executed. Other pages that create a Global Script with
the same name in the same origin would get the same object back.

The globalScript object returned from the constructor can be immediately
used to set/retrieve properties and event handlers on it.

API exposed to Global Script (on its global scope object)
- Timers
- Navigator
- localStorage
- Database
- Workers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090831/925f7028/attachment.html>

More information about the webkit-dev mailing list