Skip to content

feat(wellbeing): daily watch-time limit and break reminder (#4078) - #4490

Open
chirag127 wants to merge 3 commits into
code-charity:masterfrom
chirag127:feat/time-limiter
Open

chirag127 wants to merge 3 commits into
code-charity:masterfrom
chirag127:feat/time-limiter

Conversation

@chirag127

Copy link
Copy Markdown

Closes #4078.

What this adds

Two independent limits under General → Time limiter:

Control Behaviour
Daily watch limit Counts playback seconds per local day. At the limit the video pauses and a full-screen overlay offers Watch 5 more minutes or Not now.
Break reminder Every N minutes of playback, a dismissible toast suggests a break. 0 turns it off.

Only playback counts: the timer checks video.paused, video.ended and document.hidden, and caps a single tick at 5 s so a sleeping laptop or a background tab does not add an hour. The count rolls over at local midnight.

Design notes

  • Storage is its own key (time_limiter_data = {date, seconds, bonus}), written through the extension bridge with {action:'set'}. The Analyzer's data is untouched, so the two features can disagree without corrupting each other.
  • The 5-minute extension is stored as a bonus for the current day, not as a one-off flag, so it survives a reload and resets tomorrow.
  • "Not now" only closes the overlay. If the limit is still exceeded, the next tick pauses the video and shows it again; the extension button is the way through.
  • Default limit 60 min, reminder 0, feature off.

Where it lives

File Change
js&css/web-accessible/www.youtube.com/features/time-limiter.js new module
menu/skeleton-parts/time-limiter.js new card under General
_locales/en/messages.json four keys
manifest.json, js&css/extension/init.js, menu/index.html one line each
tests/unit/time-limiter.test.js 5 tests

Verification

$ npx jest tests/unit/time-limiter.test.js
Tests: 5 passed, 5 total
  - 0m / 1m 30s / 1h 1m formatting
  - a stored yesterday resets to 0 today
  - same-day accumulation keeps the bonus
  - remaining and over at the boundary
  - bonus extends the allowed time

$ npx jest
Test Suites: 40 passed, 40 total
Tests:       241 passed, 241 total

$ ESLINT_USE_FLAT_CONFIG=true npx eslint --config=tests/eslint_rules.config.mjs <changed files>
0 errors

Live in Chrome 157 on watch?v=dQw4w9WgXcQ with a 1-minute limit and 60 s already used:

ImprovedTube.timeLimiterTick(0)
-> {used: 60, allowed: 60, remaining: 0, over: true}
overlay present, text "Daily watch limit reached / You have watched 1m today. The limit is 1m."

Time limiter

Not tested

  • A full day of real playback, and the local-midnight rollover live (unit-tested with fixed dates).
  • The break toast during real playback; the code path is the same tick that is live-verified.
  • Multiple tabs at once. Each tab counts its own playback; the storage value is last-write-wins, so two playing tabs can undercount. A cross-tab counter would need a new permission-free locking scheme, which I did not want to bolt on here.
  • Firefox/Safari.

Conflicts

New files only. #4078 is the only issue for this; no open PR mentions a time limiter (checked the 160 open PR titles/bodies for limit/timer/break). Off by default.

Counts playback seconds per local day, pauses at the limit with a
5-minute extension, and can toast a break reminder. Uses its own
storage key, not the Analyzer data.
@chirag127
chirag127 marked this pull request as ready for review November 18, 2026 10:24
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.

Time limiter: daily time limit and break reminders

1 participant