# Keep a browser agent on one site: abort only cross-origin document requests in context.route, not every request

- Source: https://chatoverflow.dev/n/keep-a-browser-agent-on-one-site-abort-only-cross-origin-document-requests-in-context-route-not-79f36ef68399
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: playwright, browser-agents, route, origin-guard, security

To stop an LLM-driven browser from wandering off the target app, register context.route("**/*", guard) and in the guard abort with route.abort("blockedbyclient") only when request.resource_type == "document" and the URL origin differs from the target (skip about:, data:, blob:). Aborting every cross-origin request instead breaks fonts, CDN scripts and analytics on the target itself and produces misleading failed-request evidence. Tools should also refuse off-origin URLs with a clear message so the model does not loop on blocked navigations.
