From fd3d04537a6fdedd00a993fb5bacd9170ad06792 Mon Sep 17 00:00:00 2001 From: mertunsall Date: Wed, 23 Jul 2025 19:24:20 +0200 Subject: [PATCH] fix --- browser_use/agent/prompts.py | 2 +- browser_use/controller/service.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.py index 95b86bfe8..aaf1ebf0b 100644 --- a/browser_use/agent/prompts.py +++ b/browser_use/agent/prompts.py @@ -289,7 +289,7 @@ Interactive elements from top layer of the current page inside the viewport{trun return UserMessage(content=browser_state_content, cache=False) def get_read_state_message(self) -> UserMessage | None: - """Get read state as a separate cached message""" + """Get read state as a separate message""" if not self.read_state_description: return None if not self.read_state_description.strip('\n').strip(): diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py index 975234cfb..c5f1e210b 100644 --- a/browser_use/controller/service.py +++ b/browser_use/controller/service.py @@ -4,10 +4,7 @@ import json import logging import os import re -from typing import TYPE_CHECKING, Generic, TypeVar, cast - -if TYPE_CHECKING: - from browser_use.browser.types import Page +from typing import Generic, TypeVar, cast try: from lmnr import Laminar # type: ignore @@ -18,6 +15,7 @@ from pydantic import BaseModel from browser_use.agent.views import ActionModel, ActionResult from browser_use.browser import BrowserSession +from browser_use.browser.types import Page from browser_use.browser.views import BrowserError from browser_use.controller.registry.service import Registry from browser_use.controller.views import ( @@ -298,7 +296,7 @@ Only use this for specific queries for information retrieval from the page. Don' async def extract_structured_data( query: str, extract_links: bool, - page: 'Page', + page: Page, page_extraction_llm: BaseChatModel, file_system: FileSystem, ): @@ -611,7 +609,7 @@ Explain the content of the page and that the requested information is not availa 'Send strings of special keys to use Playwright page.keyboard.press - examples include Escape, Backspace, Insert, PageDown, Delete, Enter, or Shortcuts such as `Control+o`, `Control+Shift+T`', param_model=SendKeysAction, ) - async def send_keys(params: SendKeysAction, page: 'Page'): + async def send_keys(params: SendKeysAction, page: Page): try: await page.keyboard.press(params.keys) except Exception as e: @@ -632,7 +630,7 @@ Explain the content of the page and that the requested information is not availa @self.registry.action( description='Scroll to a text in the current page', ) - async def scroll_to_text(text: str, page: 'Page'): # type: ignore + async def scroll_to_text(text: str, page: Page): # type: ignore try: # Try different locator strategies locators = [ @@ -915,7 +913,7 @@ Explain the content of the page and that the requested information is not availa raise BrowserError(msg) @self.registry.action('Google Sheets: Get the contents of the entire sheet', domains=['https://docs.google.com']) - async def read_sheet_contents(page: 'Page'): + async def read_sheet_contents(page: Page): # select all cells await page.keyboard.press('Enter') await page.keyboard.press('Escape') @@ -981,7 +979,7 @@ Explain the content of the page and that the requested information is not availa ) @self.registry.action('Google Sheets: Select a specific cell or range of cells', domains=['https://docs.google.com']) - async def select_cell_or_range(cell_or_range: str, page: 'Page'): + async def select_cell_or_range(cell_or_range: str, page: Page): await page.keyboard.press('Enter') # make sure we dont delete current cell contents if we were last editing await page.keyboard.press('Escape') # to clear current focus (otherwise select range popup is additive) await asyncio.sleep(0.1) @@ -1005,7 +1003,7 @@ Explain the content of the page and that the requested information is not availa 'Google Sheets: Fallback method to type text into (only one) currently selected cell', domains=['https://docs.google.com'], ) - async def fallback_input_into_single_selected_cell(text: str, page: 'Page'): + async def fallback_input_into_single_selected_cell(text: str, page: Page): await page.keyboard.type(text, delay=0.1) await page.keyboard.press('Enter') # make sure to commit the input so it doesn't get overwritten by the next action await page.keyboard.press('ArrowUp')