continueRequest method
Continues request with optional request overrides. To use this, request
interception should be enabled with page.setRequestInterception
.
Exception is immediately thrown if the request interception is not enabled.
await page.setRequestInterception(true);
page.onRequest.listen((request) {
// Override headers
var headers = Map<String, String>.from(request.headers)
..['foo'] = 'bar'
..remove('origin');
request.continueRequest(headers: headers);
});
Parameters:
url
: If set, the request url will be changed. This is not a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url.method
: If set changes the request method (e.g.GET
orPOST
)postData
: If set changes the post data of requestheaders
: If set changes the request HTTP headers
Implementation
Future<void> continueRequest(
{String? url,
String? method,
String? postData,
Map<String, String>? headers}) async {
// Request interception is not supported for data: urls.
if (this.url.startsWith('data:')) return;
assert(allowInterception, 'Request Interception is not enabled!');
assert(!_interceptionHandled, 'Request is already handled!');
_interceptionHandled = true;
var postDataBinaryBase64 =
postData != null ? base64Encode(utf8.encode(postData)) : null;
await _fetchApi
.continueRequest(fetch.RequestId(interceptionId!),
url: url,
method: method,
postData: postDataBinaryBase64,
headers: headers?.entries
.map((e) => fetch.HeaderEntry(name: e.key, value: e.value))
.toList())
.catchError((error) {
// In certain cases, protocol will return error if the request was already canceled
// or the page was closed. We should tolerate these errors.
_logger.finer('[Request.continueRequest] swallow error: $error');
});
}