Repository navigation
Stop on a refused proxy before starting a browser, and skip media behind a proxy - #46
Merged
Merged
Conversation
…ind a proxy The three browser engines send one HEAD for robots.txt through --proxy / --proxy-file before launching a local browser; a gateway 407 or 402 ends the run with exit 5 and stop_reason proxy_auth_failed in a new <out>.latest_attempt.meta.json, leaving the data and <out>.meta.json alone. Selenium pre-checks the proxy without credentials, as its browser uses it. Behind a local proxy the engines abort images, video/audio and web fonts (--load-media opts out); nothing changes over --cdp-endpoint or with no proxy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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.
Problem
A run through a paid proxy could start a whole browser on a proxy that refuses every request (a gateway
407or402). Once it was running, a local browser behind the proxy also downloaded every image, video and web font through the metered proxy, and no parser here reads any of them.What changes
Proxy pre-check. Before a local browser starts behind
--proxy/--proxy-file,playwright_scraper.py,puppeteer_scraper.pyandselenium_scraper.pyeach send ONEHEAD https://www.farfetch.com/robots.txtthrough the proxy (proxy_pool.precheck_proxy).--proxyvalue.scheme://host:port, because its browser's--proxy-servercannot carry credentials either. On a 407 it adds a line saying that, and points toplaywright_scraper.py.407: exit 5, with the messagethe gateway refused the credential (or the traffic balance is exhausted).402: exit 5, with the messageproxy traffic/balance exhausted.FARFETCH_PROXYand never prints its value.<out>.latest_attempt.meta.jsonrecordsstatus: failed,stop_reason: proxy_auth_failedanddata_updated: false. The data files and<out>.meta.jsonare left untouched. This repo had no attempt sidecar, sooutput_writer.write_failed_attemptwas added for it.proxy_auth_failedjoinsFETCH_FAILURE_STOP_REASONS.socks5://proxy) does not count as a verdict, and the run continues as it did before.--cdp-endpoint.Media blocking, only for a local browser behind a proxy:
context.routeby resource type, installed in_launch_local, so it also covers rotations and--concurrencyworkers.Fetch.enablewithImage/Media/Fontpatterns.Network.setBlockedURLsby file extension.--load-media(in--help) opts out on all three engines. A hidden--force-block-mediaturns blocking on without a proxy, for measurement.Evidence
Offline suite (
python smoke_test.py):SKIPPED_ENGINES: pyppeteer,selenium;pytest -q: 492 passed.ruff check .is clean,mypyis clean on its 9 gated files, andci_checks.py --allis ok.New section
check_proxy_traffic_savers. It runs in the core-only job too, with each engine loaded against fake driver modules. It checks:CONNECT www.farfetch.com:443, the message namesFARFETCH_PROXY, the secret never appears in stdout, stderr or the logs, the sidecar reads failed/proxy_auth_failed, and the output directory holds only the attempt sidecar;--cdp-endpoint: no pre-check;failRequest, Selenium's blocked URL list andmedia_blocked;--helpshows--load-mediabut not--force-block-media.Real CLI against the stub proxy (
--proxy http://user:…@127.0.0.1:<stub>): rc=5 for both 407 and 402 on all three engines. The stub saw one CONNECT each time, and the secret did not leak.Each engine's real
main()was run against a local stub page holding png/jpg/woff2/mp4/js:--force-block-media/and/app.js/favicon.ico/,/app.jsand/favicon.ico/favicon.ico/and/app.jsLive comparison, 2026-10-20, no proxy:
playwright_scraper.py --url …/shopping/women/dresses-1/items.aspx --pages 1, plain and with--force-block-media. Both runs got Akamai's 403Access Denied(329 bytes, exit 3) from this datacentre address, so values could not be compared. From reading the code: listingimage_urlcomes from JSON-LDimageor the<img>src/data-srcattribute, and detail images come from JSON-LD. No extraction reads image bytes or load state.Planted-fault controls, each restored and then green again:
precheck_proxyin Playwright turns 13pre-check (playwright)checks red. Doing the same in Selenium turns 15pre-check (selenium)checks red.playwright_media_routecontinue every request turnsmedia: playwright image/media/font -> abortred.selenium_block_media(driver)turns the twomedia: selenium … blocked by URLchecks and the source check red.await pyppeteer_block_media(page)turns the twomedia: pyppeteer … Fetch pauseschecks and the source check red.No paid calls, no proxy and no credentials were used.
Not changed
--load-media:env_config.ENV_KEYSmaps only credentials and URLs.page.authenticate) is unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8