kill method

Future<String> kill({
  1. bool? blockAds,
  2. String? browserId,
  3. BrowserServerOptionsOrCDPLaunchOptionsOrString? launch,
  4. String? profile,
  5. num? timeout,
  6. String? token,
  7. String? trackingId,
  8. dynamic body,
})

HTTP Method: GET Kill running sessions based on BrowserId or TrackingId. Summary: /kill/+(0-9a-zA-Z-_)

Implementation

Future<String> kill({
  bool? blockAds,
  String? browserId,
  BrowserServerOptionsOrCDPLaunchOptionsOrString? launch,
  String? profile,
  num? timeout,
  String? token,
  String? trackingId,
  dynamic body,
}) async {
  final queryParams = <String, String>{};
  if (defaultToken != null) {
    queryParams['token'] = defaultToken!;
  }
  if (blockAds != null) {
    queryParams['blockAds'] = blockAds.toString();
  }
  if (browserId != null) {
    queryParams['browserId'] = browserId.toString();
  }
  if (launch != null) {
    queryParams['launch'] = launch.toString();
  }
  if (profile != null) {
    queryParams['profile'] = profile.toString();
  }
  if (timeout != null) {
    queryParams['timeout'] = timeout.toString();
  }
  if (token != null) {
    queryParams['token'] = token.toString();
  }
  if (trackingId != null) {
    queryParams['trackingId'] = trackingId.toString();
  }
  final pathUrl = '/kill/+([0-9a-zA-Z-_])';
  final uri = Uri.parse(
    '$baseUrl$pathUrl',
  ).replace(queryParameters: queryParams.isNotEmpty ? queryParams : null);
  final request = http.Request('GET', uri);
  if (body != null) {
    request.headers['Content-Type'] = 'application/json';
    request.body = jsonEncode(body);
  }
  final streamedResponse = await _client.send(request);
  final response = await http.Response.fromStream(streamedResponse);
  if (response.statusCode != 200 && response.statusCode != 204) {
    throw Exception('HTTP ${response.statusCode}: ${response.body}');
  }
  if (response.statusCode == 204) return '';
  return jsonDecode(response.body);
}