Repository navigation
Count proxy traffic per run and stop at --proxy-budget-mb (default 10 MB) - #7
Merged
Merged
Conversation
… MB) A local browser run through --proxy / --proxy-file now counts the bytes it sends through the proxy (Playwright: request.sizes(); Puppeteer and Selenium: CDP Network.loadingFinished.encodedDataLength plus request sizes; Selenium turns Chrome's performance log on for this behind a proxy). Once the total passes --proxy-budget-mb no further URL or post is fetched, the browser aborts what it still tries, the rows read so far are kept, and the run exits 6 (5 with no rows) with stop_reason proxy_budget_exceeded. The sidecar records proxy_bytes, proxy_budget_bytes and proxy_budget_exceeded, and the run ends with one "Proxy traffic: X.X MB of Y MB budget" line. Nothing is metered over --cdp-endpoint, --scraper-api or with no proxy. The canary passes --proxy-budget-mb 10, writes its traffic to the job summary and fails when the budget was hit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8
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 residential proxy is billed per byte, and nothing measured or limited what a run sent through it. A run that loops, or a page that grew, could spend a lot before anyone looked.
Resulting behaviour
Only for a local browser behind
--proxy/--proxy-file/INSTAGRAM_PROXY. Nothing changes over--cdp-endpoint, with--scraper-api, or with no proxy.proxy_meter.py), an estimate of the tunnelled payload. TLS/CONNECToverhead, WebSocket frames and Chrome's own background requests are not included.request.sizes()(request headers + body, response headers + body) onrequestfinished/requestfailed.Network.loadingFinished.encodedDataLengthfor responses that came over the network, plus the request line, headers and post body fromNetwork.requestWillBeSent. Chrome's own error page (about 250 KB, reported as a finished load of the failed URL) and cache hits are not counted.HEADis counted too.--proxy-budget-mb(default 10, 0 = unlimited; a negative or non-number value is exit 2). It is a flag only, becauseENV_KEYSmaps only credentials and URLs. Once the total passes the budget:--postspost) is fetched;fallback()). Puppeteer and Selenium setNetwork.setBlockedURLs ["*"];stop_reason: proxy_budget_exceeded: exit 6 with rows, 5 without.finish_runputs this above blocked or failed-page outcomes.proxy_bytes,proxy_budget_bytes,proxy_budget_exceeded. These arenull/null/falsewithout a local proxy.<out>.latest_attempt.meta.json. The data and.meta.jsonare left as they were.Proxy traffic: X.X MB of Y MB budget.--proxy-budget-mb 10. An always-run step,.github/proxy_traffic_summary.py, appends**canary**: proxy traffic X.X MB of 10 MBto$GITHUB_STEP_SUMMARY. When the budget was hit, it prints::error::stopped: proxy budget 10 MB exceededand fails. A missing sidecar, an unreadable sidecar or a run without a proxy is reported and does not fail.Evidence (offline; no proxy, no paid call, no canary dispatched)
tests/test_proxy_meter.py(the same file as facebook-ads-scraper Proxy meter: stop counting chrome:// and other local loads in Selenium and Puppeteer #8) runs a stub forward proxy that serves a page of known size (about 152 KB) and counts the bytes crossing its sockets. Meter against the proxy's count:PROXY_METER_REQUIRE=<engine>, so a missing browser fails instead of skipping.--url natgeo) through the stub proxy (CONNECT answered 403, so instagram.com was never reached): rc 5 for playwright, selenium and pyppeteer,Proxy traffic: 0.0 MB of 10 MB budget, and an attempt sidecar withproxy_bytes489 / 846 / 282. Selenium's figure shows that the performance log it now enables is read.unittest discover: OK in each, with that engine's real-browser test run, not skipped.not_attempted, sidecar(1200, 1000, True);Not changed
No version bump or release, and no canary dispatch. The proxy is never used without the user's flag or env. Chrome's background traffic is not suppressed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8