050 — Browser Session Bypass Protocol¶
Status: ACCEPTED Date: 2026-07-04 Extends: 015-ingestion-mode-bypass-strategy.md, 037-adaptive-scraping-escalation-policy.md, 048-proxy-tier-in-adaptive-bypass-chain.md
Context¶
BypassStrategy already formalised two browser hooks:
apply_browser_args(...)apply_page(...)
That contract works for Playwright-backed tiers where browser_utils.open_page()
owns the browser lifecycle and the bypass only mutates launch/context/page
state.
The new camoufox and nodriver tiers do not fit that shape cleanly:
- They own a different browser runtime and need to open the page themselves.
- A raw
getattr(bypass, "open_page", None)check makes the contract implicit and invisible to architecture/docs. - Monitor/site-parser/browser helper code still needs one shared call site so that adaptive escalation stays uniform across scraping paths.
Decision¶
- Keep
BypassStrategyas the base HTTP/browser mutation protocol. - Add a dedicated protocol extension in
application/contracts.py:
@runtime_checkable
class BrowserSessionBypass(BypassStrategy, Protocol):
def open_page(
self,
config: dict[str, Any],
*,
use_proxy: bool = False,
) -> AsyncContextManager[Any]: ...
infrastructure/sources/browser_utils.py::open_page(...)becomes the single integration point:- if the active bypass implements
BrowserSessionBypass, delegate browser lifecycle to it; - otherwise keep the existing Playwright-owned path.
camoufoxandnodrivermust preserve the shared browser config semantics that sources already rely on where the backend supports them:headlesstimeoutviewport/window sizelocalecookiespersistent_contextuse_proxyskip_ssluser_agentwhen the backend can express it- Adaptive bypass remains registry-driven and browser-tier agnostic. Adding a
new browser engine must not require new
if/elifdispatch in core code.
Consequences¶
- (+) The browser-session escape hatch is explicit, typed, and documented.
- (+)
browser_utils.open_page(...)stays the only source-side browser entry point, so monitor/site-parser/detail scraping paths continue to share one adaptive bypass integration seam. - (+) New non-Playwright browser engines can plug in without smuggling hidden methods into the contract.
- (-) Browser-tier implementations now carry more compatibility burden because they must map the shared config semantics onto their own runtime.
- (-)
BrowserSessionBypassbroadens the contract surface and therefore needs dedicated tests for config propagation.