Skip to content

add like support for comments and replies - #2

Open
FahadBinHussain wants to merge 15 commits into
andronedev:mainfrom
FahadBinHussain:fix-comment-like-button
Open

FahadBinHussain wants to merge 15 commits into
andronedev:mainfrom
FahadBinHussain:fix-comment-like-button

Conversation

@FahadBinHussain

Copy link
Copy Markdown

adds like and unlike for comments and replies.

what changed:

  • parse the engagement toolbar surface out of the comment framework updates, so every comment carries its like state plus the likeCommand / unlikeCommand commands
  • send authorization: sapisidhash on the next fetches — youtube only returns those commands to authenticated requests
  • hash the sapisid over the page origin instead of a hardcoded https://www.youtube.com — youtube validates the hash against the origin header it actually receives, a music.youtube.com page sends https://music.youtube.com, so the old hash was rejected and every request came back logged out (that is why probes showed logged_in=0 and the like button turned into a sign-in gate)
  • like posts to youtubei/v1/comment/perform_comment_action with the endpoint payload normalized to actions: [action]; the innertubeCommand-wrapped shape gets 400, and if the loop ever has to use a non-primary body shape it warns perform-comment-variant instead of hiding it
  • optimistic toggle in the ui, rollback plus a visible error with the server text when it fails, sign in to like when the surface is gated
  • the comments icon click listener moved from the inner button to the button shape — a click on the shape padding used to bubble into youtube action bar handler and bounce the page off /watch

verified in a real browser: like flips to unlike comment on a single 200 with yt_li=1, survives a full page reload, unlike restores it, account left clean. probes come back logged in, drawer opens and the page stays on /watch.

stacked on #1 (the comments icon fix) — this branch contains those commits, merge that one first.

the icon stopped appearing after yt changed the player bar. the old single anchor (.middle-controls-buttons > ytmusic-menu-renderer) broke two ways: the menu renderer now only stamps when yt serves currentItem.menu, and isMiniplayerEnabled can swap the whole top bar for the lit ytmusic-miniplayer which has no middle-controls at all.

placeButton() now walks ordered anchors - menu renderer, like button (unconditional sibling), middle-controls-buttons, then the miniplayer action bar. a non-primary anchor warns once and stamps data-ytm-anchor-strategy on the host; if nothing matches it logs the observed dom structure instead of failing silently. App.vue also warns when /watch loses its ?v= param, since that hides the button with display:none.

all diagnostics go through the new warnOnce() helper so a full session logs a handful of lines instead of hundreds.
fetching the www.youtube.com homepage for INNERTUBE_CONTEXT is CORS-blocked from a music content script, which left the client version stuck on the hardcoded 2.20240101.00.00 fallback - a stale client makes yt return comment pages without the framework updates, so threads silently come back empty.

the current origin's own page embeds a fresh context and is same-origin, so harvest from there instead. extraction walks balanced braces (a non-greedy regex stops at the first nested brace and truncates the object). the music page serves WEB_REMIX, which gets no comments at all, so the harvest rewrites it to WEB keeping the date with the canonical .00.00 build. each harvest failure warns once instead of on every refresh.
logging was flooding the console while scrolling - buildAuthHeaders warned
on every /next fetch (dozens per scroll), deriveLikeMeta dumped a 3KB
surface payload per comment, and every comment currently being gated meant
that fired for all ~20 comments on every page. the real signals were
buried.

- new lib/log.ts warnOnce(): each key logs once per page load
- removed the chrome.storage.local debug stash entirely (ytmDebugParse /
  ytmDebugLike) - edge's leveldb never flushed 000003.log, the transport
  was already dead and only added noise
- parseComments: dropped fingerprintPaths + stashParseDebug, condensed the
  per-thread debug block into one map-sizes line
- youtubeApi: auth header booleans, performCommentAction payload and
  fallback per-variant failures all one-shot
- clientContext: harvest failure warns one-shot (refreshClientContext
  re-harvests on every implausible response)
- auth: prefer __Secure-3PAPISID over legacy SAPISID for the hash
the auth probe concluded authed=false from a regex that only matched protojson 1/0 form. youtube can also serialize bools as true/false, in which case every probe was a false negative and the entire auth-is-broken investigation was built on nothing.

probe now logs the raw ~50 chars around the occurrence plus whether the visitor-id header was present on that probe. also one-shot logs when visitorData gets captured from an api response - if that never fires, x-goog-visitor-id stays absent forever and youtube gates the engagement surface even with valid auth.
ground truth from the raw probe: youtube serializes logged_in as a key/value pair with value 0, and every probe - including same-origin music where cookies are guaranteed first-party - reports logged out. so the sapisidhash and visitor-id were never the gate.

probe D strips the authorization and visitor headers entirely on a same-origin fetch. youtube authenticates account_menu on the session cookies alone in first-party context, so D=1 means our own header is downgrading auth and D=0 means the cookie session itself is dead or absent.

also logs which session cookies the page can see at all (names only - values are session secrets).
…(0.2.6)

- sapisidhash was computed over the hardcoded https://www.youtube.com origin, but youtube validates it against the real origin header, so calls from music.youtube.com came back logged out and the like command was just a sign-in gate. hash location.origin now and warn loudly when the page origin is not youtube.
- unwrap innertubeCommand in the like payload: the endpoint-wrapped body was answered 400 invalid argument. canonical body is actions[] plus clickTrackingParams, confirmed end to end in the browser; when a non-primary body shape has to be used the loop warns perform-comment-variant instead of hiding it.
- move the click listener from the inner button to the button shape. a click landing on the shape padding had no listener, bubbled into yt action bar host and bounced the page off /watch within a millisecond.
- e2e verified in a real browser: like flips to unlike with a 200 yt_li=1, persists across a full page reload, unlike restores it, account left clean at 20/0.
…he stacked pr

the like line carried its own agent notes, which dropped three sections the icon branch had added. this puts them back so this branch is a strict superset: icon anchor strategies, same-origin client context harvest, and warnOnce logging rules.
package.json and AGENTS.md conflict on every cross-branch pick; take the incoming file and let cherry-pick keep the original message.
the read-only paragraph and the www-scrape fallback description predated both fixes; they contradicted what the extension actually does now.
@andronedev

Copy link
Copy Markdown
Owner

Thanks a lot for this, really solid investigation (the origin-based SAPISIDHASH and the actions[] body shape especially). I'm interested in like support, but the extension's position so far is "anonymous, no cookies" (it's in PRIVACY.md and the Chrome Web Store privacy form), so it needs to land in a way that keeps that the default.

Since v0.2.0 reworked a lot (new player bar, no more clientContext.ts, anonymous credentials: 'omit' requests, i18n), this branch would need to be rebuilt on top of current main. Before you spend time on that, here's what I'd be happy to merge:

  1. Based on current main (v0.2.1).
  2. Loading comments stays anonymous. No auth headers or cookies on /next. Auth (SAPISIDHASH, credentials) only on the like / unlike request itself.
  3. Opt-in, at the moment it's needed:
    • The 👍 button stays visible on every comment (slightly dimmed while likes are off).
    • First click shows a small inline prompt in the drawer: "To like, the extension uses your YouTube session. Enable?" → [Enable] / [No thanks]. On Enable, the like goes through right away.
    • Signed out → same prompt, but "Sign in to YouTube to like".
    • The drawer's ⋮ menu has a toggle to turn likes off / back on.
  4. No diagnostics in production: please drop probeAuthState, the cookie inventory logs, the synthetic-commentId fallback (and its badge), and the multi-variant body loop. One known body shape, with a clear error if it fails.
  5. Strings go through lib/i18n (English is enough, I'll handle the other locales).
  6. No AGENTS.md, no version bump, I handle versions at release time.

If that scope works for you, a fresh PR against main would probably be easier than rebasing this one. And no worries at all if it's more than you signed up for, thanks again either way!

the upstream dead note aged out in three weeks: v0.2.0 and v0.2.1 landed, the icon pr got superseded and closed, and the like pr carries a scope offer parked for later.
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