# Google Drive Browser Client Setup

UnifiedFiler v1.8.3 accesses Google Drive directly from browser JavaScript. The application Host only needs to provide Google Cloud parameters to `GoogleDriveAdapter`.

## Required Google Cloud settings

1. Enable Google Drive API in a Google Cloud project.
2. Create an OAuth 2.0 Client ID for a Web application.
3. Add the demo or Host origin, such as `http://localhost:8051`, to authorized JavaScript origins.
4. Create or reuse an API key for Google Picker / Drive API access.
5. Use `https://www.googleapis.com/auth/drive.file` as the default minimal scope, or use broader Drive scopes only when the Host application genuinely needs them.

## Adapter parameters

```javascript
var googleDrive = new UnifiedFiler.adapters.GoogleDriveAdapter({
    id: 'googleDrive',
    label: 'Google Drive',
    clientId: '<OAuth Client ID>',
    apiKey: '<API Key>',
    appId: '<Google App ID>',
    scopes: ['https://www.googleapis.com/auth/drive.file'],
    enablePicker: true,
    supportsAllDrives: true,
    includeItemsFromAllDrives: true,
    deleteMode: 'trash'
});
```

## Demo

Open `demo/google-drive.html` through a local HTTP server. Enter API Key, OAuth Client ID, App ID and scopes, save parameters, then click `Connect Google Drive`.

The demo intentionally stores those parameters only in browser localStorage for manual testing. Production Hosts should pass adapter parameters from their own configuration layer.

## Notes

- Browser popup blocking can prevent OAuth or Picker windows if actions are not started from a user click.
- `deleteMode` defaults to `trash` for safety.
- Google Workspace native files are exported to common formats before download.
- Fetch upload progress is lifecycle-level in this version; it reports start and completion because the browser Fetch API does not expose upload byte progress consistently.


## Frontend-only Google Drive access

UnifiedFiler accesses Google Drive from browser JavaScript only. The flow is:

1. Load Google Identity Services in the browser.
2. Obtain an OAuth access token in the browser.
3. Call Google Drive API v3 directly with `fetch`.
4. Upload files with multipart or resumable upload directly from the browser to Google Drive.

No backend proxy, server-side upload endpoint, client secret, or package-provided server code is required.

## COOP / window.closed warning

When Google Identity Services opens a popup, Chrome may show a warning like:

```text
Cross-Origin-Opener-Policy policy would block the window.closed call.
```

This is a browser/environment warning from the popup flow, not a Drive upload implementation requirement. If OAuth completes and Drive API requests work, it is not a UnifiedFiler JavaScript exception.

If a Host application explicitly sets COOP headers, avoid applying only `Cross-Origin-Opener-Policy: same-origin` on the page that starts the Google Identity Services popup. A Host can choose an opener policy compatible with popups, but UnifiedFiler does not include or require server-side code for Drive access.

## Token popup behavior

UnifiedFiler v1.9.7-fix3 keeps Google OAuth authorization single-flight. If FileExplorer starts tree and list requests at the same time, only one `requestAccessToken()` popup flow is allowed to run. Other requests wait for the same token response.

The explicit demo `Connect Google Drive` button still requests consent with `prompt: 'consent'`. Normal Drive API requests use the cached access token and do not force a consent popup every time.
