Skip to content

Android - WebView issue - shouldOverrideUrlLoading #10147

Closed

Description

@prabudevarrajan

Issue Description

Android app is unable to handle custom URLs. Due to the following change.

For e.g. if my app has a custom URL bookkeeper://action=close which is used to close the current screen

 webview.on(WebView.loadStartedEvent, function (args: LoadEventData) {  
      if ((args.url).indexOf('bookkeeper://action=close') === 0) { // This code is used to override the default webview for loading the URL
                webview.stopLoading();
                this.routerExtensions.back();
      }
}

What is happening is shouldOverrideUrlLoading is getting called in android webView and directly passing to Util.openURL API. So, the loadStartedEvent is not getting called.

Reproduction

Reproducible in nativescript android core 8.4.0 and above

$ ns run/debug android

Relevant log output (if applicable)

OS: macOS 13.0.1
CPU: (8) x64 Apple M1
Shell: /bin/bash
node: 16.15.0
npm: 8.5.5
nativescript: 8.4.0

# android
java: 18.0.1
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 14.1/14B47b
cocoapods: 1.11.3
python: 3.9.13
python3: 3.9.13
ruby: 2.6.10
platforms: 
  - DriverKit 22.1
  - iOS 16.1
  - macOS 13.0
  - tvOS 16.1
  - watchOS 9.1


### Dependencies

```json
"dependencies": {
  "@angular/animations": "~14.2.0",
  "@angular/common": "~14.2.0",
  "@angular/compiler": "~14.2.0",
  "@angular/core": "~14.2.0",
  "@angular/forms": "~14.2.0",
  "@angular/platform-browser": "~14.2.0",
  "@angular/platform-browser-dynamic": "~14.2.0",
  "@angular/router": "~14.2.0",
  "@bradmartin/nativescript-urlhandler": "^2.0.1",
  "@nativescript-community/ble": "^3.1.11",
  "@nativescript-community/drawingpad": "^4.1.0",
  "@nativescript-community/perms": "^2.2.21",
  "@nativescript/angular": "^14.2.0",
  "@nativescript/appversion": "^2.0.0",
  "@nativescript/background-http": "^6.0.0",
  "@nativescript/camera": "^5.0.12",
  "@nativescript/core": "~8.4.1",
  "@nativescript/firebase-core": "^2.0.2",
  "@nativescript/firebase-messaging": "^2.0.2",
  "@nativescript/geolocation": "^8.0.2",
  "@nativescript/google-maps": "^1.3.0",
  "@nativescript/imagepicker": "^1.0.6",
  "@nativescript/iqkeyboardmanager": "^2.0.0",
  "@nativescript/secure-storage": "^3.0.0",
  "@nativescript/theme": "^3.0.2",
  "@nstudio/nativescript-barcodescanner": "^5.0.1",
  "@prabudevarrajan/filepicker": "^2.0.0",
  "@proplugins/nativescript-globalevents": "^1.4.1",
  "@proplugins/nativescript-platform": "^1.4.11",
  "@proplugins/nativescript-platform-css": "^1.8.1",
  "@ticnat/nativescript-image-cache": "^1.0.7",
  "@triniwiz/nativescript-toasty": "^4.1.3",
  "angular2-moment": "^1.9.0",
  "nativescript-material-icons": "^1.0.3",
  "nativescript-ngx-fonticon": "^7.0.0",
  "nativescript-sqlite": "^2.8.6",
  "nativescript-ui-listview": "^14.2.2",
  "nativescript-ui-sidedrawer": "~14.2.0",
  "reflect-metadata": "~0.1.12",
  "rxjs": "~7.5.0",
  "zone.js": "~0.11.5"
},
"devDependencies": {
  "@angular-devkit/build-angular": "~14.2.0",
  "@angular/compiler-cli": "~14.2.0",
  "@nativescript/android": "8.4.0",
  "@nativescript/ios": "8.4.0",
  "@nativescript/types": "^8.4.0",
  "@nativescript/webpack": "~5.0.6",
  "@ngtools/webpack": "~14.2.0",
  "nativescript-worker-loader": "^0.12.1",
  "terser-webpack-plugin": "^5.3.1",
  "typescript": "~4.7.0"
}


### Environment

_No response_

### Please accept these terms

- [X] I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before
- [X] This is a bug report
- [X] I agree to follow this project's [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc)

Activity

  1. CatchABus commented on Dec 28, 2022

    @CatchABus
    Contributor

    Thanks for clarifying the issue. Does iOS have similar behaviour when using this custom schema?
    We'd rather keep behaviour identical for both platforms.

  2. prabudevarrajan commented on Dec 29, 2022

    @prabudevarrajan
    ContributorAuthor

    iOS my current logic works fine. I believe in iOS internally they use canOpenURL to check whether the URL can be opened by the device, then invoke openUrl. Otherwise, app has to handle the URL. So, I was handling the URL with event WebView.loadStartedEvent.

    Similar discussion in stackoverflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions