invokeBrowser method
Invokes an operating system-level action on a browser session in Amazon Bedrock AgentCore. This operation provides direct OS-level control over browser sessions, enabling mouse actions, keyboard input, and screenshots that the WebSocket-based Chrome DevTools Protocol (CDP) cannot handle — such as interacting with print dialogs, context menus, and JavaScript alerts.
You send a request with exactly one action in the
BrowserAction union, and receive a corresponding result in
the BrowserActionResult union.
The following operations are related to InvokeBrowser:
May throw AccessDeniedException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter action :
The browser action to perform. Exactly one member of the
BrowserAction union must be set per request.
Parameter browserIdentifier :
The unique identifier of the browser associated with the session. This
must match the identifier used when creating the session with
StartBrowserSession.
Parameter sessionId :
The unique identifier of the browser session on which to perform the
action. This must be an active session created with
StartBrowserSession.
Implementation
Future<InvokeBrowserResponse> invokeBrowser({
required BrowserAction action,
required String browserIdentifier,
required String sessionId,
}) async {
final headers = <String, String>{
'x-amzn-browser-session-id': sessionId.toString(),
};
final $payload = <String, dynamic>{
'action': action,
};
final response = await _protocol.sendRaw(
payload: $payload,
method: 'POST',
requestUri:
'/browsers/${Uri.encodeComponent(browserIdentifier)}/sessions/invoke',
headers: headers,
exceptionFnMap: _exceptionFns,
);
final $json = await _s.jsonFromResponse(response);
return InvokeBrowserResponse(
result: BrowserActionResult.fromJson(
($json['result'] as Map<String, dynamic>?) ??
const <String, dynamic>{}),
sessionId: _s.extractHeaderStringValue(
response.headers, 'x-amzn-browser-session-id')!,
);
}