Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useShouldOverrideUrlLoading is broken for InAppWebView #146

Closed
peter-meemo opened this issue Aug 27, 2019 · 27 comments
Closed

useShouldOverrideUrlLoading is broken for InAppWebView #146

peter-meemo opened this issue Aug 27, 2019 · 27 comments

Comments

@peter-meemo
Copy link

On ios: the provided shouldOverrideUrlLoading callback is never called.
On android: the browser sometimes returns empty pages.

@YudiH
Copy link

YudiH commented Sep 16, 2019

Any solutions for this? Having the same issue when I put useShouldOverrideUrlLoading": true in initialOptions. Empty/blank page. Loads fine when I remove that option.

I'm trying to find a solution to listen to url changes. Is there a workaround for this plugin? Or is the alternative only in finding/using some other plugin?

Cheers

@YudiH
Copy link

YudiH commented Sep 16, 2019

For now, my bandage solution is listening to the url change inside onLoadStart, seems to fire everytime a diff url has to load.

@pcg92
Copy link

pcg92 commented Sep 24, 2019

@YudiH im using onLoadStart on ios and seems not working, only the first time, Can you show me your code please?

@YudiH
Copy link

YudiH commented Sep 24, 2019

@pcegarra
image

That's all I did. Made a function that takes the loaded url and do with it whatever you need.
You could add a print() to check whenever it fires. Should help you understand how it works on ios. I personally am testing this on Android. So I can't help you there, sorry. Hope this helps.

@pichillilorenzo
Copy link
Owner

Try the latest version of the plugin. Also, this plugin changed its name to flutter_inappwebview. The current latest version now is 2.1.0+1. So, you can change your dependency influtter_inappwebview: ^2.1.0+1.

@ductranit
Copy link

ductranit commented Dec 5, 2019

@pichillilorenzo
I can confirm this issue still happen on iOS with the latest version in my pubspec.yaml: flutter_inappwebview: ^2.1.0+1
Here is my code:

InAppWebView(
          initialUrl: "https://www.google.com",
          initialOptions: InAppWebViewWidgetOptions(inAppWebViewOptions: InAppWebViewOptions(useShouldOverrideUrlLoading: true, useOnLoadResource: true)),
          onLoadStop: (InAppWebViewController controller, String url) {
            hideLoading();
          }, shouldOverrideUrlLoading: (InAppWebViewController controller, String url) {
              LogUtil.v("shouldOverrideUrlLoading $url");
          })

The shouldOverrideUrlLoading callback is never called

@pichillilorenzo
Copy link
Owner

@ductranit Do you mean at the first load or also when you navigate other links?

In the first load, the shouldOverrideUrlLoading event is not called (that's because both Android and iOS platforms don't call this event in their webview implementation).

@ductranit
Copy link

ductranit commented Dec 5, 2019

@pichillilorenzo ok, so it isn't called on the first time.
When user clicks on an url, it works
But when website is navigated by javascript, shouldOverrideUrlLoading isn't called.
For example, my app uses azure b2c authenticate, after user login, it redirects to https://jwt.ms to get the token, only the onLoadStop works (but I need to handle url before it loads). I tried the plugin https://pub.dev/packages/webview_flutter
and it can catch all the navigations in the navigationDelegate callback.

@pichillilorenzo
Copy link
Owner

@ductranit then you can try the onNavigationStateChange event. As the documentation says:

Event fired when the navigation state of the InAppWebView changes throught the usage of javascript History API functions (pushState(), replaceState()) and onpopstate event.

Also, the event is fired when the javascript window.location changes without reloading the webview (for example appending or modifying an hash to the url).

Let me know

@ductranit
Copy link

@pichillilorenzo the onNavigationStateChange is never called. I debug & see these events are called when it navigates:

  • onLoadStop: when the url is loaded completely
  • onProgressChanged: I use controller.getUrl() during the progress changed, but this way isn't stable, sometime the url changes after progress is 100 (page loaded)
  • onLoadResource - same as onProgressChanged (page loaded)

pichillilorenzo added a commit that referenced this issue Dec 9, 2019
…nd event #128, fix #123 javascript handler for Android API <= 22, renamed onTargetBlank to onCreateWindow event, deleted useOnTargetBlank option, added supportMultipleWindows android option, added getDefaultUserAgent static method, Updated default value for domStorageEnabled option to true
pichillilorenzo added a commit that referenced this issue Dec 9, 2019
…nd event #128, fix #123 javascript handler for Android API <= 22, renamed onTargetBlank to onCreateWindow event, deleted useOnTargetBlank option, added supportMultipleWindows android option, added getDefaultUserAgent static method, Updated default value for domStorageEnabled option to true
pichillilorenzo added a commit that referenced this issue Dec 9, 2019
…nd event #128, fix #123 javascript handler for Android API <= 22, renamed onTargetBlank to onCreateWindow event, deleted useOnTargetBlank option, added supportMultipleWindows android option, added getDefaultUserAgent static method, Updated default value for domStorageEnabled option to true
@YudiH
Copy link

YudiH commented Dec 13, 2019

Try the latest version of the plugin. Also, this plugin changed its name to flutter_inappwebview. The current latest version now is 2.1.0+1. So, you can change your dependency influtter_inappwebview: ^2.1.0+1.

@pichillilorenzo Updated to that version. But a friend that built on ios reported this problem:

CustomeSchemeHandler.swift:22:27: warning:
expression implicitly coerced from 'String?' to 'Any'
print((result as! FlutterError).message

Had to revert back to flutter_inappbrowser 1.2.2 for now

@kbokarius
Copy link

I have the same issue with federated sign in through Cognito, switching over to https://pub.dev/packages/webview_flutter

@arnaudelub
Copy link

arnaudelub commented Apr 1, 2020

i'm facing the same issue, i'm using the git url in my pubsec.yaml:

flutter_inappwebview:
  git: 
    url: https://github.com/pichillilorenzo/flutter_inappwebview

It's working fine in debug mode, but in release, the souldOverrideUrlLoading is never triggered on Android. On iOS, it's working fine

Update

Using controller.getOptions() i can see that, while in debug, options are set correctly but in release mode, every option is equal to null

Update 2

Found out that shouldOverrideUrlLoading is working correctly unless using in app/build.gradle:

buildTypes{
  release {
    minifyEnabled True
  }
}

So in the meanwhile, set it to false if anyone is having the same problem as me

@pichillilorenzo
Copy link
Owner

It should work with the new version! Let me know

This was referenced Jul 6, 2020
@dwiprawira
Copy link

Hi I think useShouldOverrideUrlLoading broken again after I updated flutter to stable version 1.22.0.

My workaround is use onLoadStart for android platform and shouldOverrideUrlLoading on iOS

@lo-re-co
Copy link

It's broken again

@mozaa-vn
Copy link

mozaa-vn commented Jul 30, 2021

It's broken again

I'm using version 5.3.2 and it works perfectly

@Zamaruu
Copy link

Zamaruu commented Aug 9, 2021

I'm using version 5.3.2 and it works perfectly

Can you share your code please?

@aamir-nazir
Copy link

I'm using version 5.3.2 and it works perfectly

Can you share your code please?

I managed to get it working. I was missing something. Thank you for the quick reply.

@mozaa-vn
Copy link

I'm using version 5.3.2 and it works perfectly

Can you share your code please?

I just follow the document, here is my code:

shouldOverrideUrlLoading: (controller, navigationAction) async {
  final uri = navigationAction.request.url!;
  print("uri = " + uri.toString());
  if (uri.toString().contains(GameRoute.GAME_COMPLETE)) {
    //
    return NavigationActionPolicy.CANCEL;
  }
  return NavigationActionPolicy.ALLOW;
},

@mrgulshanyadav
Copy link

It's not working for me too in iOS.

@djks74
Copy link

djks74 commented Sep 17, 2021

Its broken.

why there is none perfect webview plugin in this world? :-(

@SCaptainCAP
Copy link

Why is this issue closed? It does not work for now

@kouchi32
Copy link

I solved the problem with this code.

InAppWebView(
  initialOptions: InAppWebViewGroupOptions(
    crossPlatform:
        InAppWebViewOptions(useShouldOverrideUrlLoading: true),
  ),
  shouldOverrideUrlLoading: (controller, navigationAction) async {
    // any code;
    return NavigationActionPolicy.ALLOW;
  },
)

@dwikurniantom
Copy link

@bakatsuyuki DUDE! you save me a lot of time. Thanks man, i appreciate it, really.

@ghost
Copy link

ghost commented Jun 29, 2023

@kouchi32 : This only works when you are openning any new page. If you come back, it doesn't work

Copy link

github-actions bot commented Oct 7, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests