loadRequest method

  1. @override
Future<void> loadRequest(
  1. WebViewRequest request
)

See WebViewController.loadRequest or WebViewPlatformController.loadRequest.

Limitations on Linux

Requests cannot be made for an origin different from the current page. You must first navigate to the request origin (scheme + domain) using some other mechanism (loadUrl without headers, link click, etc).

This is due to CEF (the underlying browser) limitations.

loadRequest calls CefFrame::LoadRequest on the native side. the LoadRequest method will fail with a "bad IPC message" error unless you first navigate to the request origin.

For more detail: https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-custom-requests

Known bug (?)

The timing of when Future is resolved is different from Android/iOS. Immediately after this method is resolved, the new URL cannot yet be obtained with currentUrl.

TODO(Ino): Immediately reflect the new URL in currentUrl.

Implementation

@override
Future<void> loadRequest(
  WebViewRequest request,
) async {
  final int? webviewId = instanceManager.getInstanceId(this);
  if (webviewId == null) {
    throw 'Failed to get the webview instance';
  }
  final String method = request.method.serialize().toUpperCase();
  await (await LinuxWebViewPlugin.channel)
      .invokeMethod('loadRequest', <String, dynamic>{
    'webviewId': webviewId,
    'uri': request.uri.toString(),
    'method': method,
    'headers': request.headers,
    'body': request.body ?? Uint8List(0),
  });
}