{"record":{"id":"11aa02c2baefeb43","repo":"unclecode/crawl4ai","slug":"hook-hook-type-must-return-an-instance-of-webdri","errorCode":null,"errorMessage":"Hook {hook_type} must return an instance of webdriver.Chrome or None.","messagePattern":"Hook (.+?) must return an instance of webdriver\\.Chrome or None\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crawl4ai/legacy/crawler_strategy.py","lineNumber":175,"sourceCode":"        if kwargs.get(\"cookies\"):\n            for cookie in kwargs.get(\"cookies\"):\n                self.driver.add_cookie(cookie)\n\n    def set_hook(self, hook_type: str, hook: Callable):\n        if hook_type in self.hooks:\n            self.hooks[hook_type] = hook\n        else:\n            raise ValueError(f\"Invalid hook type: {hook_type}\")\n\n    def execute_hook(self, hook_type: str, *args):\n        hook = self.hooks.get(hook_type)\n        if hook:\n            result = hook(*args)\n            if result is not None:\n                if isinstance(result, webdriver.Chrome):\n                    return result\n                else:\n                    raise TypeError(\n                        f\"Hook {hook_type} must return an instance of webdriver.Chrome or None.\"\n                    )\n        # If the hook returns None or there is no hook, return self.driver\n        return self.driver\n\n    def update_user_agent(self, user_agent: str):\n        self.options.add_argument(f\"user-agent={user_agent}\")\n        self.driver.quit()\n        self.driver = webdriver.Chrome(service=self.service, options=self.options)\n        self.driver = self.execute_hook(\"on_user_agent_updated\", self.driver)\n\n    def set_custom_headers(self, headers: dict):\n        # Enable Network domain for sending headers\n        self.driver.execute_cdp_cmd(\"Network.enable\", {})\n        # Set extra HTTP headers\n        self.driver.execute_cdp_cmd(\"Network.setExtraHTTPHeaders\", {\"headers\": headers})\n\n    def _ensure_page_load(self, max_checks=6, check_interval=0.01):","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/legacy/crawler_strategy.py#L157-L193","documentation":"Error \"Hook {hook_type} must return an instance of webdriver.Chrome or None.\" thrown in unclecode/crawl4ai.","triggerScenarios":"Thrown at crawl4ai/legacy/crawler_strategy.py:175 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make the hook return the webdriver.Chrome instance it configured, or None.","Do not return arbitrary values from driver hooks."],"exampleFix":"def hook(driver):\n    driver.execute_cdp_cmd(...)\n    return driver","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}