{"record":{"id":"d41b79ea7db5b1cf","repo":"unclecode/crawl4ai","slug":"unsupported-number-of-browsers-num-browsers","errorCode":null,"errorMessage":"Unsupported number of browsers: {num_browsers}","messagePattern":"Unsupported number of browsers: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/user_agent_generator.py","lineNumber":278,"sourceCode":"\n    def get_browser_stack(self, num_browsers: int = 1) -> List[str]:\n        \"\"\"\n        Get a valid combination of browser versions.\n\n        How it works:\n        1. Check if the number of browsers is supported.\n        2. Randomly choose a combination of browsers.\n        3. Iterate through the combination and add browser versions.\n        4. Return the browser stack.\n\n        Args:\n            num_browsers: Number of browser specifications (1-3)\n\n        Returns:\n            List[str]: A list of browser versions.\n        \"\"\"\n        if num_browsers not in self.browser_combinations:\n            raise ValueError(f\"Unsupported number of browsers: {num_browsers}\")\n\n        combination = random.choice(self.browser_combinations[num_browsers])\n        browser_stack = []\n\n        for browser in combination:\n            if browser == \"chrome\":\n                browser_stack.append(random.choice(self.chrome_versions))\n            elif browser == \"firefox\":\n                browser_stack.append(random.choice(self.firefox_versions))\n            elif browser == \"safari\":\n                browser_stack.append(random.choice(self.safari_versions))\n            elif browser == \"edge\":\n                browser_stack.append(random.choice(self.edge_versions))\n            elif browser == \"gecko\":\n                browser_stack.append(random.choice(self.rendering_engines[\"gecko\"]))\n            elif browser == \"webkit\":\n                browser_stack.append(self.rendering_engines[\"chrome_webkit\"])\n","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/user_agent_generator.py#L260-L296","documentation":"ValueError from UserAgentGenerator's browser-stack builder: the requested num_browsers is not a key in browser_combinations (which supports stacks of 1-3 browsers). The generator composes realistic version strings by sampling from predefined combinations per count, so unsupported counts have no template.","triggerScenarios":"Calling _get_browser_stack (or a public wrapper like generate_user_agent with a stack size parameter) with num_browsers of 0, a negative number, or >= 4.","commonSituations":"Computing the count dynamically (e.g. random.randint(1, 5) or len(custom_list)) and letting it exceed 3, passing a list length instead of a clamped int, or API misuse assuming any count is supported.","solutions":["Clamp the value to 1-3 before calling: max(1, min(3, num_browsers)).","If you need richer fingerprint variety, vary OS/device and version lists instead of stack depth.","Check the generator's API/docs for the supported range and pass a literal."],"exampleFix":"# before\nua = generator.generate_user_agent(num_browsers=4)  # ValueError: Unsupported number of browsers: 4\n\n# after\nnum = max(1, min(3, requested_count))\nua = generator.generate_user_agent(num_browsers=num)","handlingStrategy":"validation","validationCode":"def safe_num_browsers(n: int | None) -> int:\n    if n is None:\n        return 2\n    return max(1, min(3, int(n)))","typeGuard":null,"tryCatchPattern":"try:\n    ua = generator.generate_user_agent(num_browsers=n)\nexcept ValueError as e:\n    if 'Unsupported number of browsers' in str(e):\n        ua = generator.generate_user_agent(num_browsers=max(1, min(3, n)))","preventionTips":["Clamp dynamic counts to 1-3 at the call site.","Don't derive stack size from unbounded inputs like list lengths or random ranges wider than 1-3."],"tags":["user-agent","validation","configuration","fingerprinting"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}