Repository navigation
Conversation
Reddit's edge now answers every comments API route (/comments/{id}.json,
/r/{sub}/comments/...) with a 403 HTML block page for anonymous OAuth
tokens, so post pages failed with "Failed to parse page JSON data".
Fetch the post from /by_id, which still works, and build the comment
tree from www.reddit.com/svc/shreddit fragments, expanding "more"
placeholders concurrently within a bounded budget. Shreddit requests use
their own cookie session, rotated before Reddit's per-session rate limit
or on a 429/captcha response.
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Great idea! Unfortunately, I'm getting this error: and: Edit: tried a different IP, now I'm getting 302 found error. |
|
@arch-btw I've made a commit on my fork that should fix the 302 Found error, by following the redirect similar to somewhere else in the client.rs file. |
knguyen1/fix/shreddit-comments fix(post): load comments from shreddit HTML fragments
|
Okay, I've done some brief testing, and it's obvious to me that this is much slower than the original, even with release optimisations. I guess that's web scraping for ya.
|
Reddit answers some clients with a 302 to the same shreddit path plus an rdt query parameter and cookie. Follow up to three such redirects with the original method and cursor, refusing any target outside /svc/shreddit/ on www.reddit.com, instead of failing with "Reddit returned 302 Found". Replace the batch barrier in the crawler with a JoinSet so one slow "more comments" request no longer holds up the rest of its batch. Thanks to @Sparronator9999 for reporting the redirect and the first fix. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks both! I pushed 1d55e3e to address this. (Like the PR, this reply was written with an AI coding assistant.) 302 Found (@arch-btw, @Sparronator9999): this is Reddit's bot check. It answers with
I couldn't trigger the 302 from my own IP, so it would help if someone who sees it could confirm the fix. 403 Forbidden: shreddit requests go to www.reddit.com. A 403 there most likely means Reddit is blocking that IP for www, as it does for some VPN and datacenter ranges, which code can't work around. If you have a moment, could you check whether
Speed: scraping does need more round trips than the old single JSON request. The crawler now keeps 10 expansion requests in flight and starts the next one as soon as any finishes, rather than waiting for a whole batch. In a release build, uncached post pages took 0.7–1.8s in my testing:
Results are cached for 30s. |
|
I've updated my fork to the latest commit of this PR (not pushed to GitHub yet, as of writing). It does seem a bit faster than last time.
|
|
Okay, I've done some more testing, and media proxied via the An example of a comment that uses
```
```
|
knguyen1/fix/shreddit-comments fix(post): load comments from shreddit HTML fragments
Comment media is wrapped in Reddit's <shreddit-player> custom element, which only renders through Reddit's JavaScript, so GIFs showed up as an empty clickable box. Replace each player with a <video> of its proxied MP4 source, autoplaying and looping silently for GIFs like Reddit does. Reported by @Sparronator9999. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@Sparronator9999 thanks for the report and the markup sample! Fixed in a12eaf6. (This reply was written with an AI coding assistant.) Comment media is wrapped in Reddit's Checked on your example comment and on https://www.reddit.com/r/memes/comments/1xd9q2w/that_would_be_the_final_straw/19rj2mpfyhh5w/. A new unit test builds on your sample markup. |
Reddit's edge now answers "more comments" POSTs without an Origin or Referer with its "blocked by network security" 403, so Chrome-emulating instances only showed the first fragment. Send the Origin, Referer and Sec-Fetch headers a browser sends with these requests. Shreddit also serves mobile browsers 10 comments per fragment instead of 25, so shreddit requests now use their own client with a desktop platform. The OAuth API client keeps its existing emulation. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Fixed a regression in 26c0219: busy posts only showed about 10 comments and no replies. (This reply was written with an AI coding assistant.) There were two causes, and both depended on which browser redlib happens to emulate:
Tested with all four profile/platform combinations: every expansion succeeds and first fragments have 25 comments. For example, an AskReddit post with 7.5k comments went from 10 visible comments to about 285, and the "More replies" links load their threads. |
…/shreddit-comments fix(post): load comments from shreddit HTML fragments
|
Sorry for the delayed comment on the latest commits - I literally didn't have the energy to even comment on this PR over the past few days thanks to a nasty cold (or worse). Anyways, I tested the latest commits, and the images are indeed restored, however there are still issues with a few images overflowing their container. For example, a few comments on this post, but nearly every post I saw that was media heavy in the comments had this issue. I can't tell for sure, but I think loading times did improve somewhat since I updated my fork to the latest version of this PR, thanks to the desktop client commit. |
Note
This PR was created with AI. The code, tests, and this description were written by an AI coding assistant.
Problem
Every post page currently fails with:
Reddit's edge now answers all comments API routes with a 403 "blocked by network security" HTML page when they are called with the anonymous Android OAuth token. This affects
/comments/{id}.json,/r/{sub}/comments/..., and bothoauth.reddit.comandwww. Other routes (/by_id/t3_{id}.json, listings,/duplicates) still work. The GraphQL comments endpoints returnNOT_AUTHENTICATED, so they are not an alternative.Possibly related: #488.
Fix
/by_id/t3_{id}.json, which still returns the same JSON thatparse_postexpects.www.reddit.com/svc/shreddit/comments/r/{sub}/t3_{id}[/t1_{comment}]?sort=...). The newsrc/shreddit.rsmodule:<shreddit-comment>elements withscraperinto the same JSON shape the comments endpoint used to return, soparse_comments,query_commentsand the templates are unchanged;/svc/shreddit/more-comments/...POSTs carrying the hiddencursor) breadth-first, keeping up to 10 requests in flight and starting the next as soon as one finishes. This is bounded byCRAWL_LIMITS(200 comments, 30 expansions, 10 in flight). Unexpanded placeholders become the usual "More replies (N)" links;/comments/{id}/{slug}/{comment}) and?context=Nby expanding only placeholders under the focused comment, then trimming the tree to the focused thread;cachedfetchers.client.rs,shreddit_fragmentis the only network entry point. It accepts only/svc/shreddit/paths and handles Reddit's throttling of these endpoints:wreqcookie jar (enabled via thecookiesfeature), which gets about 225 requests per session window.x-ratelimit-remaining< 20), and also on a 429 or captcha response, followed by a single retry.302 Location: <same path>?rdt=NNNNNplus anrdtcookie. Up to three redirects are followed with the original method and cursor. Targets outside/svc/shreddit/on www.reddit.com are refused.Trade-offs
scraper0.29, with default features off. Its html5ever MSRV of 1.85 is below the effective MSRV already imposed bytime.Testing
cargo fmt --checkandcargo clippy --all-targetsare clean.shreddit.rs, covering:client.rschecks that non-shreddit paths are rejected.cargo testrun shows the same network-dependent failures asmain. Those tests are flaky against live Reddit; none of the failures come from this change.sort=newandsort=topwork./comments/{id}works.?context=3.Dockerfile.alpineimage works when run read-only asnobody.