setProxy method

Future<void> setProxy(
  1. Proxy proxy
)

Sets a proxy for the browser to use

Implementation

Future<void> setProxy(Proxy proxy) async {
  _checkDisposed();

  _proxy = proxy;

  if (_controller == null) {
    return;
  }

  if (Platform.isAndroid) {
    // Try to set system proxy if available
    bool systemProxySet = false;
    try {
      // Check if Android proxy setter is supported
      if (AndroidProxySetter.isSupported) {
        final hasPermission = await AndroidProxySetter.hasProxyPermission();
        if (hasPermission) {
          systemProxySet = await AndroidProxySetter.setSystemProxy(proxy);
        }
      }
    } catch (e) {
      _log('Error setting system proxy: $e', isError: true);
    }

    // Set WebView settings
    await _controller!.setSettings(
      settings: InAppWebViewSettings(
        // Android uses system proxy settings
        // We can't set them directly from the app
        // This is a limitation of the Android WebView
      ),
    );

    if (systemProxySet) {
      _log('System proxy set to ${proxy.host}:${proxy.port}');
    } else {
      _log(
        'Proxy set to ${proxy.host}:${proxy.port} (Note: Android uses system proxy)',
      );
    }
  } else if (Platform.isIOS) {
    // iOS doesn't support proxy configuration in WebView
    _log('Proxy settings not supported on iOS WebView', isError: true);
  }
}