download method
Future<String>
download({
- bool? blockAds,
- CDPLaunchOptionsOrString? launch,
- String? profile,
- num? timeout,
- String? token,
- String? trackingId,
- JSONSchema? body,
HTTP Method: POST A JSON or JavaScript content-type API for returning files Chrome has downloaded during the execution of puppeteer code, which is ran inside context of the browser. Browserless sets up a blank page, a fresh download directory, injects your puppeteer code, and then executes it. You can load external libraries via the "import" syntax, and import ESM-style modules that are written for execution inside of the browser. Once your script is finished, any downloaded files from Chromium are returned back with the appropriate content-type header.
Note: This endpoint is also available at: /download for backwards compatibility.
Summary: /chromium/download
Implementation
Future<String> download({
bool? blockAds,
CDPLaunchOptionsOrString? launch,
String? profile,
num? timeout,
String? token,
String? trackingId,
JSONSchema? body,
}) async {
final queryParams = <String, String>{};
if (defaultToken != null) {
queryParams['token'] = defaultToken!;
}
if (blockAds != null) {
queryParams['blockAds'] = blockAds.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 = '/chromium/download';
final uri = Uri.parse(
'$baseUrl$pathUrl',
).replace(queryParameters: queryParams.isNotEmpty ? queryParams : null);
final request = http.Request('POST', uri);
if (body != null) {
request.headers['Content-Type'] = 'application/json';
request.body = jsonEncode(body.toJson());
}
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 response.body;
}