Skip to content

Reddit Module

Scrapes top Reddit posts from configured subreddits using browser automation.

RedditService

fetchTopPosts(limit: number): Promise<Result<RedditPost[], RedditError>>

Scrapes configured subreddits for top posts:

  1. Opens browser page via BrowserService
  2. Iterates subreddits in configured order
  3. Applies filters: minimum score, max age, max text length, already-processed check
  4. Returns up to limit qualifying posts

markAsProcessed(postId, subreddit, title, score): Promise<Result<void, RedditError>>

Records a post as processed to prevent re-scraping.

Time Filter Escalation

When REDDIT_TIME_FILTER_ESCALATION=true (default), if not enough posts are found at the current time filter, the service automatically escalates:

day (48h) → week (168h) → month (720h)

RedditPost

typescript
interface RedditPost {
  id: string;
  subreddit: string;
  title: string;
  body: string;
  score: number;
  url: string;
  createdUtc: number;
}

Error Codes

CodeDescription
BROWSER_NOT_READYCamoufox not initialized
NAVIGATION_FAILEDFailed to load subreddit page
SCRAPING_FAILEDDOM parsing error
NO_POSTS_FOUNDNo posts match filters
PERSISTENCE_FAILEDDatabase write error

Built with VitePress