create method
HTTP Method: PUT Returns a JSON payload that acts as a pass-through to the DevTools /json/new HTTP API in Chromium. Browserless mocks this payload so that remote clients can connect to the underlying "webSocketDebuggerUrl" which will cause Browserless to start the browser and proxy that request into a blank page. Summary: /json/new
Implementation
Future<Map<String, dynamic>> create({dynamic body}) async {
final queryParams = <String, String>{};
if (defaultToken != null) {
queryParams['token'] = defaultToken!;
}
final pathUrl = '/json/new';
final uri = Uri.parse(
'$baseUrl$pathUrl',
).replace(queryParameters: queryParams.isNotEmpty ? queryParams : null);
final request = http.Request('PUT', 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);
}