GitSyncMarks — Data Formats and Data Flow
Overview
GitSyncMarks stores each bookmark as an individual JSON file in a Git repository. The directory structure mirrors the bookmark folder hierarchy. Synchronization uses the configured Git provider API (GitHub/GitLab Git Data API, Gitea-family git data with Contents fallback, or GitLab /repository/commits). See PROVIDERS.md.
Profile transfer copies file maps between profiles (one-shot migration). Mirror destinations receive push-only copies after each primary commit; they are not merge participants.
Data Flow: Push
Data Flow: Pull
Data Flow: Context Menu
- Add to Toolbar / Other Bookmarks: Resolves the target folder via
getRootFolderIdForRole(), creates the bookmark withchrome.bookmarks.create(). The existingonCreatedlistener inbackground.jsfiresdebouncedSync()automatically. - Sync Now: Calls
sync()directly (same as popup sync button). - Copy Favicon URL: Resolves favicon via
getFaviconUrl(tab)— usestab.favIconUrlif available, falls back to Google's favicon service (https://www.google.com/s2/favicons?domain={domain}&sz=64). Then useschrome.scripting.executeScript()to runnavigator.clipboard.writeText()in the active tab context (clipboard API is not available in service workers). - Download Favicon: Same favicon resolution as Copy. Uses
chrome.downloads.download()withsaveAs: true; filename isfavicon_{hostname}.png. - Switch Profile: Reads all profiles via
getProfiles(), callsswitchProfile(targetId)inlib/profile-switch.js(diff-push current profile when unchanged skip commit, load target from cache when remote HEAD matcheslastCommitShaor delta-pull when it differs, apply bookmarks viareplaceLocalBookmarks()), then refreshes the context menu radio items. Profile switch uses only static imports so it runs from the MV3 service worker (popup/context menu), not only the options page.
MV3 constraint: background.js and lib/** must not use dynamic import() — Chrome/Edge service workers throw import() is disallowed on ServiceWorkerGlobalScope. Mirror push, profile switch, profile transfer, and Bitwarden password storage were affected before 3.0.8.
File Formats
Bookmark File (e.g. github_a1b2.json)
Each bookmark is a minimal JSON file:
{
"title": "GitHub",
"url": "https://github.com"
}
Filename format: {slug-from-title}_{4-char-hash-from-url}.json
The hash (FNV-1a of the URL, base-36) ensures uniqueness. The slug makes files human-readable.
_order.json — Folder Ordering
Each folder contains an _order.json that defines the order of its children:
[
"github_a1b2.json",
"stackoverflow_c3d4.json",
{"dir": "dev-tools", "title": "Dev Tools"}
]
Entries are either:
- String: A bookmark filename
- Object: A subfolder with
dir(directory name) andtitle(original display name)
Files not listed in _order.json (e.g., manually created) are picked up automatically and appended at the end.
Orphan subfolders: Subfolders that exist in the file map (with their own _order.json) but are not listed in the parent's _order.json are also included. All generators (README.md, bookmarks.html, feed.xml, dashy-conf.yml) and the tree builder scan for such orphans and append them. This handles manually created folders, corrupted _order.json, or migration from older formats.
External bookmark add
Bookmarks can be added to the repository from outside the extension and imported on the next sync:
- Add a bookmark JSON file (
{ "title": ..., "url": ... }) under a role folder, e.g.bookmarks/toolbar/. - The role folder must contain an
_order.jsonfile — the tree builder (buildFolderChildren) only walks folders that have one. An empty array is enough; files not listed in it are picked up as orphans. - Run Sync (or wait for auto-sync). The three-way merge imports the new file and normalizes its filename on the next push.
Two supported paths:
giton any host: commit the JSON yourself. Create_order.jsonif the repo was never initialized by the extension.- GitHub Action template (
.github/workflows/add-bookmark.yml): runsscripts/add-bookmark-to-repo.py, which creates the bookmark file and ensures_index.json, role_order.json, and any target subfolder entry — so it also works on a fresh, greenfield repo.
_index.json — Metadata
{
"version": 2
}
README.md — Human-Readable Overview
Auto-generated on every push. Shows all bookmarks as Markdown with folder headings. Includes subfolders recursively; orphan subfolders (present in file map but not in parent _order.json) are included. Not used for sync — purely informational.
# Bookmarks
> Last synced: 2026-02-09T15:30:00.000Z
## Bookmarks Bar
- [GitHub](https://github.com)
- [Stack Overflow](https://stackoverflow.com)
### Dev Tools
- [MDN Web Docs](https://developer.mozilla.org)
## Other Bookmarks
bookmarks.html — Netscape Format for Browser Import
Auto-generated on push when mode is Auto (default). Uses the Netscape Bookmark File format (<!DOCTYPE NETSCAPE-Bookmark-file-1>) which Chrome, Firefox, Edge, and Safari can import directly. Includes all subfolders recursively, including orphans. Not used for sync — purely for importing bookmarks without the extension.
feed.xml — RSS 2.0 Feed
Auto-generated on push when mode is Auto (default). Each bookmark becomes an <item> with title, link, and category (folder path). Includes bookmarks from all subfolders recursively, including orphans. Subscribable via any RSS reader (Feedly, Thunderbird, etc.); useful for automations (Slack, IFTTT, n8n) or embedding on websites. Works as a live feed via raw.githubusercontent.com or GitHub Pages.
dashy-conf.yml — Dashy Dashboard Config
Auto-generated on push when mode is Auto. Produces YAML sections with bookmark links for the Dashy dashboard. Each bookmark folder (including orphan subfolders) becomes a section with items. Not used for sync — purely for Dashy integration.
profiles/<alias>/settings.enc — Encrypted Settings
Optional. When "Sync settings to Git" is enabled, the extension writes an encrypted copy of all settings (profiles, tokens, sync preferences) to the repo. Uses the same gitsyncmarks-enc:v2 (PBKDF2-SHA256, 600,000 iterations; v1 with 100,000 iterations stays readable) format as the manual encrypted export (PBKDF2 + AES-256-GCM). The password is stored locally per device in chrome.storage.local and never synced.
Individual mode (current): Each device writes to profiles/<alias>/settings.enc where <alias> is the slugified client name (e.g. base-chrome). Other devices can list and import individual device configs via the UI.
Legacy: settings.enc or settings-{id}.enc at the base path are still supported and migrated to profiles/ on first sync.
Excluded from three-way merge (DIFF_IGNORE_SUFFIXES + SETTINGS_ENC_PATTERN).
backups/bitwarden/ — Bitwarden / Vaultwarden exports (optional)
Repo-root path (default backups/bitwarden, configurable as bitwardenBackupPath). User-uploaded password-protected encrypted JSON exports from Bitwarden or Vaultwarden. Optional second layer: GitSyncMarks gitsyncmarks-enc:v2 (PBKDF2-SHA256, 600,000 iterations; v1 with 100,000 iterations stays readable) (.gitsyncmarks.enc suffix). Listed, downloaded, or deleted from Files → Bitwarden Backup (Git commit on delete). Not used for bookmark sync; excluded from three-way merge (BITWARDEN_BACKUP_DEFAULT_PATTERN in lib/sync-diff.js). See IDEAS-BITWARDEN-BACKUP.md.
Complete Repository Structure
backups/ (optional — Bitwarden backup)
bitwarden/
vault-2026-06-06T14-30-00-000Z.enc.json
bookmarks/
_index.json
README.md
bookmarks.html
feed.xml
dashy-conf.yml
profiles/ (when settings sync enabled)
base-chrome/
settings.enc (per-device, client name = base-chrome)
toolbar/
_order.json
github_a1b2.json
stackoverflow_c3d4.json
dev-tools/
_order.json
mdn-web-docs_e5f6.json
other/
_order.json
...
Legacy: settings.enc or settings-*.enc at the base path are still supported and migrated to profiles/ on first sync.
Root folders are mapped by role:
| Role | Chrome | Firefox |
|---|---|---|
toolbar |
Bookmarks Bar (ID: 1) |
Bookmarks Toolbar (toolbar_____) |
other |
Other Bookmarks (ID: 2) |
Bookmarks Menu (menu________) |
On Firefox, the other role uses the Bookmarks Menu root (menu________); on Chrome it uses Other Bookmarks. Only toolbar and other are synced; menu and mobile are no longer used.
GitHub Repos Folder (Optional)
When enabled (githubReposEnabled), a folder "GitHubRepos (username)" is created under the configured root (toolbar or other). It contains bookmarks to all user repos (public and private). Updated manually via "Update GitHub Repos"; changes are synced through the normal bookmark sync. On pull, if the folder is not in Git, it is preserved locally.
Local Storage
chrome.storage.sync — User Settings
Per-profile keys (repo config, githubRepos) live in profiles[id]; others are global.
| Key | Type | Default | Description |
|---|---|---|---|
repoOwner |
string |
"" |
Repository owner |
repoName |
string |
"" |
Repository name |
branch |
string |
"main" |
Git branch |
filePath |
string |
"bookmarks" |
Base path in repo |
githubReposEnabled |
boolean |
false |
Show GitHub Repos folder |
githubReposParent |
string |
"other" |
Folder position: toolbar or other |
githubReposUsername |
string |
"" |
GitHub username (set on first refresh, for folder name) |
autoSync |
boolean |
true |
Auto-sync enabled |
syncInterval |
number |
15 |
Sync interval (minutes) |
language |
string |
"auto" |
UI language |
generateReadmeMd |
string |
"auto" |
Generate README.md: "off", "manual", or "auto" |
generateBookmarksHtml |
string |
"auto" |
Generate bookmarks.html: "off", "manual", or "auto" |
generateFeedXml |
string |
"auto" |
Generate feed.xml (RSS 2.0): "off", "manual", or "auto" |
generateDashyYml |
string |
"off" |
Generate dashy-conf.yml: "off", "manual", or "auto" |
syncSettingsToGit |
boolean |
false |
Sync encrypted settings to Git repo |
settingsSyncMode |
string |
"global" |
Settings sync mode: "global" (shared) or "individual" (per device) |
chrome.storage.local — Sync State + Token
Per-profile blobs (legacy top-level lastSyncFiles / githubToken are migrated into these maps):
| Key | Type | Description |
|---|---|---|
profileTokens |
object |
{ [profileId]: { primary, mirrors } } encrypted PATs (enc:v1:…) |
syncState |
object |
Per-profile { lastSyncFiles, lastCommitSha, lastSyncTime, hasConflict, conflictReason, conflicts, conflictChoices, pendingDelete, lastError, previousCommitSha, tokenExpiresAt, mirrors }. conflicts lists the open per-bookmark conflicts (path, local, remote); conflictChoices maps a conflict path to local or remote until the next sync applies it |
syncFlags |
object |
Per-profile { pendingLocalDeletes: string[] } — bookmark filenames deleted locally since last successful sync. Separate from syncState so event writes never RMW lastSyncFiles |
applyInProgress |
object|null |
{ profileId, commitSha, startedAt } set before the local bookmarks are reconciled; cleared after the new base is saved. Present → recover via pull() |
localBackups |
array |
Up to three snapshots { createdAt, reason, files } of the local bookmark files, taken before a pull, merge or remote apply. Used by "Restore local backup" |
localBackupsInfo |
array |
Metadata only (createdAt, reason, fileCount) of the same snapshots, so status reads stay small |
deviceId |
string |
UUID for this device |
settingsSyncPassword |
string |
Password for settings.enc encryption (device-local, never synced); stored encrypted (enc:v1:…) |
bitwardenBackupPassword:<id> |
string |
Optional Git wrap password for that profile's Bitwarden backup; stored encrypted (enc:v1:…) |
syncState[id].lastSyncFiles is the base state for three-way merge. It maps each file path to its blob SHA (for remote change detection) and content (for local change detection). conflictReason is bulkDelete (push-side) or remoteBulkDelete (pull-side).
GitHub Git Data API Interaction
All sync operations use the Git Data API for atomic multi-file commits:
Reading the Remote State
GET /repos/{owner}/{repo}/git/ref/heads/{branch} → commitSha
GET /repos/{owner}/{repo}/git/commits/{commitSha} → treeSha
GET /repos/{owner}/{repo}/git/trees/{treeSha}?recursive=1 → all files + SHAs
GET /repos/{owner}/{repo}/git/blobs/{blobSha} → file content (base64)
Writing (Atomic Multi-File Commit)
POST /repos/{owner}/{repo}/git/blobs → create file blob
POST /repos/{owner}/{repo}/git/trees → create new tree (incremental)
POST /repos/{owner}/{repo}/git/commits → create commit
PATCH /repos/{owner}/{repo}/git/refs/heads/{branch} → update branch
For empty repos (no branch yet), POST /git/refs creates the initial branch. If git-data writes keep returning empty-repo 409, commitBookmarkChanges / initializeRemoteFolder fall back to Contents PUT …/contents/{path} (creates the first commit).
Efficiency
A typical sync with few changes:
- 3 API calls to read (ref + commit + tree)
- N calls to fetch changed blob contents
- M calls to create new blobs
- 3 calls to write (tree + commit + ref update)
Total: ~6 + N + M calls, regardless of total bookmark count.
Token Encryption
The GitHub PAT is encrypted at rest using AES-256-GCM:
- Non-extractable
CryptoKeygenerated once and stored in IndexedDB - Encrypted as
"enc:v1:<base64-iv>:<base64-ciphertext>"inchrome.storage.local - Decrypted transparently on load; legacy plain-text tokens handled gracefully
- Token never stored in
chrome.storage.sync