{"record":{"id":"f5d815f74f7c50cb","repo":"NanmiCoder/MediaCrawler","slug":"playwright-page-is-required-for-browser-based-comm","errorCode":null,"errorMessage":"playwright_page is required for browser-based comment fetching","messagePattern":"playwright_page is required for browser-based comment fetching","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"media_platform/tieba/client.py","lineNumber":471,"sourceCode":"        self,\n        note_detail: TiebaNote,\n        crawl_interval: float = 1.0,\n        callback: Optional[Callable] = None,\n        max_count: int = 10,\n    ) -> List[TiebaComment]:\n        \"\"\"\n        Get all first-level comments for specified post (uses Playwright to access page, avoiding API detection)\n        Args:\n            note_detail: Post detail object\n            crawl_interval: Crawl delay interval in seconds\n            callback: Callback function after one post crawl completes\n            max_count: Maximum number of comments to crawl per post\n        Returns:\n            List[TiebaComment]: Comment list\n        \"\"\"\n        if not self.playwright_page:\n            utils.logger.error(\"[BaiduTieBaClient.get_note_all_comments] playwright_page is None, cannot use browser mode\")\n            raise Exception(\"playwright_page is required for browser-based comment fetching\")\n\n        result: List[TiebaComment] = []\n        current_page = 1\n\n        while note_detail.total_replay_page >= current_page and len(result) < max_count:\n            utils.logger.info(\n                f\"[BaiduTieBaClient.get_note_all_comments] Accessing comment API, \"\n                f\"note_id: {note_detail.note_id}, page: {current_page}\"\n            )\n\n            try:\n                api_data = await self._get_pc_page_data(note_id=note_detail.note_id, page=current_page)\n                comments = self._page_extractor.extract_tieba_note_parent_comments_from_api(\n                    api_data, note_detail=note_detail\n                )\n\n                if not comments:\n                    utils.logger.info(f\"[BaiduTieBaClient.get_note_all_comments] Page {current_page} has no comments, stopping crawl\")","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/media_platform/tieba/client.py#L453-L489","documentation":"Raised by BaiduTieBaClient.get_note_all_comments (media_platform/tieba/client.py:471) when self.playwright_page is None. Comment pagination is fetched by loading the post page in a browser for each comment page, so the method hard-requires a live page. The guard triggers before the pagination while-loop starts.","triggerScenarios":"Calling get_note_all_comments(note_detail, ...) on a client with no playwright_page — e.g. a comment crawl scheduled before browser setup, or a client built only for cookie/HTTP usage.","commonSituations":"Reusing a client instance after the browser closed; enabling comment crawling (ENABLE_GET_COMMENTS) in a pipeline that never opens a browser; unit tests calling the method directly.","solutions":["Attach a Playwright page to the client before starting comment crawls","Run the platform's login/browser bootstrap first so playwright_page is populated","Skip comment crawling (or gate it on bool(client.playwright_page)) in pipelines that legitimately run browserless"],"exampleFix":"# before\ncomments = await client.get_note_all_comments(note)\n\n# after\nif not client.playwright_page:\n    client.playwright_page = await context.new_page()\ncomments = await client.get_note_all_comments(note)","handlingStrategy":"type-guard","validationCode":"if not client.playwright_page:\n    client.playwright_page = await browser_context.new_page()","typeGuard":"def can_fetch_comments(client) -> bool:\n    return client.playwright_page is not None and not client.playwright_page.is_closed()","tryCatchPattern":null,"preventionTips":["Gate comment crawling on bool(client.playwright_page) in browserless pipelines","Complete login (which creates the page) before the comment stage","Handle browser crashes by re-initializing context and page together"],"tags":["playwright","tieba","comments","browser-context","validation"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}