unclecode/crawl4ai · error · TypeError
Hook {hook_type} must return an instance of webdriver.Chrome
Error message
Hook {hook_type} must return an instance of webdriver.Chrome or None. What it means
Error "Hook {hook_type} must return an instance of webdriver.Chrome or None." thrown in unclecode/crawl4ai.
Source
Thrown at crawl4ai/legacy/crawler_strategy.py:175
if kwargs.get("cookies"):
for cookie in kwargs.get("cookies"):
self.driver.add_cookie(cookie)
def set_hook(self, hook_type: str, hook: Callable):
if hook_type in self.hooks:
self.hooks[hook_type] = hook
else:
raise ValueError(f"Invalid hook type: {hook_type}")
def execute_hook(self, hook_type: str, *args):
hook = self.hooks.get(hook_type)
if hook:
result = hook(*args)
if result is not None:
if isinstance(result, webdriver.Chrome):
return result
else:
raise TypeError(
f"Hook {hook_type} must return an instance of webdriver.Chrome or None."
)
# If the hook returns None or there is no hook, return self.driver
return self.driver
def update_user_agent(self, user_agent: str):
self.options.add_argument(f"user-agent={user_agent}")
self.driver.quit()
self.driver = webdriver.Chrome(service=self.service, options=self.options)
self.driver = self.execute_hook("on_user_agent_updated", self.driver)
def set_custom_headers(self, headers: dict):
# Enable Network domain for sending headers
self.driver.execute_cdp_cmd("Network.enable", {})
# Set extra HTTP headers
self.driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": headers})
def _ensure_page_load(self, max_checks=6, check_interval=0.01):View on GitHub (pinned to 7e80152142)
Solutions
- Make the hook return the webdriver.Chrome instance it configured, or None.
- Do not return arbitrary values from driver hooks.
Example fix
def hook(driver):
driver.execute_cdp_cmd(...)
return driver When it happens
Trigger: Thrown at crawl4ai/legacy/crawler_strategy.py:175 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of unclecode/crawl4ai@7e80152142 (2026-08-14).
Data as JSON: /api/errors/11aa02c2baefeb43.
Report an issue: GitHub.