loadUrl method
See WebViewController.loadUrl
or WebViewPlatformController.loadUrl
.
Limitations on Linux
Requests with headers
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.
loadUrl calls CefFrame::LoadURL or CefFrame::LoadRequest on the native side. CefFrame::LoadURL is used when no header is specified, and CefFrame::LoadRequest is used when a header is specified. However, the LoadRequest method will fail 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 that expected on Android/iOS (see the integration test). When loadUrl is resolved, the new URL is expected to be available in currentUrl, but the current implementation does not do so.
TODO(Ino): Fix loadUrl so that the expected URL is available in currentUrl.
Implementation
@override
Future<void> loadUrl(
String url,
Map<String, String>? headers,
) async {
final int? webviewId = instanceManager.getInstanceId(this);
if (webviewId == null) {
throw 'Failed to get the webview instance';
}
if (headers == null || headers.isEmpty) {
// no headers
await (await LinuxWebViewPlugin.channel)
.invokeMethod('loadUrl', <String, dynamic>{
'webviewId': webviewId,
'url': url,
});
} else {
// with headers
await loadRequest(WebViewRequest(
uri: Uri.parse(url),
method: WebViewRequestMethod.get,
headers: headers,
));
}
}