This API was turned down in January 2019 and is deprecated. Migrate to Cloud Firestore or another data store.

Collaborators and sharing

The Realtime API uses Google Drive to manage permissions and sharing. The Realtime API supports owner, reader and writer roles. The commenter role has no effect.

Read-only mode

When a user only has a read permission the document is loaded in read-only mode and you cannot write to the model. Doing so will cause an error of type to be thrown. You will still receive updates as other users make changes.

You can verify a user's access by viewing the isReadOnly property on the model.

To be notified when the user's access has changed while the document is opened, listen for an event on the document.

function onAttributeChanged(event) {
  if (event.attribute == {
    // enable or disable editing

document.addEventListener(, onAttributeChanged);


When a user is actively viewing or editing a document they are called a collaborator.

The Collaborator object contains information about the user including their display name and photo. The provided color can be used to identify actions being performed by the user, such as indicating their cursor position.

The userId uniquely identifies the Google account that represents the collaborator. The sessionId will be unique for each collaborator object.

The collaborator representing the current session is identified by the isMe property.

You can retrieve the list of active collaborators by calling document.getCollaborators().

function displayAllCollaborators(document) {
  var collaborators = document.getCollaborators();
  var collaboratorCount = collaborators.length;
  console.log(collaboratorCount + ' collaborators:');
  for (var i = 0; i < collaboratorCount; i++) {
    var user = collaborators[collaboratorCount];
    console.log('Name: ' + user.displayName);
    console.log('Is me:' + user.isMe);

CollaboratorJoinedEvent and CollaboratorLeftEvent are emitted in response to users respectively loading and closing the current document. Listeners for these events are attached to the realtime document.

function displayCollaboratorEvent(evt) {
  var user = evt.collaborator;
  console.log('User ID:'    + user.userId);
  console.log('Session ID:' + user.sessionId);
  console.log('Name:'       + user.displayName);
  console.log('Color:'      + user.color);

document.addEventListener(, displayCollaboratorEvent);

Skicka feedback om ...

Behöver du hjälp? Besök vår supportsida.