> [!WARNING]
> **Warning:** chrome.syncFileSystem API will no longer be supported after January 1, 2025. [Migrate your app](https://developer.chrome.com/docs/apps/migration) and use other storage alternatives to prevent data loss.

<br />

<br />

## Description

Use the `chrome.syncFileSystem` API to save and synchronize data on Google Drive. This API is NOT for accessing arbitrary user docs stored in Google Drive. It provides app-specific syncable storage for offline and caching usage so that the same data can be available across different clients. Read [Manage Data](https://developer.chrome.com/docs/extensions/app_storage) for more on using this API.

<br />

<br />

## Permissions

`syncFileSystem`  

<br />

<br />

<br />

<br />

## Types

### ConflictResolutionPolicy

#### Enum

"last_write_win"   
"manual"   

<br />

### FileInfo

#### Properties

- action [SyncAction](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-SyncAction) optional

  Sync action taken to fire [`onFileStatusChanged`](https://developer.chrome.com/docs/apps/reference/syncFileSystem#event-onFileStatusChanged) event. The action value can be `'added'`, `'updated'` or `'deleted'`. Only applies if status is `'synced'`.
- direction [SyncDirection](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-SyncDirection) optional

  Sync direction for the [`onFileStatusChanged`](https://developer.chrome.com/docs/apps/reference/syncFileSystem#event-onFileStatusChanged) event. Sync direction value can be `'local_to_remote'` or `'remote_to_local'`. Only applies if status is `'synced'`.
- fileEntry Entry

  `fileEntry` for the target file whose status has changed. Contains name and path information of synchronized file. On file deletion, `fileEntry` information will still be available but file will no longer exist.
- status [FileStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus)

  Resulting file status after [`onFileStatusChanged`](https://developer.chrome.com/docs/apps/reference/syncFileSystem#event-onFileStatusChanged) event. The status value can be `'synced'`, `'pending'` or `'conflicting'`.

### FileStatus

#### Enum

"synced"   
Not conflicting and has no pending local changes.
"pending"   
Has one or more pending local changes that haven't been synchronized.
"conflicting"   
File conflicts with remote version and must be resolved manually.

<br />

### FileStatusInfo

#### Properties

- error string optional

  Optional error that is only returned if there was a problem retrieving the FileStatus for the given file.
- fileEntry Entry

  One of the Entry's originally given to getFileStatuses.
- status [FileStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus)

  The status value can be `'synced'`, `'pending'` or `'conflicting'`.

### ServiceInfo

#### Properties

- description string
- state [ServiceStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ServiceStatus)

### ServiceStatus

#### Enum

"initializing"   
The sync service is being initialized (e.g. restoring data from the database, checking connectivity and authenticating to the service etc).
"running"   
The sync service is up and running.
"authentication_required"   
The sync service is not synchronizing files because the remote service needs to be authenticated by the user to proceed.
"temporary_unavailable"   
The sync service is not synchronizing files because the remote service is (temporarily) unavailable due to some recoverable errors, e.g. network is offline, the remote service is down or not reachable etc. More details should be given by `description` parameter in OnServiceInfoUpdated (which could contain service-specific details).
"disabled"   
The sync service is disabled and the content will never sync. (E.g. this could happen when the user has no account on the remote service or the sync service has had an unrecoverable error.)

<br />

### StorageInfo

#### Properties

- quotaBytes number
- usageBytes number

### SyncAction

#### Enum

"added"   
"updated"   
"deleted"   

<br />

### SyncDirection

#### Enum

"local_to_remote"   
"remote_to_local"   

<br />

## Methods

### getConflictResolutionPolicy()

Promise

```typescript
chrome.syncFileSystem.getConflictResolutionPolicy(
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ConflictResolutionPolicy>
```

Gets the current conflict resolution policy.

#### Parameters

- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (policy: ConflictResolutionPolicy) => void
  ```

  <br />

  - policy [ConflictResolutionPolicy](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ConflictResolutionPolicy)

#### Returns

- Promise\<[ConflictResolutionPolicy](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ConflictResolutionPolicy)\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getFileStatus()

Promise

```typescript
chrome.syncFileSystem.getFileStatus(
  fileEntry: Entry,
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus>
```

Returns the [`FileStatus`](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus) for the given `fileEntry`. The status value can be `'synced'`, `'pending'` or `'conflicting'`. Note that `'conflicting'` state only happens when the service's conflict resolution policy is set to `'manual'`.

#### Parameters

- fileEntry Entry
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (status: FileStatus) => void
  ```

  <br />

  - status [FileStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus)

#### Returns

- Promise\<[FileStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus)\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getFileStatuses()

Promise

```typescript
chrome.syncFileSystem.getFileStatuses(
  fileEntries: object[],
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatusInfo[]>
```

Returns each [`FileStatus`](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatus) for the given `fileEntry` array. Typically called with the result from dirReader.readEntries().

#### Parameters

- fileEntries object\[\]
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (status: FileStatusInfo[]) => void
  ```

  <br />

  - status [FileStatusInfo](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatusInfo)\[\]

#### Returns

- Promise\<[FileStatusInfo](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileStatusInfo)\[\]\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getServiceStatus()

Promise

```typescript
chrome.syncFileSystem.getServiceStatus(
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ServiceStatus>
```

Returns the current sync backend status.

#### Parameters

- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (status: ServiceStatus) => void
  ```

  <br />

  - status [ServiceStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ServiceStatus)

#### Returns

- Promise\<[ServiceStatus](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ServiceStatus)\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getUsageAndQuota()

Promise

```typescript
chrome.syncFileSystem.getUsageAndQuota(
  fileSystem: DOMFileSystem,
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-StorageInfo>
```

Returns the current usage and quota in bytes for the `'syncable'` file storage for the app.

#### Parameters

- fileSystem DOMFileSystem
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (info: StorageInfo) => void
  ```

  <br />

  - info [StorageInfo](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-StorageInfo)

#### Returns

- Promise\<[StorageInfo](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-StorageInfo)\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### requestFileSystem()

Promise

```typescript
chrome.syncFileSystem.requestFileSystem(
  callback?: function,
): Promise<DOMFileSystem>
```

Returns a syncable filesystem backed by Google Drive. The returned `DOMFileSystem` instance can be operated on in the same way as the Temporary and Persistant file systems (see [http://dev.w3.org/2009/dap/file-system/file-dir-sys.html](https://dev.w3.org/2009/dap/file-system/file-dir-sys.html)).

Calling this multiple times from the same app will return the same handle to the same file system.

Note this call can fail. For example, if the user is not signed in to Chrome or if there is no network operation. To handle these errors it is important chrome.runtime.lastError is checked in the callback.

#### Parameters

- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (fileSystem: DOMFileSystem) => void
  ```

  <br />

  - fileSystem DOMFileSystem

#### Returns

- Promise\<DOMFileSystem\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### setConflictResolutionPolicy()

Promise

```typescript
chrome.syncFileSystem.setConflictResolutionPolicy(
  policy: ConflictResolutionPolicy,
  callback?: function,
): Promise<void>
```

Sets the default conflict resolution policy for the `'syncable'` file storage for the app. By default it is set to `'last_write_win'`. When conflict resolution policy is set to `'last_write_win'` conflicts for existing files are automatically resolved next time the file is updated. `callback` can be optionally given to know if the request has succeeded or not.

#### Parameters

- policy [ConflictResolutionPolicy](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ConflictResolutionPolicy)
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  () => void
  ```

  <br />

#### Returns

- Promise\<void\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

## Events

### onFileStatusChanged

```typescript
chrome.syncFileSystem.onFileStatusChanged.addListener(
  callback: function,
)
```

Fired when a file has been updated by the background sync service.

#### Parameters

- callback function


  The `callback` parameter looks like:

  ```typescript
  (detail: FileInfo) => void
  ```

  <br />

  - detail [FileInfo](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-FileInfo)

### onServiceStatusChanged

```typescript
chrome.syncFileSystem.onServiceStatusChanged.addListener(
  callback: function,
)
```

Fired when an error or other status change has happened in the sync backend (for example, when the sync is temporarily disabled due to network or authentication error).

#### Parameters

- callback function


  The `callback` parameter looks like:

  ```typescript
  (detail: ServiceInfo) => void
  ```

  <br />

  - detail [ServiceInfo](https://developer.chrome.com/docs/apps/reference/syncFileSystem#type-ServiceInfo)

<br />