If Microsoft Edge gets stuck on "Setting up sync" every time you restart the browser — and signing out/in only fixes it until the next restart — here is why it keeps happening and a 1-click surgical fix that does not wipe your User Data folder.
Why updates, "Reset sync", and sign-out/sign-in fail
- Signing out, clicking "Reset sync", or updating Edge does not clear corrupted local sync state:
- Corrupted LevelDB inside
Sync Data
- Stale/broken OAuth rows in the
token_service table inside the Web Data SQLite database
- Stuck
sync, account_info, and signin entries inside Preferences
- Wiping the whole
User Data folder works, but it replaces Local State (os_crypt encryption keys), which logs you out of all extensions, clears cookies, and resets site permissions.
1-Click Zero-Dependency Fix (Fix-EdgeSync.bat)
- 100% plain-text, zero downloads, no Python required — uses built-in Windows PowerShell and Windows' built-in
winsqlite3.dll.
- Automatic backups — renames/backs up
Sync Data, Web Data, and Preferences with .bak_ timestamps before editing anything.
- Preserves everything else — does not touch
Local State, Cookies, Login Data, Bookmarks, or Extensions.
Steps
- Open Notepad, paste the entire script below, save it as
Fix-EdgeSync.bat (make sure Save as type is set to All Files (.), not .txt), and double-click it.
- Reopen Edge, sign in to your Microsoft account once, and turn Sync ON.
- Open
edge://settings/system and turn OFF:
- Startup boost
- Continue running background extensions and apps when Microsoft Edge is closed
(Otherwise Windows shutdown can force-kill lingering background Edge processes while writing to the sync DB and corrupt it again.)
- Close and reopen Edge once to confirm Sync stays active automatically.
Script (Fix-EdgeSync.bat)
@echo off
setlocal
set "SCRIPT_PATH=%~f0"
powershell -NoProfile -ExecutionPolicy Bypass -Command "$c=[IO.File]::ReadAllText($env:SCRIPT_PATH,[Text.Encoding]::UTF8); & ([scriptblock]::Create(($c -split '(?m)^#PS_START#\r?$',2)[1]))"
echo.
pause
exit /b
#PS_START#
$ErrorActionPreference = 'Stop'
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host " Microsoft Edge Sync Surgical Repair (Windows)" -ForegroundColor Cyan
Write-Host "============================================================" -ForegroundColor Cyan
Write-Host "Will reset (with .bak backups created first):"
Write-Host " - Sync Data folder"
Write-Host " - token_service table inside Web Data"
Write-Host " - sync / account_info / signin keys inside Preferences"
Write-Host "Will NOT touch:"
Write-Host " - Local State, Cookies, Extensions, Login Data, Bookmarks"
Write-Host ""
$null = Read-Host "Press Enter to close Microsoft Edge and repair (or Ctrl+C to cancel)"
Write-Host "`nClosing Microsoft Edge..." -ForegroundColor Yellow
Get-Process -Name msedge -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
$waitLimit = (Get-Date).AddSeconds(6)
while ((Get-Process -Name msedge -ErrorAction SilentlyContinue) -and (Get-Date) -lt $waitLimit) {
Start-Sleep -Milliseconds 250
}
Start-Sleep -Milliseconds 500
if (Get-Process -Name msedge -ErrorAction SilentlyContinue) {
Write-Host "[ERROR] msedge.exe is still running. Close Edge completely in Task Manager and retry." -ForegroundColor Red
exit 1
}
$userData = Join-Path $env:LOCALAPPDATA "Microsoft\Edge\User Data"
if (-not (Test-Path $userData)) {
Write-Host "[ERROR] Edge User Data folder not found: $userData" -ForegroundColor Red
exit 1
}
Add-Type -TypeDefinition @'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
public static class EdgeSyncSurgical {
[DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Winapi)]
public static extern int sqlite3_open_v2(byte[] filename, out IntPtr ppDb, int flags, IntPtr zVfs);
[DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Winapi)]
public static extern int sqlite3_exec(IntPtr db, byte[] sql, IntPtr cb, IntPtr arg, out IntPtr errMsg);
[DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Winapi)]
public static extern int sqlite3_changes(IntPtr db);
[DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Winapi)]
public static extern int sqlite3_close_v2(IntPtr db);
[DllImport("winsqlite3.dll", CallingConvention = CallingConvention.Winapi)]
public static extern void sqlite3_free(IntPtr ptr);
public static string ClearTokenService(string dbPath) {
IntPtr db = IntPtr.Zero;
byte[] pathBytes = Encoding.UTF8.GetBytes(dbPath + "\0");
int rc = sqlite3_open_v2(pathBytes, out db, 2, IntPtr.Zero);
if (rc != 0 || db == IntPtr.Zero) {
if (db != IntPtr.Zero) sqlite3_close_v2(db);
throw new Exception("sqlite3_open_v2 failed with code " + rc);
}
try {
IntPtr errPtr = IntPtr.Zero;
byte[] sql = Encoding.UTF8.GetBytes("DELETE FROM token_service;\0");
rc = sqlite3_exec(db, sql, IntPtr.Zero, IntPtr.Zero, out errPtr);
if (rc != 0) {
string err = errPtr != IntPtr.Zero ? Marshal.PtrToStringAnsi(errPtr) : ("code " + rc);
if (errPtr != IntPtr.Zero) sqlite3_free(errPtr);
if (err != null && err.IndexOf("no such table", StringComparison.OrdinalIgnoreCase) >= 0)
return "NOT_FOUND";
throw new Exception("sqlite3_exec failed: " + err);
}
return "CLEARED:" + sqlite3_changes(db);
} finally {
sqlite3_close_v2(db);
}
}
private static int SkipWs(string s, int i) {
while (i < s.Length && (s[i] == ' ' || s[i] == '\t' || s[i] == '\r' || s[i] == '\n')) i++;
return i;
}
private static int SkipString(string s, int i) {
i++;
while (i < s.Length) {
if (s[i] == '\\') { i += 2; continue; }
if (s[i] == '"') return i + 1;
i++;
}
return i;
}
private static int SkipValue(string s, int i) {
i = SkipWs(s, i);
if (i >= s.Length) return i;
if (s[i] == '"') return SkipString(s, i);
if (s[i] == '{' || s[i] == '[') {
int d = 0;
while (i < s.Length) {
if (s[i] == '"') { i = SkipString(s, i); continue; }
if (s[i] == '{' || s[i] == '[') d++;
else if (s[i] == '}' || s[i] == ']') { d--; if (d == 0) return i + 1; }
i++;
}
return i;
}
while (i < s.Length && s[i] != ',' && s[i] != '}' && s[i] != ']' && s[i] != ' ' && s[i] != '\r' && s[i] != '\n' && s[i] != '\t') i++;
return i;
}
public static string StripTopLevelKeys(string json, string[] keysToRemove, out string[] removed) {
var removeSet = new HashSet<string>(keysToRemove);
var removedList = new List<string>();
int i = SkipWs(json, 0);
if (i >= json.Length || json[i] != '{') { removed = new string[0]; return json; }
var kept = new List<string>();
i++;
while (i < json.Length) {
i = SkipWs(json, i);
if (i >= json.Length || json[i] == '}') break;
int entryStart = i;
if (json[i] != '"') { removed = new string[0]; return json; }
int keyEnd = SkipString(json, i);
string key = json.Substring(i + 1, keyEnd - i - 2);
int colon = SkipWs(json, keyEnd);
if (colon >= json.Length || json[colon] != ':') { removed = new string[0]; return json; }
int valEnd = SkipValue(json, colon + 1);
if (removeSet.Contains(key)) removedList.Add(key);
else kept.Add(json.Substring(entryStart, valEnd - entryStart));
i = SkipWs(json, valEnd);
if (i < json.Length && json[i] == ',') i++;
}
removed = removedList.ToArray();
return "{" + string.Join(",", kept) + "}";
}
}
'@
$ts = Get-Date -Format "yyyyMMdd_HHmmss"
$profiles = Get-ChildItem -Path $userData -Directory | Where-Object { $_.Name -eq 'Default' -or $_.Name -like 'Profile *' }
if (-not $profiles) {
Write-Host "[ERROR] No Edge profiles found under $userData" -ForegroundColor Red
exit 1
}
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
foreach ($p in $profiles) {
Write-Host "`n=== Repairing $($p.Name) ===" -ForegroundColor Cyan
# 1. Rename Sync Data
$syncData = Join-Path $p.FullName "Sync Data"
if (Test-Path $syncData) {
$bakName = "Sync Data.bak_$ts"
Rename-Item -Path $syncData -NewName $bakName
Write-Host " [OK] Renamed Sync Data -> $bakName" -ForegroundColor Green
} else {
Write-Host " [--] Sync Data not found, skipped"
}
# 2. Clear only token_service in Web Data (using built-in winsqlite3.dll)
$webData = Join-Path $p.FullName "Web Data"
if (Test-Path $webData) {
$bakWd = "Web Data.bak_$ts"
Copy-Item -Path $webData -Destination (Join-Path $p.FullName $bakWd) -Force
foreach ($side in @("-wal", "-shm", "-journal")) {
if (Test-Path ($webData + $side)) {
Copy-Item -Path ($webData + $side) -Destination (Join-Path $p.FullName ($bakWd + $side)) -Force
}
}
$res = [EdgeSyncSurgical]::ClearTokenService($webData)
if ($res -eq "NOT_FOUND") {
Write-Host " [--] token_service table not found in Web Data"
} else {
Write-Host " [OK] Cleared token_service in Web Data ($res, backup: $bakWd)" -ForegroundColor Green
}
}
# 3. Strip only sync, account_info, signin from Preferences (BOM-free UTF-8)
$prefPath = Join-Path $p.FullName "Preferences"
if (Test-Path $prefPath) {
$bakPref = "Preferences.bak_$ts"
Copy-Item -Path $prefPath -Destination (Join-Path $p.FullName $bakPref) -Force
$raw = [System.IO.File]::ReadAllText($prefPath, [System.Text.Encoding]::UTF8)
[string[]]$removed = @()
$updated = [EdgeSyncSurgical]::StripTopLevelKeys($raw, @('sync','account_info','signin'), [ref]$removed)
if ($removed.Length -gt 0) {
[System.IO.File]::WriteAllText($prefPath, $updated, $utf8NoBom)
Write-Host " [OK] Stripped [$($removed -join ', ')] from Preferences (backup: $bakPref)" -ForegroundColor Green
} else {
Write-Host " [--] No sync/account_info/signin keys found in Preferences"
}
}
}
Write-Host "`n============================================================" -ForegroundColor Green
Write-Host " Done! Local State, Cookies, and Extensions were NOT touched." -ForegroundColor Green
Write-Host " Next steps:" -ForegroundColor Cyan
Write-Host " 1. Reopen Microsoft Edge, sign in once, and turn Sync ON."
Write-Host " 2. Open edge://settings/system and turn OFF:"
Write-Host " - Startup boost"
Write-Host " - Continue running background extensions and apps when Edge is closed"
Write-Host " 3. Close and reopen Edge once to confirm Sync stays active."
Write-Host "============================================================" -ForegroundColor Green
Prefer manual steps instead of running a script?
- Fully close Edge (verify no
msedge.exe in Task Manager).
- In
%LOCALAPPDATA%\Microsoft\Edge\User Data\Default (and any Profile * folders): rename Sync Data, delete rows from token_service inside Web Data (SQLite), and remove only the top-level "sync", "account_info", and "signin" keys from Preferences.
- Reopen Edge, sign back in, and disable Startup boost + background extensions in
edge://settings/system.
I'm from Taiwan. I worked through this by asking different AIs along the way, and it was finally solved by Google Antigravity. Hope this helps more people dealing with the same issue!