Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Add exmamples on how to prohibit domain
Chris Schnabl63d9b5774428
diff --git a/docs/customize/browser/all-parameters.mdx b/docs/customize/browser/all-parameters.mdxindex db87f4f21..91af17a83 100644--- a/docs/customize/browser/all-parameters.mdx+++ b/docs/customize/browser/all-parameters.mdx@@ -32,6 +32,9 @@ The `Browser` instance also provides all [Actor](/customize/actor/all-parameters- `'chrome-extension://*'` - Matches any Chrome extension URL- **Security**: Wildcards in TLD (e.g., `example.*`) are **not allowed** for security- Use list like `['*.google.com', 'https://example.com', 'chrome-extension://*']`+- `prohibited_domains`: Block navigation to specific domains. Uses same pattern formats as `allowed_domains`. When both `allowed_domains` and `prohibited_domains` are set, `allowed_domains` takes precedence. Examples:+ - `['pornhub.com', '*.gambling-site.net']` - Block specific sites and all subdomains+ - `['https://explicit-contnt.org']` - Block specific protocol/domain combination- `enable_default_extensions` (default: `True`): Load automation extensions (uBlock Origin, cookie handlers, ClearURLs)- `cross_origin_iframes` (default: `False`): Enable cross-origin iframe support (may cause complexity)- `is_local` (default: `True`): Whether this is a local browser instance. Set to `False` for remote browsers. If we have a `executable_path` set, it will be automatically set to `True`. This can effect your download behavior.diff --git a/examples/features/blocked_domains.py b/examples/features/blocked_domains.pynew file mode 100644index 000000000..3de5e3046--- /dev/null+++ b/examples/features/blocked_domains.py@@ -0,0 +1,58 @@+import asyncio+import os+import sys++sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))++from dotenv import load_dotenv++load_dotenv()++from browser_use import Agent, ChatOpenAI+from browser_use.browser import BrowserProfile, BrowserSession++llm = ChatOpenAI(model='gpt-4o-mini')++# Example task: Try to navigate to various sites including blocked ones+task = 'Navigate to example.com, then try to go to x.com, then facebook.com, and finally visit google.com. Tell me which sites you were able to access.'++prohibited_domains = [+ 'x.com', # Block X (formerly Twitter) - "locked the f in"+ 'twitter.com', # Block Twitter (redirects to x.com anyway)+ 'facebook.com', # Lock the F in Facebook too+ '*.meta.com', # Block all Meta properties+ '*.adult-site.com', # Block all subdomains of adult sites+ 'https://explicit-content.org', # Block specific protocol/domain+ 'gambling-site.net', # Block gambling sites+]++browser_session = BrowserSession(+ browser_profile=BrowserProfile(+ prohibited_domains=prohibited_domains,+ headless=False, # Set to True to run without visible browser+ user_data_dir='~/.config/browseruse/profiles/blocked-demo',+ ),+)++agent = Agent(+ task=task,+ llm=llm,+ browser_session=browser_session,+)+++async def main():+ print('Demo: Blocked Domains Feature - "Lock the F in" Edition')+ print('We\'re literally locking the F in Facebook and X!')+ print(f'Prohibited domains: {prohibited_domains}')+ print('The agent will try to visit various sites, but blocked domains will be prevented.')+ print()++ await agent.run(max_steps=10)++ input('Press Enter to close the browser...')+ await browser_session.kill()+++if __name__ == '__main__':+ asyncio.run(main())