{"record":{"id":"cd085c2dac6f5e72","repo":"assafelovic/gpt-researcher","slug":"percentage-should-be-between-0-and-1","errorCode":null,"errorMessage":"Percentage should be between 0 and 1","messagePattern":"Percentage should be between 0 and 1","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/scraper/browser/browser.py","lineNumber":255,"sourceCode":"            title = extract_title(soup)\n\n        return text, image_urls, title\n\n    def _scroll_to_bottom(self):\n        \"\"\"Scroll to the bottom of the page to load all content\"\"\"\n        last_height = self.driver.execute_script(\"return document.body.scrollHeight\")\n        while True:\n            self.driver.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")\n            time.sleep(2)  # Wait for content to load\n            new_height = self.driver.execute_script(\"return document.body.scrollHeight\")\n            if new_height == last_height:\n                break\n            last_height = new_height\n\n    def _scroll_to_percentage(self, ratio: float) -> None:\n        \"\"\"Scroll to a percentage of the page\"\"\"\n        if ratio < 0 or ratio > 1:\n            raise ValueError(\"Percentage should be between 0 and 1\")\n        self.driver.execute_script(f\"window.scrollTo(0, document.body.scrollHeight * {ratio});\")\n\n    def _add_header(self) -> None:\n        \"\"\"Add a header to the website\"\"\"\n        self.driver.execute_script(open(f\"{FILE_DIR}/browser/js/overlay.js\", \"r\").read())\n","sourceCodeStart":237,"sourceCodeEnd":261,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/scraper/browser/browser.py#L237-L261","documentation":"BrowserScraper._scroll_to_percentage(ratio) validates its scroll argument: ratio must be a float between 0 and 1, where 1 is the bottom of the page. Passing a percentage like 50, a negative value, or anything >1 raises ValueError('Percentage should be between 0 and 1') before the JavaScript scroll is executed.","triggerScenarios":"Calling scraper methods that scroll (e.g., scrape() with scroll config, or _scroll_to_percentage directly) with ratio passed as 0-100 percent (e.g., 0.5 intended as 50% is fine, but 50 is not), a negative number, or a value greater than 1.0.","commonSituations":"Configuring GPT Researcher's browser scroll settings with a 0-100 scale instead of 0-1 (passing 50 for 'halfway'); copy-pasted snippets using percent integers; passing None or a computed fraction that can go negative/out of range due to a math bug upstream.","solutions":["Pass a fraction in [0, 1]: use 0.5 for 50%, 1.0 for the bottom of the page.","If your config is in percent, divide by 100 before calling: ratio = pct / 100.","Clamp user-supplied values: ratio = min(max(ratio, 0.0), 1.0).","Default to 1.0 when the intended behavior is 'scroll to bottom'."],"exampleFix":"# before\nscraper._scroll_to_percentage(50)  # ValueError: Percentage should be between 0 and 1\n\n# after\nscraper._scroll_to_percentage(0.5)  # 50% of page height\n# or clamp: scraper._scroll_to_percentage(min(max(pct / 100, 0.0), 1.0))","handlingStrategy":"validation","validationCode":"ratio = min(max(float(ratio), 0.0), 1.0)\nassert 0.0 <= ratio <= 1.0, 'scroll ratio must be in [0, 1]'","typeGuard":"def is_scroll_ratio(v) -> bool:\n    return isinstance(v, (int, float)) and not isinstance(v, bool) and 0.0 <= v <= 1.0","tryCatchPattern":"try:\n    scraper._scroll_to_percentage(ratio)\nexcept ValueError:\n    scraper._scroll_to_percentage(min(max(ratio, 0.0), 1.0))  # clamp and retry","preventionTips":["Treat scroll config as a fraction in [0, 1]; never pass 0-100 percentages.","Clamp external/user-supplied values before calling scroll APIs.","Use 1.0 for 'scroll to bottom' semantics.","Validate config numerically at load time with range checks."],"tags":["selenium","scroll","value-validation","range-error","browser-scraper"],"backgroundTag":"argument-out-of-range","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}