startBrowserSession method

Future<StartBrowserSessionResponse> startBrowserSession({
  1. required String browserIdentifier,
  2. List<Certificate>? certificates,
  3. String? clientToken,
  4. List<BrowserEnterprisePolicy>? enterprisePolicies,
  5. List<BrowserExtension>? extensions,
  6. String? name,
  7. BrowserProfileConfiguration? profileConfiguration,
  8. ProxyConfiguration? proxyConfiguration,
  9. int? sessionTimeoutSeconds,
  10. String? traceId,
  11. String? traceParent,
  12. ViewPort? viewPort,
})

Creates and initializes a browser session in Amazon Bedrock AgentCore. The session enables agents to navigate and interact with web content, extract information from websites, and perform web-based tasks as part of their response generation.

To create a session, you must specify a browser identifier and a name. You can also configure the viewport dimensions to control the visible area of web content. The session remains active until it times out or you explicitly stop it using the StopBrowserSession operation.

The following operations are related to StartBrowserSession:

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter browserIdentifier : The unique identifier of the browser to use for this session. This identifier specifies which browser environment to initialize for the session.

Parameter certificates : A list of certificates to install in the browser session.

Parameter clientToken : A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock AgentCore ignores the request, but does not return an error. This parameter helps prevent the creation of duplicate sessions if there are temporary network issues.

Parameter enterprisePolicies : A list of files containing enterprise policies for the browser.

Parameter extensions : A list of browser extensions to load into the browser session.

Parameter name : The name of the browser session. This name helps you identify and manage the session. The name does not need to be unique.

Parameter profileConfiguration : The browser profile configuration to use for this session. A browser profile contains persistent data such as cookies and local storage that can be reused across multiple browser sessions. If specified, the session initializes with the profile's stored data, enabling continuity for tasks that require authentication or personalized settings.

Parameter proxyConfiguration : Optional proxy configuration for routing browser traffic through customer-specified proxy servers. When provided, enables HTTP Basic authentication via Amazon Web Services Secrets Manager and domain-based routing rules. Requires secretsmanager:GetSecretValue IAM permission for the specified secret ARNs.

Parameter sessionTimeoutSeconds : The duration in seconds (time-to-live) after which the session automatically terminates, regardless of ongoing activity. Defaults to 3600 seconds (1 hour). Recommended minimum: 60 seconds. Maximum allowed: 28,800 seconds (8 hours).

Parameter traceId : The trace identifier for request tracking.

Parameter traceParent : The parent trace information for distributed tracing.

Parameter viewPort : The dimensions of the browser viewport for this session. This determines the visible area of the web content and affects how web pages are rendered. If not specified, Amazon Bedrock AgentCore uses a default viewport size.

Implementation

Future<StartBrowserSessionResponse> startBrowserSession({
  required String browserIdentifier,
  List<Certificate>? certificates,
  String? clientToken,
  List<BrowserEnterprisePolicy>? enterprisePolicies,
  List<BrowserExtension>? extensions,
  String? name,
  BrowserProfileConfiguration? profileConfiguration,
  ProxyConfiguration? proxyConfiguration,
  int? sessionTimeoutSeconds,
  String? traceId,
  String? traceParent,
  ViewPort? viewPort,
}) async {
  _s.validateNumRange(
    'sessionTimeoutSeconds',
    sessionTimeoutSeconds,
    1,
    28800,
  );
  final headers = <String, String>{
    if (traceId != null) 'X-Amzn-Trace-Id': traceId.toString(),
    if (traceParent != null) 'traceparent': traceParent.toString(),
  };
  final $payload = <String, dynamic>{
    if (certificates != null) 'certificates': certificates,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (enterprisePolicies != null) 'enterprisePolicies': enterprisePolicies,
    if (extensions != null) 'extensions': extensions,
    if (name != null) 'name': name,
    if (profileConfiguration != null)
      'profileConfiguration': profileConfiguration,
    if (proxyConfiguration != null) 'proxyConfiguration': proxyConfiguration,
    if (sessionTimeoutSeconds != null)
      'sessionTimeoutSeconds': sessionTimeoutSeconds,
    if (viewPort != null) 'viewPort': viewPort,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'PUT',
    requestUri:
        '/browsers/${Uri.encodeComponent(browserIdentifier)}/sessions/start',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return StartBrowserSessionResponse.fromJson(response);
}