Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: add headless browser search toolkit & enhance browser stealth (#3895)

Puzhen Zhang8d765465425e
diff --git a/camel/toolkits/__init__.py b/camel/toolkits/__init__.py
index fa1bbe5d4..4ede3aae4 100644
--- a/camel/toolkits/__init__.py
+++ b/camel/toolkits/__init__.py
@@ -102,6 +102,7 @@ from .imap_mail_toolkit import IMAPMailToolkit
from .microsoft_outlook_mail_toolkit import OutlookMailToolkit
from .earth_science_toolkit import EarthScienceToolkit
from .skill_toolkit import SkillToolkit
+from .headless_browser_search_toolkit import HeadlessBrowserSearchToolkit
__all__ = [
'BaseToolkit',
@@ -195,4 +196,5 @@ __all__ = [
"OutlookMailToolkit",
'EarthScienceToolkit',
'SkillToolkit',
+ 'HeadlessBrowserSearchToolkit',
]
diff --git a/camel/toolkits/headless_browser_search_toolkit.py b/camel/toolkits/headless_browser_search_toolkit.py
new file mode 100644
index 000000000..9716244b5
--- /dev/null
+++ b/camel/toolkits/headless_browser_search_toolkit.py
@@ -0,0 +1,540 @@
+# ========= Copyright 2023-2026 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2026 @ CAMEL-AI.org. All Rights Reserved. =========
+
+import json
+import re
+import urllib.parse
+from dataclasses import dataclass, field
+from typing import Any, Dict, List, Literal
+
+from camel.logger import get_logger
+from camel.toolkits.base import BaseToolkit
+from camel.toolkits.function_tool import FunctionTool
+
+logger = get_logger(__name__)
+
+EngineType = Literal["google", "bing", "brave"]
+
+
+@dataclass
+class SearchResult:
+ r"""A single search result.
+
+ Attributes:
+ title (str): The title of the search result.
+ url (str): The URL of the search result.
+ snippet (str): A short text snippet from the result.
+ """
+
+ title: str
+ url: str
+ snippet: str
+
+ def to_dict(self) -> Dict[str, str]:
+ return {
+ "title": self.title,
+ "url": self.url,
+ "snippet": self.snippet,
+ }
+
+
+@dataclass
+class SearchResponse:
+ r"""Response from a search query.
+
+ Attributes:
+ query (str): The original search query.
+ engine (str): The search engine used.
+ page (int): The page number of this response.
+ results (List[SearchResult]): Extracted structured results.
+ raw_snapshot (str): Raw page snapshot when JS extraction
+ fails or page is blocked.
+ """
+
+ query: str
+ engine: str
+ page: int
+ results: List[SearchResult] = field(default_factory=list)
+ raw_snapshot: str = ""
+
+ def to_dict(self) -> Dict:
+ d: Dict = {
+ "query": self.query,
+ "engine": self.engine,
+ "page": self.page,
+ "total_results": len(self.results),
+ "results": [r.to_dict() for r in self.results],
+ }
+ if self.raw_snapshot:
+ d["raw_snapshot"] = self.raw_snapshot
+ return d
+
+
+def _parse_console_result(raw: str) -> str:
+ """Strip the 'Console execution result: ' prefix and unquote."""
+ prefix = "Console execution result: "
+ if raw.startswith(prefix):
+ raw = raw[len(prefix) :]
+ if raw.startswith('"') and raw.endswith('"'):
+ try:
+ return json.loads(raw)
+ except (json.JSONDecodeError, ValueError):
+ pass
+ return raw
+
+
+def _parse_json_from_response(raw: str) -> list:
+ """Parse JSON array from a console exec response string."""
+ cleaned = _parse_console_result(raw)
+ try:
+ return json.loads(cleaned)
+ except (json.JSONDecodeError, TypeError):
+ pass
+ match = re.search(r'\[.*\]', cleaned, re.DOTALL)
+ if match:
+ try:
+ return json.loads(match.group())
+ except (json.JSONDecodeError, TypeError):
+ pass
+ return []
+
+
+# ---------------------------------------------------------------------------
+# ES5-compatible extraction JS for each engine.
+# We avoid const/let/arrow/template-literals because
+# browser_console_exec wraps code in a way that can choke on them.
+# ---------------------------------------------------------------------------
+
+_GOOGLE_JS = """
+(function() {
+ var results = [];
+ var seen = {};
+ var items = document.querySelectorAll('#search .g, #rso .g');
+ for (var i = 0; i < items.length; i++) {
+ var item = items[i];
+ var linkEl = item.querySelector('a[href]');
+ var titleEl = item.querySelector('h3');
+ var snippetEl = item.querySelector(
+ '[data-sncf], .VwiC3b, .IsZvec, .lEBKkf span, .st'
+ );
+ if (linkEl && titleEl) {
+ var url = linkEl.href;
+ if (url && url.indexOf('google.com/search') === -1 &&
+ url.indexOf('accounts.google') === -1 &&
+ url.indexOf('javascript:') !== 0 && !seen[url]) {
+ seen[url] = true;
+ results.push({
+ title: titleEl.innerText.trim(),
+ url: url,
+ snippet: snippetEl
+ ? snippetEl.innerText.trim() : ''
+ });
+ }
+ }
+ }
+ return JSON.stringify(results);
+})()
+"""
+
+_BING_JS = """
+(function() {
+ var results = [];
+ var items = document.querySelectorAll(
+ '#b_results > li.b_algo'
+ );
+ for (var i = 0; i < items.length; i++) {
+ var item = items[i];
+ var linkEl = item.querySelector('h2 a')
+ || item.querySelector('h3 a');
+ if (!linkEl) continue;
+ var title = linkEl.innerText.trim();
+ var url = linkEl.href;
+ try {
+ var u = new URL(url);
+ if (u.hostname.indexOf('bing.com') !== -1
+ && u.pathname === '/ck/a') {
+ var uParam = u.searchParams.get('u');
+ if (uParam
+ && uParam.indexOf('a1') === 0) {
+ url = decodeURIComponent(
+ atob(uParam.substring(2))
+ );
+ }
+ }
+ } catch(e) {}
+ if (url.indexOf('bing.com/ck/a') !== -1) {
+ var citeEl = item.querySelector('cite');
+ if (citeEl) {
+ var citeUrl = citeEl.innerText.trim();
+ if (citeUrl.indexOf('http') !== 0)
+ citeUrl = 'https://' + citeUrl;
+ url = citeUrl;
+ }
+ }
+ var snippetEl = item.querySelector(
+ '.b_caption p, .b_lineclamp2, .b_paractl'
+ );
+ var snippet = snippetEl
+ ? snippetEl.innerText.trim() : '';
+ if (title && url) {
+ results.push({
+ title: title, url: url, snippet: snippet
+ });
+ }
+ }
+ return JSON.stringify(results);
+})()
+"""
+
+_BRAVE_JS = """
+(function() {
+ var results = [];
+ var seen = {};
+ var items = document.querySelectorAll(
+ '[data-type="web"]'
+ );
+ for (var i = 0; i < items.length; i++) {
+ var item = items[i];
+ var url = '';
+ var titleEl = item.querySelector('.title a');
+ if (!titleEl) {
+ var links = item.querySelectorAll('a[href]');
+ for (var j = 0; j < links.length; j++) {
+ var a = links[j];
+ var h = a.href || '';
+ if (h.indexOf('search.brave.com') === -1
+ && h.indexOf('javascript:') !== 0
+ && h.indexOf('http') === 0) {
+ titleEl = a;
+ break;
+ }
+ }
+ }
+ if (!titleEl) continue;
+ url = titleEl.href;
+ if (!url || seen[url]) continue;
+ seen[url] = true;
+ var titleDiv = item.querySelector('.title');
+ var title = titleDiv
+ ? titleDiv.innerText.trim()
+ : titleEl.innerText.trim()
+ .split('\\n').pop().trim();
+ var snippetEl = item.querySelector(
+ '.generic-snippet, '
+ + '.snippet-description, '
+ + '.snippet-content'
+ );
+ var snippet = snippetEl
+ ? snippetEl.innerText.trim() : '';
+ if (title && url) {
+ results.push({
+ title: title, url: url, snippet: snippet
+ });
+ }
+ }
+ return JSON.stringify(results);
+})()
+"""
+
+_BLOCK_DETECT_JS = """
+(function() {
+ var body = document.body
+ ? document.body.innerText : '';
+ var url = window.location.href;
+ return JSON.stringify({
+ url: url,
+ title: document.title,
+ hasCaptcha: !!(document.querySelector(
+ '#captcha-form, '
+ + '.g-recaptcha, '
+ + 'iframe[src*="recaptcha"]'
+ )),
+ hasConsent: !!(document.querySelector(
+ 'form[action*="consent"]'
+ )),
+ isSorryPage:
+ url.indexOf('/sorry/') !== -1 ||
+ body.indexOf('unusual traffic') !== -1,
+ bodyLength: body.length
+ });
+})()
+"""
+
+_ENGINE_JS = {
+ "google": _GOOGLE_JS,
+ "bing": _BING_JS,
+ "brave": _BRAVE_JS,
+}
+
+
+class HeadlessBrowserSearchToolkit(BaseToolkit):
+ r"""Headless browser search toolkit using HybridBrowserToolkit.
+
+ Performs web searches via a stealth headless browser, supporting
+ Google, Bing, and Brave search engines. Automatically constructs
+ search URLs, navigates pages, and extracts structured results.
+
+ Args:
+ headless (bool): Run browser in headless mode.
+ (default: :obj:`True`)
+ stealth (bool): Enable anti-fingerprint stealth mode.
+ (default: :obj:`True`)
+ lang (str): Language hint for search results.
+ (default: :obj:`"en"`)
+
+ Example:
+ >>> from camel.toolkits import (
+ ... HeadlessBrowserSearchToolkit,
+ ... )
+ >>> toolkit = HeadlessBrowserSearchToolkit()
+ >>> tools = toolkit.get_tools()
+ """
+
+ def __init__(
+ self,
+ headless: bool = True,
+ stealth: bool = True,
+ lang: str = "en",
+ ):
+ super().__init__()
+ self.lang = lang
+ self._toolkit: Any = None
+ self._headless = headless
+ self._stealth = stealth
+ self._browser_opened = False
+
+ async def _ensure_browser(self) -> Any:
+ r"""Initialize the browser toolkit if not already done."""
+ if self._toolkit is None:
+ from camel.toolkits.hybrid_browser_toolkit import (
+ HybridBrowserToolkit,
+ )
+
+ self._toolkit = HybridBrowserToolkit(
+ headless=self._headless,
+ stealth=self._stealth,
+ enabled_tools=[
+ "browser_open",
+ "browser_close",
+ "browser_visit_page",
+ "browser_get_page_snapshot",
+ "browser_console_exec",
+ ],
+ )
+ if not self._browser_opened:
+ await self._toolkit.browser_open()
+ self._browser_opened = True
+ return self._toolkit
+
+ async def close(self) -> None:
+ r"""Close the browser and release resources."""
+ if self._toolkit and self._browser_opened:
+ await self._toolkit.browser_close()
+ self._browser_opened = False
+
+ def _build_search_url(
+ self, query: str, engine: str, page_idx: int = 0
+ ) -> str:
+ r"""Build search URL for the given query and page.
+
+ Args:
+ query (str): The search query.
+ engine (str): Search engine name.
+ page_idx (int): Zero-based page index.
+ (default: :obj:`0`)
+
+ Returns:
+ str: The full search URL.
+ """
+ q = urllib.parse.quote_plus(query)
+ if engine == "google":
+ return (
+ f"https://www.google.com/search?q={q}"
+ f"&start={page_idx * 10}&hl={self.lang}"
+ )
+ elif engine == "bing":
+ return (
+ f"https://www.bing.com/search?q={q}"
+ f"&first={page_idx * 10 + 1}"
+ )
+ else: # brave
+ return (
+ f"https://search.brave.com/search?q={q}"
+ f"&source=web&offset={page_idx}"
+ )
+
+ async def _check_blocked(self, toolkit: Any) -> dict:
+ r"""Check if the current page is a captcha/block page.
+
+ Args:
+ toolkit: The browser toolkit instance.
+
+ Returns:
+ dict: Block detection info with keys like
+ ``hasCaptcha``, ``isSorryPage``, etc.
+ """
+ resp = await toolkit.browser_console_exec(_BLOCK_DETECT_JS)
+ raw = resp.get("result", "")
+ cleaned = _parse_console_result(raw)
+ try:
+ return json.loads(cleaned)
+ except (json.JSONDecodeError, TypeError):
+ return {}
+
+ async def _extract_results(
+ self, toolkit: Any, engine: str
+ ) -> List[SearchResult]:
+ r"""Extract search results from current page via JS.
+
+ Args:
+ toolkit: The browser toolkit instance.
+ engine (str): Search engine name.
+
+ Returns:
+ List[SearchResult]: Extracted search results.
+ """
+ js_code = _ENGINE_JS[engine]
+ resp = await toolkit.browser_console_exec(js_code)
+ raw = resp.get("result", "")
+
+ try:
+ items = _parse_json_from_response(raw)
+ return [
+ SearchResult(
+ title=item.get("title", ""),
+ url=item.get("url", ""),
+ snippet=item.get("snippet", ""),
+ )
+ for item in items
+ if item.get("url")
+ ]
+ except Exception as e:
+ logger.warning(f"JS extraction failed: {e}, " f"raw={raw[:300]}")
+ return []
+
+ async def search(
+ self,
+ query: str,
+ engine: EngineType = "brave",
+ page: int = 1,
+ ) -> str:
+ r"""Perform a web search and return structured results.
+
+ Uses a stealth headless browser to search the specified
+ engine, extract structured results (title, URL, snippet),
+ and return them as a JSON string. The browser is
+ automatically closed after each search.
+
+ Args:
+ query (str): The search query string.
+ engine (str): Search engine to use. Options:
+ ``"brave"``, ``"bing"``, ``"google"``.
+ (default: :obj:`"brave"`)
+ page (int): Which result page to return (1-based).
+ For example, ``page=3`` fetches page 3.
+ (default: :obj:`1`)
+
+ Returns:
+ str: JSON string containing the page result with
+ ``query``, ``engine``, ``page``,
+ ``total_results``, ``results``, and optionally
+ ``raw_snapshot`` fields.
+ """
+ if engine not in _ENGINE_JS:
+ return json.dumps(
+ {
+ "error": f"Unsupported engine: {engine!r}."
+ f" Choose from: {list(_ENGINE_JS.keys())}"
+ }
+ )
+
+ page_idx = max(page - 1, 0)
+ try:
+ toolkit = await self._ensure_browser()
+ url = self._build_search_url(query, engine, page_idx)
+ logger.info(f"[{engine}] Page {page}: {url}")
+
+ await toolkit.browser_visit_page(url)
+
+ # Check for blocks/captcha
+ block_info = await self._check_blocked(toolkit)
+ is_blocked = block_info.get("hasCaptcha") or block_info.get(
+ "isSorryPage"
+ )
+
+ if is_blocked:
+ logger.warning(
+ f"[{engine}] Page {page} BLOCKED: "
+ f"captcha="
+ f"{block_info.get('hasCaptcha')}, "
+ f"sorry="
+ f"{block_info.get('isSorryPage')}, "
+ f"url={block_info.get('url', '')}"
+ )
+ snapshot = await toolkit.browser_get_page_snapshot()
+ return json.dumps(
+ SearchResponse(
+ query=query,
+ engine=engine,
+ page=page,
+ results=[],
+ raw_snapshot=snapshot,
+ ).to_dict(),
+ ensure_ascii=False,
+ indent=2,
+ )
+
+ results = await self._extract_results(toolkit, engine)
+
+ # Fallback: snapshot if JS got nothing
+ snapshot = ""
+ if not results:
+ logger.info(
+ f"[{engine}] Page {page}: "
+ f"JS extraction empty, "
+ f"falling back to snapshot"
+ )
+ snapshot = await toolkit.browser_get_page_snapshot()
+
+ page_response = SearchResponse(
+ query=query,
+ engine=engine,
+ page=page,
+ results=results,
+ raw_snapshot=snapshot,
+ )
+ logger.info(
+ f"[{engine}] Page {page}: "
+ f"{len(results)} results"
+ + (f" (snapshot: {len(snapshot)} chars)" if snapshot else "")
+ )
+
+ return json.dumps(
+ page_response.to_dict(),
+ ensure_ascii=False,
+ indent=2,
+ )
+ finally:
+ await self.close()
+
+ def get_tools(self) -> List[FunctionTool]:
+ r"""Returns a list of FunctionTool objects representing
+ the functions in the toolkit.
+
+ Returns:
+ List[FunctionTool]: A list of FunctionTool objects.
+ """
+ return [
+ FunctionTool(self.search),
+ ]
diff --git a/camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts b/camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts
index d98b0921d..656353978 100644
--- a/camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts
+++ b/camel/toolkits/hybrid_browser_toolkit/ts/src/browser-session.ts
@@ -441,6 +441,13 @@ export class HybridBrowserSession {
}
}
+ // Inject stealth init scripts into context (runs before every page load)
+ if (stealthConfig.enabled && stealthConfig.initScripts) {
+ for (const script of stealthConfig.initScripts) {
+ await this.context!.addInitScript(script);
+ }
+ }
+
// Set timeouts
for (const page of this.pages.values()) {
page.setDefaultNavigationTimeout(browserConfig.navigationTimeout);
diff --git a/camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts b/camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts
index 4d0fc30c0..0d16d65c2 100644
--- a/camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts
+++ b/camel/toolkits/hybrid_browser_toolkit/ts/src/config-loader.ts
@@ -3,6 +3,7 @@ export interface StealthConfig {
args?: string[];
userAgent?: string;
extraHTTPHeaders?: Record<string, string>;
+ initScripts?: string[]; // JS scripts to inject before any page loads
}
export interface BrowserConfig {
@@ -104,7 +105,236 @@ function getDefaultStealthConfig(): StealthConfig {
'--disable-setuid-sandbox',
],
userAgent: undefined,
- extraHTTPHeaders: {}
+ extraHTTPHeaders: {},
+ initScripts: []
+ };
+}
+
+// Enhanced stealth configuration that patches common fingerprint leaks
+function getEnhancedStealthConfig(): StealthConfig {
+ // Platform-aware Chrome UA (no "HeadlessChrome")
+ const platform = process.platform;
+ let uaPlatform: string;
+ let clientHintPlatform: string;
+ let webglVendor: string;
+ let webglRenderer: string;
+ if (platform === 'win32') {
+ uaPlatform = 'Windows NT 10.0; Win64; x64';
+ clientHintPlatform = 'Windows';
+ webglVendor = 'Google Inc. (NVIDIA)';
+ webglRenderer = 'ANGLE (NVIDIA, NVIDIA GeForce GTX 1650, OpenGL 4.5)';
+ } else if (platform === 'linux') {
+ uaPlatform = 'X11; Linux x86_64';
+ clientHintPlatform = 'Linux';
+ webglVendor = 'Google Inc. (Mesa)';
+ webglRenderer = 'ANGLE (Mesa, llvmpipe, OpenGL 4.5)';
+ } else {
+ // macOS / darwin
+ uaPlatform = 'Macintosh; Intel Mac OS X 10_15_7';
+ clientHintPlatform = 'macOS';
+ webglVendor = 'Google Inc. (Apple)';
+ webglRenderer = 'ANGLE (Apple, Apple M1 Pro, OpenGL 4.1)';
+ }
+ const realUserAgent = `Mozilla/5.0 (${uaPlatform}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36`;
+
+ const stealthInitScript = `
+ // === Stealth Init Script (platform: ${platform}) ===
+
+ // 1. Override navigator.webdriver
+ Object.defineProperty(navigator, 'webdriver', {
+ get: () => undefined,
+ configurable: true
+ });
+
+ // 2. Fake plugins array (Chrome typically has 5 default plugins)
+ Object.defineProperty(navigator, 'plugins', {
+ get: () => {
+ const pluginData = [
+ { name: 'Chrome PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
+ { name: 'Chrome PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' },
+ { name: 'Chromium PDF Plugin', filename: 'internal-pdf-viewer', description: 'Portable Document Format' },
+ { name: 'Chromium PDF Viewer', filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai', description: '' },
+ { name: 'Native Client', filename: 'internal-nacl-plugin', description: '' },
+ ];
+ const plugins = Object.create(PluginArray.prototype);
+ for (let i = 0; i < pluginData.length; i++) {
+ const p = Object.create(Plugin.prototype);
+ Object.defineProperties(p, {
+ name: { value: pluginData[i].name, enumerable: true },
+ filename: { value: pluginData[i].filename, enumerable: true },
+ description: { value: pluginData[i].description, enumerable: true },
+ length: { value: 0, enumerable: true },
+ });
+ Object.defineProperty(plugins, i, { value: p, enumerable: true });
+ }
+ Object.defineProperty(plugins, 'length', { value: pluginData.length, enumerable: true });
+ plugins.item = (index) => plugins[index] || null;
+ plugins.namedItem = (name) => Array.from({length: pluginData.length}, (_, i) => plugins[i]).find(p => p.name === name) || null;
+ plugins.refresh = () => {};
+ return plugins;
+ },
+ configurable: true
+ });
+
+ // 3. Fake window.chrome object
+ if (!window.chrome) {
+ window.chrome = {};
+ }
+ if (!window.chrome.runtime) {
+ window.chrome.runtime = {
+ connect: function() {},
+ sendMessage: function() {},
+ onMessage: { addListener: function() {}, removeListener: function() {} },
+ id: undefined
+ };
+ }
+ if (!window.chrome.loadTimes) {
+ window.chrome.loadTimes = function() {
+ return {
+ commitLoadTime: Date.now() / 1000,
+ connectionInfo: 'http/1.1',
+ finishDocumentLoadTime: Date.now() / 1000 + 0.1,
+ finishLoadTime: Date.now() / 1000 + 0.2,
+ firstPaintAfterLoadTime: 0,
+ firstPaintTime: Date.now() / 1000 + 0.05,
+ navigationType: 'Other',
+ npnNegotiatedProtocol: 'unknown',
+ requestTime: Date.now() / 1000 - 0.5,
+ startLoadTime: Date.now() / 1000 - 0.4,
+ wasAlternateProtocolAvailable: false,
+ wasFetchedViaSpdy: false,
+ wasNpnNegotiated: false,
+ };
+ };
+ }
+ if (!window.chrome.csi) {
+ window.chrome.csi = function() {
+ return {
+ onloadT: Date.now(),
+ startE: Date.now() - 500,
+ pageT: 500,
+ tran: 15,
+ };
+ };
+ }
+ if (!window.chrome.app) {
+ window.chrome.app = {
+ isInstalled: false,
+ InstallState: { DISABLED: 'disabled', INSTALLED: 'installed', NOT_INSTALLED: 'not_installed' },
+ RunningState: { CANNOT_RUN: 'cannot_run', READY_TO_RUN: 'ready_to_run', RUNNING: 'running' },
+ getDetails: function() { return null; },
+ getIsInstalled: function() { return false; },
+ };
+ }
+
+ // 4. Fix Permissions API (headless returns 'prompt' for notifications, real Chrome returns 'denied')
+ const originalQuery = window.navigator.permissions.query.bind(window.navigator.permissions);
+ window.navigator.permissions.query = (parameters) => {
+ if (parameters.name === 'notifications') {
+ return Promise.resolve({ state: Notification.permission, onchange: null });
+ }
+ return originalQuery(parameters);
+ };
+
+ // 5. Fake languages (add more variety)
+ Object.defineProperty(navigator, 'languages', {
+ get: () => ['en-US', 'en', 'zh-CN', 'zh'],
+ configurable: true
+ });
+
+ // 6. Fake MediaDevices
+ if (!navigator.mediaDevices) {
+ Object.defineProperty(navigator, 'mediaDevices', {
+ get: () => ({
+ enumerateDevices: () => Promise.resolve([
+ { deviceId: '', groupId: '', kind: 'audioinput', label: '' },
+ { deviceId: '', groupId: '', kind: 'videoinput', label: '' },
+ { deviceId: '', groupId: '', kind: 'audiooutput', label: '' },
+ ]),
+ getUserMedia: () => Promise.reject(new DOMException('Not allowed', 'NotAllowedError')),
+ getSupportedConstraints: () => ({
+ aspectRatio: true, autoGainControl: true, brightness: true,
+ channelCount: true, colorTemperature: true, contrast: true,
+ deviceId: true, echoCancellation: true, exposureCompensation: true,
+ exposureMode: true, facingMode: true, focusDistance: true,
+ focusMode: true, frameRate: true, groupId: true, height: true,
+ iso: true, latency: true, noiseSuppression: true, pan: true,
+ pointsOfInterest: true, resizeMode: true, sampleRate: true,
+ sampleSize: true, saturation: true, sharpness: true, tilt: true,
+ torch: true, whiteBalanceMode: true, width: true, zoom: true,
+ }),
+ }),
+ configurable: true
+ });
+ }
+
+ // 7. Override WebGL renderer to hide SwiftShader
+ const getParameterProto = WebGLRenderingContext.prototype.getParameter;
+ WebGLRenderingContext.prototype.getParameter = function(parameter) {
+ // UNMASKED_VENDOR_WEBGL
+ if (parameter === 0x9245) return '${webglVendor}';
+ // UNMASKED_RENDERER_WEBGL
+ if (parameter === 0x9246) return '${webglRenderer}';
+ return getParameterProto.call(this, parameter);
+ };
+ // Same for WebGL2
+ if (typeof WebGL2RenderingContext !== 'undefined') {
+ const getParameterProto2 = WebGL2RenderingContext.prototype.getParameter;
+ WebGL2RenderingContext.prototype.getParameter = function(parameter) {
+ if (parameter === 0x9245) return '${webglVendor}';
+ if (parameter === 0x9246) return '${webglRenderer}';
+ return getParameterProto2.call(this, parameter);
+ };
+ }
+
+ // 8. Fake deviceMemory
+ Object.defineProperty(navigator, 'deviceMemory', {
+ get: () => 8,
+ configurable: true
+ });
+
+ // 9. Fake hardwareConcurrency (if too low)
+ if (navigator.hardwareConcurrency < 4) {
+ Object.defineProperty(navigator, 'hardwareConcurrency', {
+ get: () => 8,
+ configurable: true
+ });
+ }
+
+ `;
+
+ return {
+ enabled: true,
+ args: [
+ '--disable-blink-features=AutomationControlled',
+ '--disable-dev-shm-usage',
+ '--disable-features=VizDisplayCompositor',
+ '--no-first-run',
+ '--no-default-browser-check',
+ '--no-sandbox',
+ '--disable-setuid-sandbox',
+ '--disable-infobars',
+ '--disable-background-timer-throttling',
+ '--disable-backgrounding-occluded-windows',
+ '--disable-renderer-backgrounding',
+ '--disable-component-update',
+ '--disable-hang-monitor',
+ '--disable-prompt-on-repost',
+ '--disable-sync',
+ '--metrics-recording-only',
+ '--disable-default-apps',
+ '--mute-audio',
+ '--disable-extensions',
+ '--lang=en-US,en',
+ ],
+ userAgent: realUserAgent,
+ extraHTTPHeaders: {
+ 'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
+ 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
+ 'sec-ch-ua-mobile': '?0',
+ 'sec-ch-ua-platform': `"${clientHintPlatform}"`,
+ },
+ initScripts: [stealthInitScript]
};
}
@@ -209,10 +439,12 @@ export class ConfigLoader {
if (config.stealth !== undefined) {
// Handle both boolean and object formats for backward compatibility
if (typeof config.stealth === 'boolean') {
- browserConfig.stealth = {
- enabled: config.stealth,
- args: getDefaultStealthConfig().args
- };
+ if (config.stealth) {
+ // Use enhanced stealth config with full anti-detection
+ browserConfig.stealth = getEnhancedStealthConfig();
+ } else {
+ browserConfig.stealth = getDefaultStealthConfig();
+ }
} else {
browserConfig.stealth = config.stealth;
}
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 6aebe0637..0c6c4798d 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -43,7 +43,7 @@ class ModelType(UnifiedModelType, Enum):
O1_PREVIEW = "o1-preview"
O1_MINI = "o1-mini"
O3_MINI = "o3-mini"
- GPT_4_1 = "gpt-4.1-2025-04-14"
+ GPT_4_1 = "gpt-4.1"
GPT_4_1_MINI = "gpt-4.1-mini-2025-04-14"
GPT_4_1_NANO = "gpt-4.1-nano-2025-04-14"
O4_MINI = "o4-mini"
diff --git a/examples/toolkits/headless_browser_search_toolkit_example.py b/examples/toolkits/headless_browser_search_toolkit_example.py
new file mode 100644
index 000000000..ffb37deb3
--- /dev/null
+++ b/examples/toolkits/headless_browser_search_toolkit_example.py
@@ -0,0 +1,80 @@
+# ========= Copyright 2023-2026 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2026 @ CAMEL-AI.org. All Rights Reserved. =========
+"""HeadlessBrowserSearchToolkit Example."""
+
+import asyncio
+import json
+
+from camel.toolkits.headless_browser_search_toolkit import (
+ HeadlessBrowserSearchToolkit,
+)
+
+
+async def example_basic_search():
+ """Search with all args: query, engine, page."""
+ toolkit = HeadlessBrowserSearchToolkit()
+ result_json = await toolkit.search(
+ query="large language model",
+ engine="brave",
+ page=1,
+ )
+ page = json.loads(result_json)
+ print(f"Results: {page['total_results']}")
+ for r in page["results"][:3]:
+ print(f" {r['title']}")
+ print(f" {r['url']}")
+
+
+async def example_agent_tools():
+ """Show FunctionTool schema for agent integration.
+
+ Expected output::
+
+ Tool: search
+ Params: ['query', 'engine', 'page']
+ Schema:
+ {
+ "type": "function",
+ "function": {
+ "name": "search",
+ "parameters": {
+ "properties": {
+ "query": {"type": "string", ...},
+ "engine": {"type": ["string", "null"], ...},
+ "page": {"type": ["integer", "null"], ...}
+ },
+ "required": ["query", "engine", "page"]
+ }
+ }
+ }
+ """
+ toolkit = HeadlessBrowserSearchToolkit()
+ tools = toolkit.get_tools()
+ for t in tools:
+ schema = t.get_openai_tool_schema()
+ func = schema["function"]
+ params = func["parameters"]
+ print(f"Tool: {func['name']}")
+ print(f"Params: {list(params['properties'])}")
+ print("Schema:")
+ print(json.dumps(schema, indent=2))
+
+
+async def main():
+ await example_basic_search()
+ # await example_agent_tools()
+
+
+if __name__ == "__main__":
+ asyncio.run(main())