-
Notifications
You must be signed in to change notification settings - Fork 9.4k
fix(route/cw): Deprecate obsolete puppeteer method. #21158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import cache from '@/utils/cache'; | |||||||||||||||||||||||||||||
| import logger from '@/utils/logger'; | ||||||||||||||||||||||||||||||
| import ofetch from '@/utils/ofetch'; | ||||||||||||||||||||||||||||||
| import { parseDate } from '@/utils/parse-date'; | ||||||||||||||||||||||||||||||
| import { getPuppeteerPage } from '@/utils/puppeteer'; | ||||||||||||||||||||||||||||||
| import { getCookies, setCookies } from '@/utils/puppeteer-utils'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| let cookie; | ||||||||||||||||||||||||||||||
|
|
@@ -29,18 +30,11 @@ const pathMap = { | |||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const getCookie = async (browser, tryGet) => { | ||||||||||||||||||||||||||||||
| const getCookie = async (tryGet) => { | ||||||||||||||||||||||||||||||
| if (!cookie) { | ||||||||||||||||||||||||||||||
| cookie = await tryGet('cw:cookie', async () => { | ||||||||||||||||||||||||||||||
| const page = await browser.newPage(); | ||||||||||||||||||||||||||||||
| await page.setRequestInterception(true); | ||||||||||||||||||||||||||||||
| page.on('request', (request) => { | ||||||||||||||||||||||||||||||
| request.resourceType() === 'document' || request.resourceType() === 'script' ? request.continue() : request.abort(); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| logger.http(`Requesting ${baseUrl}/user/get/cookie-bar`); | ||||||||||||||||||||||||||||||
| await page.goto(`${baseUrl}/user/get/cookie-bar`, { | ||||||||||||||||||||||||||||||
| waitUntil: 'domcontentloaded', | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| const { page } = (await getPuppeteerPage(`${baseUrl}/user/get/cookie-bar`)); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| const { page } = (await getPuppeteerPage(`${baseUrl}/user/get/cookie-bar`)); | |
| const { page } = await getPuppeteerPage(`${baseUrl}/user/get/cookie-bar`, { | |
| onBeforeLoad: async (page) => { | |
| await page.setRequestInterception(true); | |
| page.on('request', (request) => { | |
| const resourceType = request.resourceType(); | |
| if (resourceType === 'document' || resourceType === 'xhr' || resourceType === 'fetch') { | |
| request.continue(); | |
| } else { | |
| request.abort(); | |
| } | |
| }); | |
| }, | |
| }); |
Copilot
AI
Feb 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCookie uses getPuppeteerPage(...) but only closes the page; the underlying browser is left open until the helper's 30s timeout. Please also close/destroy the browser returned by getPuppeteerPage (e.g. via its destory function) to avoid accumulating Chromium processes on cache misses.
Copilot
AI
Feb 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsePage signature was changed to (path, ctx), but other CW route handlers (e.g. lib/routes/cw/author.ts, master.ts, sub.ts) still call parsePage(path, browser, ctx). This will cause TypeScript compile failures; either update those call sites to the new signature, or keep backward compatibility (e.g. accept an optional browser parameter).
Copilot
AI
Feb 15, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous implementation intercepted requests and aborted non-document/script resources; switching to getPuppeteerPage without setting request interception can significantly increase bandwidth/latency for these pages. Consider using getPuppeteerPage(..., { onBeforeLoad }) to enable request interception (or otherwise block images/fonts/styles) before navigation to keep behavior/performance consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file still imports
puppeteer(top of file) but no longer uses it after switching toparsePage('today', ctx). Since ESLint enforces@typescript-eslint/no-unused-vars, remove the unused import to avoid CI/lint failures.