This API is available on Firefox OS for internal applications only.

The sync() method of the DataStore interface opens a cursor that allows you to step through any changes that have taken place in the data store going back to a particular revision ID, and run code in response to different types of change.

Note: The Data Store API is available in Web Workers, from Firefox 32 onwards (Firefox OS 2.0; see bug 949325.)


var cursor = stores[0].sync(3);


A DataStoreCursor object.


revisionId Optional
You can optionally pass sync() a revision ID that specifies the place in the revision history to go back to when running through the tasks. If you don't specify this, it runs through all tasks going back to the beginning of the history.


In the following example, we create a cursor using sync(), then invoke the runNextTask() function to run the next task in the cursor. In this function, the DataStoreCursor.next method is used to retrieve the next task (a DataStoreTask object), then the manageTask() function checks what type of task it is, and takes action accordingly. In this case, we are either done running through the tasks, in which case we return, or the task is an addition, in which case we run a function to display that addition in the app UI then move on to the next task by running runNextTask() again.

var cursor = stores[0].sync();

function runNextTask(cursor) {
 cursor.next().then(function(task) {
   manageTask(cursor, task);

function manageTask(cursor, task) {
  if (task.operation == 'done') {
    // Finished adding contacts!

  if (task.operation == 'add') {
    // Add the contacts that are different to how it was before
    displayExisting(task.id, task.data);


Note: This code is taken from our Data Store Contacts Editor demo. Look through the code to help you understand better what is going on, and how the full code works.


Specification Status Comment
Data Store API
The definition of 'sync()' in that specification.

The discussion concerning this API's creation happened in various Mozilla mailing lists and other places. A summary of the discussion and further pointers can be found on the Mozilla Wiki. For further feedback and questions, send mail to the dev-webapi mailing list.

Browser compatibility

Supported in Firefox OS 1.0.1.
Available in web workers in Firefox OS 2.0.

See also

Document Tags and Contributors

 Contributors to this page: fscholz, chrisdavidmills
 Last updated by: fscholz,