Skip to content

Get the timestamp of the last browser activity#4

Merged
ariya merged 1 commit intomainfrom
timestamp
Jan 27, 2026
Merged

Get the timestamp of the last browser activity#4
ariya merged 1 commit intomainfrom
timestamp

Conversation

@ariya
Copy link
Contributor

@ariya ariya commented Jan 27, 2026

This is done by going inside the browser container:

  1. copy the browser history file (to avoid locked access)
  2. get the most recent last_visit_time

Note that the browser history file is just a regular SQLite database.

Chromium stores the timestamp in microseconds since 1601-01-01 00:00:00 UTC, hence a conversion is necessary to get the usual Unix epochs (in seconds).

2026-01-26 chrome fleet activity timestamp

To verify, run uv run chromefleet.py as usual, start a browser, and query it.

Before:

{"ip_address":"100.70.213.14",
 "cdp_url":"http://100.70.213.14:9222"}

After:

{"ip_address":"100.70.213.14",
 "cdp_url":"http://100.70.213.14:9222",
 "last_activity_timestamp":1769470996.638466}

This is done by going inside the browser container:

1) copy the browser history file (to avoid locked access)
2) get the most recent `last_visit_time`

Note that the browser history file is just a regular SQLite database.

Chromium stores the timestamp in microseconds since 1601-01-01 00:00:00 UTC,
hence a conversion is necessary to get the usual Unix epochs (in seconds).

To verify, run `uv run chromefleet.py` as usual, start a browser, and query it.

Before:
```json
{"ip_address":"100.70.213.14",
 "cdp_url":"http://100.70.213.14:9222"}
```

After:
```json
{"ip_address":"100.70.213.14",
 "cdp_url":"http://100.70.213.14:9222",
 "last_activity_timestamp":1769470996.638466}
```
@ariya
Copy link
Contributor Author

ariya commented Jan 27, 2026

Note that this depends on SQLite on the browser containers:

@ariya ariya requested review from bin-ario and kpprasa January 27, 2026 01:20

async def get_container_last_activity(container_name: str) -> float | None:
try:
run_podman(["exec", container_name, "sh", "-c", "cp $HOME/chrome-profile/Default/History db"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is copy necessary or can we just query the History file directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Chromium is still running, it will lock write access to that file (because sqlite3 will want to read and write).

@ariya ariya merged commit 592c3f3 into main Jan 27, 2026
3 checks passed
@ariya ariya deleted the timestamp branch January 27, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants