fix: use cloned browser profile and pass user-agent to crawler contexts#755
Draft
younglim wants to merge 1 commit into
Draft
fix: use cloned browser profile and pass user-agent to crawler contexts#755younglim wants to merge 1 commit into
younglim wants to merge 1 commit into
Conversation
…er contexts The domain and sitemap crawlers were creating empty sub-profile directories per browser launch, discarding the cloned Chrome profile data. They also never passed process.env.OOBEE_USER_AGENT to the browser context, causing WAF-protected sites to see HeadlessChrome in the UA and return 403. - Extract shared getPreLaunchHook() into commonCrawlerFunc that removes stale SingletonLock and sets userDataDir to the actual cloned profile - Pass OOBEE_USER_AGENT in preLaunchHooks launchOptions for both crawlers - Remove per-browser sub-profile creation (empty dirs served no purpose) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
crawlDomainandcrawlSitemapwere creating empty sub-profile directories per browser launch, discarding the cloned Chrome profile data (cookies, preferences). The browser never benefited from the cloned profile.process.env.OOBEE_USER_AGENTto the Playwright browser context, so WAF-protected sites (e.g. scdf.gov.sg) sawHeadlessChromein the UA string and returned 403.getPreLaunchHook()intocommonCrawlerFunc.tsto eliminate duplication between both crawlers.Changes
src/crawlers/commonCrawlerFunc.tsgetPreLaunchHook(userDataDirectory)— removes staleSingletonLock, setsuserDataDirto the actual cloned profilesrc/crawlers/crawlDomain.tsOOBEE_USER_AGENTinlaunchOptions, remove sub-profile creationsrc/crawlers/crawlSitemap.tsRoot cause
crawlDomain.tsprofile-{ts}-{rand}/sub-dirs; UA never setuserAgentpassed inpreLaunchHookscrawlSitemap.tsTest plan
npx tsc --noEmitpassesnavigator.userAgentin crawled pages does not containHeadlessChromeSingletonLockerrors on repeated scan runs