Class BrowserService
java.lang.Object
com.shaft.mcp.BrowserService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a cookie to the current browser session.voidDeletes all cookies in the current browser session.voiddeleteCookie(String cookieName) Deletes a specific cookie by name in the current browser session.voidSets the browser window to fullscreen mode.Retrieves all cookies from the current browser session.Retrieves a cookie by name from the current browser session.Retrieves the current URL of the browser.getPageDom(int maxCharacters) Captures the current page DOM for MCP browser automation inspection.getTitle()Retrieves the title of the current page in the browser.voidMaximizes the browser window.voidNavigates the browser to the specified URL.voidNavigates back to the previous page in the browser's history.voidNavigates forward to the next page in the browser's history.voidnavigateWithBasicAuth(String targetUrl, String username, String password, String targetUrlAfterAuth) Navigates the browser to the specified URL using Basic Authentication.voidRefreshes the current page in the browser.voidsetWindowSize(int width, int height) Sets the browser window to a specific size.takeScreenshot(String outputPath, boolean includeBase64) Takes a PNG screenshot of the current browser viewport for MCP browser automation inspection.
-
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
-
getCookie
-
getAllCookies
Retrieves all cookies from the current browser session.- Returns:
- A string representation of all cookies.
-
getCurrentUrl
Retrieves the current URL of the browser.- Returns:
- The current URL as a 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 pathincludeBase64- whether to include the PNG bytes as base64 in the response- Returns:
- screenshot metadata and optional base64 payload