hlwhl / webview_cef

WebView for Flutter Desktop Apps using CEF(Chromium Embedded Framework) [Work in Progress]
Apache License 2.0
189 stars 54 forks source link

Detect and avoid navigate to other url on click #127

Open MobileD3v3l opened 5 months ago

MobileD3v3l commented 5 months ago

Hi,

It's possible to detect clicks on links inside a website and block the navigation.

Something like:

shouldOverrideUrlLoading: (controller, url) async {
      if (url.startsWith('http://') || url.startsWith('https://')) {
          if (await canLaunch(url)) {
              await launch(url);
              return true; // Prevent navigation within WebView
          }
      }
      return false; // Allow navigation within WebView
},
SinyimZhi commented 5 months ago

It looks like you need a blacklist, and I will consider adding this feature next.