agentcore-browser-web-scraping
Skill51 starsChanged 3 months agoApache-2.0View on GitHub
Build production web scraping on Bedrock AgentCore Browser — connect Playwright over signed CDP WebSocket, drive extraction with an LLM agent over fixed tool primitives (navigate, scroll, extract-by-selector, screenshot), reuse login state via Browser Profiles with a DCV live-view login flow, detect login walls without false positives, and route through an external proxy. Use when scraping dynamic or login-gated sites (X/Twitter, Reddit, Instagram, YouTube, forums) with AgentCore Browser, when scraped results come back empty on lazy-loaded pages, when Google SSO fails silently in the cloud browser, or when a target site blocks AWS egress IPs.
In this repository16 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agentcore-mcp-oauth-facadeSkill
- agentic-responsible-ai-assessmentSkill
- api-gateway-authorizer-securitySkill
- aws-agentic-aiSkill
- aws-cdk-developmentSkill
- aws-cost-operationsSkill
- aws-mcp-setupSkill
- cost-estimatorSkill
- create-install-scriptsSkill
- end-to-end-testingSkill
- gitlab-docs-publishingSkill
- quip-to-gitlab-wikiSkill
- security-scanSkill
- strands-context-managerSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 112
Timestamp resilience: if your sink requires non-null timestamps (Iceberg/Parquet), a single null can poison an entire batch *silently*.
- Distinctive: line 130
Run sync Playwright in a dedicated worker thread if your host framework owns an asyncio loop.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AgentCore Browser Web Scraping
Amazon Bedrock AgentCore Browser gives you a managed cloud Chromium — no crawler fleet, no resident containers, per-session billing, natural isolation. This skill captures a production scraping architecture built on it: an LLM agent decides what to do on the page, but only through fixed code primitives it can parameterize, never arbitrary scripts. Login state lives in Browser Profiles that users populate once through a live-view session, so credentials never transit the conversation.
Collector (Python, worker thread)
├─ browser_session(region, profile_configuration=..., proxy_configuration=...)
│ └─ StartBrowserSession → generate_ws_headers() (SigV4)
│ └─ playwright chromium.connect_over_cdp(ws_url, headers)
└─ Strands Agent (LLM) with 6 fixed tools:
navigate / scroll_to_bottom / click_load_more /
get_page_text / screenshot / extract_by_selectorWhen to Apply
Reference this skill when:
- Scraping dynamic, JS-rendered, or lazy-loading pages (social feeds, forums, review sites) with AgentCore Browser + Playwright.
- Scraping sites that require login (X/Twitter, Reddit, Instagram) and you need reusable login state that never leaves AWS.
- Scrapes return 0 items on pages that clearly have content — usually a scroll-container or login-wall misdiagnosis, both covered here.
- Google SSO inside the cloud browser silently fails (third-party cookies).
- The target site blocks AWS egress IPs and you need an external proxy.
Not for: general AgentCore Browser service overview or session APIs —
see the aws-agentic-ai skill's Browser service docs for that.
How It Works
1. Session, connection, and the LLM-driven extraction loop
Connect Playwright to the managed browser over a SigV4-signed CDP WebSocket, then let an LLM agent drive a bounded tool loop. Key decisions:
- LLM decides, code executes. A hand-written script per site doesn't scale across arbitrary DOMs; raw LLM-generated JS is an injection surface. The middle path: six fixed tools, the model only supplies parameters.
extract_by_selector: a constant JS extraction template evaluated with the model's CSS selectors passed as data arguments — zero string concatenation, zero eval. Preserves item boundaries and attributes that a flatinnerTextdump loses.screenshot(downscaled JPEG returned as an image tool-result) lets the model see the page and distinguish "genuinely empty" from login wall / CAPTCHA / cookie banner before declaring failure.- Adaptive step budget: scale the agent's max tool-steps (and the session timeout) with the requested record count — lazy feeds yield 10–20 items per scroll, so a fixed small budget silently under-collects.
- Scrolling that actually works:
document.body.scrollHeightis 0 on flex layouts (YouTube) — scrolldocument.scrollingElementinstead, and also iterate inner overflow panels; comments often live in an overlay that window scrolling never touches. - SSRF guard: HTTPS-only, no IP literals, private ranges and IMDS
blocked for the hostname and every resolved IP — re-validated inside the
navigatetool on every call, so the model can't pivot mid-session.
See references/session-and-extraction.md
— includes IAM specifics (the browser/ vs browser-custom/ ARN pitfall,
InvokeModelWithResponseStream), the asyncio × sync-Playwright worker-thread
requirement, and the error-code taxonomy.
2. Login state: Browser Profiles + live-view login
Users log in once inside the cloud browser via a DCV live-view page; the
session's cookies/tokens are saved to an AgentCore Browser Profile and reused
by every later scrape (profile_configuration={"profileIdentifier": ...}).
Credentials never appear in the conversation or your database.
Flow: mint a one-time URL token → start_browser_session with the profile →
presign the live-view stream endpoint (SigV4 query auth) → embed the DCV
Web Client → on completion save_browser_session_profile then
stop_browser_session (that order — save requires a live session).
The subtle part is login-wall detection without false positives. Hitting a wall does not mean the stored login is dead (a login can stay valid across days and multiple egress IPs while an overlay still blocks anonymous views). Use three layers: a pre-flight gate for known login-walled hosts, an in-scrape sentinel from the model, and an active probe that replays the session's cookies against a login-sensitive endpoint to ask the server directly — only a definitive INVALID expires the stored profile.
See references/login-profiles-and-liveview.md
— includes profile-name constraints and idempotent creation, DCV embed
gotchas (WebCodecs, absolute baseUrl), the Google SSO third-party-cookie
fix via Chromium enterprisePolicies, and the parked-task auto-resume
pattern.
3. Proxy egress and data normalization
- External proxy: sites that score egress-IP reputation block AWS ranges
wholesale.
start_browser_sessionaccepts aproxyConfigurationwith anexternalProxy(server, port, credentials by Secrets Manager ARN only — never inline). Fall back gracefully to the default egress when unconfigured. - Timestamp resilience: if your sink requires non-null timestamps
(Iceberg/Parquet), a single null can poison an entire batch silently.
Parse ISO → parse relative phrases ("3 hours ago") → fall back to
collection time tagged
time_confidence="unknown". Never drop, never null. - Stable message IDs + cross-run dedup: content-hash IDs with explicit field separators, native platform IDs folded in when available; periodic scrapes dedup against an already-seen ledger before paying for enrichment, degrading open on ledger errors.
See references/proxy-and-data-normalization.md.
Usage
Adoption checklist:
- Pin SDK versions:
bedrock-agentcoreand a boto3 recent enough to knowprofileConfiguration/ thebedrock-agentcoreservice (Lambda's bundled boto3 is too old — bundle your own). - Run sync Playwright in a dedicated worker thread if your host framework owns an asyncio loop.
- Grant both
bedrock:InvokeModelandInvokeModelWithResponseStreamto the agent's model, and write Browser session ARNs in bothbrowser/andbrowser-custom/forms. - Constrain the model's final output to a strict contract (JSON array,
[], or typed sentinels likeLOGIN_NEEDED: <host>/BLOCKED: <reason>) and parse defensively. - Derive hostnames for profile lookups server-side from the source URL, never from model output.
- Apply the same
enterprisePoliciesto login sessions and scrape sessions — SSO cookies saved under one policy break under another.
References
- Session, connection, and LLM extraction loop
- Login profiles, live-view login, wall detection
- Proxy egress and data normalization
- Amazon Bedrock AgentCore Browser
- AgentCore samples — browser with proxy
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

