Class BrowserService

java.lang.Object
com.shaft.mcp.BrowserService

@Service public class BrowserService extends Object
  • Constructor Details

    • BrowserService

      public BrowserService()
  • Method Details

    • refreshPage

      @Tool(name="browser_refresh", description="refreshes the current page") public void refreshPage()
      Refreshes the current page in the browser.
    • maximizeWindow

      @Tool(name="browser_maximize_window", description="maximizes the browser window") public void maximizeWindow()
      Maximizes the browser window.
    • setWindowSize

      @Tool(name="browser_set_window_size", description="sets the browser window to a specific size") public void setWindowSize(int width, int height)
      Sets the browser window to a specific size.
      Parameters:
      width - The desired width of the browser window.
      height - The desired height of the browser window.
    • fullscreenWindow

      @Tool(name="browser_fullscreen_window", description="sets the browser window to fullscreen mode") public void fullscreenWindow()
      Sets the browser window to fullscreen mode.
    • deleteAllCookies

      @Tool(name="browser_delete_all_cookies", description="deletes all cookies") public void deleteAllCookies()
      Deletes all cookies in the current browser session.
    • deleteCookie

      @Tool(name="browser_delete_cookie", description="deletes a specific cookie by name") public void deleteCookie(String cookieName)
      Deletes a specific cookie by name in the current browser session.
      Parameters:
      cookieName - The name of the cookie to delete.
    • addCookie

      public void addCookie(String name, String value)
      Adds a cookie to the current browser session.
      Parameters:
      name - The name of the cookie.
      value - The value of the cookie.
    • getCookie

      public String getCookie(String cookieName)
      Retrieves a cookie by name from the current browser session.
      Parameters:
      cookieName - The name of the cookie to retrieve.
      Returns:
      The cookie value as a string, or null if not found.
    • getAllCookies

      public String getAllCookies()
      Retrieves all cookies from the current browser session.
      Returns:
      A string representation of all cookies.
    • getCurrentUrl

      @Tool(name="browser_get_current_url", description="gets current URL") public String getCurrentUrl()
      Retrieves the current URL of the browser.
      Returns:
      The current URL as a string.
    • getTitle

      @Tool(name="browser_get_title", description="gets current page title") public String getTitle()
      Retrieves the title of the current page in the browser.
      Returns:
      The page title as a string.
    • getPageDom

      @Tool(name="browser_get_page_dom", description="gets the current page DOM/page source for browser automation inspection") public McpPageDomSnapshot getPageDom(int maxCharacters)
      Captures the current page DOM for MCP browser automation inspection.
      Parameters:
      maxCharacters - maximum DOM characters to return; uses a safe default when unset or non-positive
      Returns:
      page DOM snapshot and browser context metadata
    • takeScreenshot

      @Tool(name="browser_take_screenshot", description="takes a PNG screenshot of the current browser viewport") public McpScreenshotResult takeScreenshot(String outputPath, boolean includeBase64)
      Takes a PNG screenshot of the current browser viewport for MCP browser automation inspection.
      Parameters:
      outputPath - optional workspace-relative or workspace-contained output file path
      includeBase64 - whether to include the PNG bytes as base64 in the response
      Returns:
      screenshot metadata and optional base64 payload