unclecode/crawl4ai · error · ValueError
Invalid hook type: {hook_type}
Error message
Invalid hook type: {hook_type} What it means
Error "Invalid hook type: {hook_type}" thrown in unclecode/crawl4ai.
Source
Thrown at crawl4ai/legacy/crawler_strategy.py:165
# self.service = Service(chromedriver_path)
# self.service.log_path = "NUL"
# self.driver = webdriver.Chrome(service=self.service, options=self.options)
# Use selenium-manager (built into Selenium 4.10.0+)
self.service = Service()
self.driver = webdriver.Chrome(options=self.options)
self.driver = self.execute_hook("on_driver_created", self.driver)
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()View on GitHub (pinned to 7e80152142)
Solutions
- Use one of the supported hook types (e.g. on_driver_created, before_get_url, after_get_url, before_return_html).
- Check the hook name string for typos.
Example fix
crawler_strategy.set_hook('after_get_url', my_hook) When it happens
Trigger: Thrown at crawl4ai/legacy/crawler_strategy.py:165 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/1c7a2d3a796981f1.
Report an issue: GitHub.