A Go port of the xBrowserSync REST API service. This is a drop-in replacement for the original Node.js API - existing browser extensions and mobile apps connect to it without any changes.
xBrowserSync is a free tool for syncing browser data between different browsers and devices, built for privacy and anonymity. The server stores only encrypted, opaque data - all encryption and decryption happens client-side.
git clone https://github.com/navin09/xbrowsersync-api-go.git
cd xbrowsersync-api-go
make build
./bin/xbrowsersync-api
The server starts on http://127.0.0.1:8080/ by default.
-
Create a database user and the required indexes in the mongo shell:
use admin db.createUser({ user: "xbrowsersyncdb", pwd: "[password]", roles: [ { role: "readWrite", db: "xbrowsersync" }, { role: "readWrite", db: "xbrowsersynctest" } ] }) use xbrowsersync db.newsynclogs.createIndex({ "expiresAt": 1 }, { expireAfterSeconds: 0 }) db.newsynclogs.createIndex({ "ipAddress": 1 }) -
Set the database credentials via environment variables:
export XBROWSERSYNC_DB_USER=xbrowsersyncdb export XBROWSERSYNC_DB_PWD=[password] -
If exposing your service publicly, add a TTL index to automatically delete syncs that haven't been accessed for 3 weeks:
use xbrowsersync db.bookmarks.createIndex({ "lastAccessed": 1 }, { expireAfterSeconds: 1814400 })
Configuration is managed through two JSON files in the config/ directory:
settings.default.json- contains all settings with their default values. Do not edit this file.settings.json- your overrides. Create this file and include only the settings you want to change.
To customise your instance, copy the settings you want to override from settings.default.json into a new config/settings.json. For example, to set a welcome message and restrict the service to specific origins:
{
"status": {
"message": "Welcome to my xBrowserSync service"
},
"allowedOrigins": ["https://mybrowser.example.com"]
}Any settings not present in settings.json fall back to the defaults. This means future updates to default values are picked up automatically - only override what you need.
Database credentials can also be supplied via environment variables (XBROWSERSYNC_DB_USER, XBROWSERSYNC_DB_PWD), which take precedence over empty values in the config files.
| Setting | Default | Description |
|---|---|---|
allowedOrigins |
[] |
Permitted CORS origins. Empty allows all. |
dailyNewSyncsLimit |
3 |
Max new syncs per IP per day. 0 disables the limit. |
db.host |
127.0.0.1 |
MongoDB hostname |
db.port |
27017 |
MongoDB port |
db.name |
xbrowsersync |
Database name |
db.username / db.password |
"" |
DB credentials (or use env vars) |
db.authSource |
admin |
MongoDB auth database |
db.connTimeout |
30000 |
Connection timeout in ms |
db.ssl |
false |
Enable SSL/TLS |
db.useSRV |
false |
Use mongodb+srv:// connection string |
location |
"" |
ISO 3166-1 alpha-2 country code for this service |
log.file.enabled |
true |
Enable file logging |
log.file.path |
/var/log/xBrowserSync/api.log |
Log file path |
log.file.level |
info |
Log level (trace/debug/info/warn/error/fatal) |
log.file.rotatedFilesToKeep |
5 |
Number of rotated log files to retain |
log.file.rotationPeriod |
1d |
Log rotation period |
log.stdout.enabled |
true |
Enable console logging |
log.stdout.level |
info |
Console log level |
maxSyncs |
5242 |
Max total syncs. 0 disables the limit. |
maxSyncSize |
512000 |
Max sync payload size in bytes |
server.host |
127.0.0.1 |
Bind address |
server.port |
8080 |
Bind port |
server.relativePath |
/ |
URL path prefix |
server.behindProxy |
false |
Trust X-Forwarded-For for client IP |
server.https.enabled |
false |
Enable HTTPS |
server.https.certPath |
"" |
Path to TLS certificate |
server.https.keyPath |
"" |
Path to TLS private key |
status.online |
true |
Whether the service is online |
status.allowNewSyncs |
true |
Whether to accept new sync creation |
status.message |
"" |
Status message (HTML, script tags stripped) |
throttle.maxRequests |
1000 |
Max requests per time window. 0 disables. |
throttle.timeWindow |
300000 |
Rate limit window in ms (default 5 minutes) |
make build # builds bin/xbrowsersync-api
make test # runs unit tests
make lint # runs golangci-lint (if installed)
make clean # removes bin/
To set a custom version string:
make build VERSION=2.0.0
make run
# or
./bin/xbrowsersync-api
The binary looks for config/ relative to the working directory.
| Method | Path | Description |
|---|---|---|
| POST | /bookmarks | Create a new sync |
| GET | /bookmarks/:id | Retrieve bookmarks by sync ID |
| PUT | /bookmarks/:id | Update bookmarks |
| GET | /bookmarks/:id/lastUpdated | Get last updated timestamp |
| GET | /bookmarks/:id/version | Get sync version |
| GET | /info | Service status and metadata |
All endpoints support API versioning via the Accept-Version header.
Build and run with Docker:
docker build -t xbrowsersync-api .
docker run -p 8080:8080 \
-e XBROWSERSYNC_DB_USER=xbrowsersyncdb \
-e XBROWSERSYNC_DB_PWD=[password] \
-v /path/to/settings.json:/config/settings.json \
xbrowsersync-api
The image is ~15MB (distroless base). Mount your settings.json to override defaults - at minimum you'll need to set db.host to point at your MongoDB instance.
Cloud Run runs the Docker container serverlessly - it scales to zero when idle and you only pay for requests.
- A MongoDB Atlas cluster (free tier works). Cloud Run can't host MongoDB, so you need an external database.
- Google Cloud SDK installed and a GCP project configured.
-
Create a
config/settings.jsonfor Cloud Run:{ "db": { "host": "your-cluster.mongodb.net", "name": "xbrowsersync", "useSRV": true }, "server": { "host": "0.0.0.0", "behindProxy": true }, "log": { "file": { "enabled": false } } }Key settings:
hostmust be0.0.0.0(Cloud Run requirement),behindProxyshould betrue(Cloud Run terminates TLS), and file logging is disabled (use stdout - Cloud Run captures it automatically). -
Build and push the container:
gcloud builds submit --tag gcr.io/YOUR_PROJECT/xbrowsersync-api -
Deploy to Cloud Run:
gcloud run deploy xbrowsersync-api \ --image gcr.io/YOUR_PROJECT/xbrowsersync-api \ --port 8080 \ --set-env-vars XBROWSERSYNC_DB_USER=xbrowsersyncdb,XBROWSERSYNC_DB_PWD=[password] \ --allow-unauthenticated -
Point your xBrowserSync extension at the Cloud Run URL.
This is a faithful port of the Node.js xBrowserSync API. It uses the same:
- MongoDB collections and schema (including binary UUID storage)
- JSON config file format
- API contract (endpoints, request/response shapes, error codes, HTTP status codes)
- Semver-based API version routing
Existing xBrowserSync clients work without modification. Data created by the Node.js server is fully readable by the Go server and vice versa.
GPL-3.0