Search code examples
javascriptangulartypescriptnativescriptnativescript-angular

Access headers/queryparams from a WebView from Nativescript


I am currently working on a mobile app with Nativescript. So, I do have a WebView in the main page to log in with Spotify. After the login I have to retrieve headers/queryparams from the page in the WebView. Is this possible and if, how do I do that?


Solution

  • You can register the loadFinishedEvent and check for the URL to get the queryparameters that are returning back to you. I am doing the same for third party login.

    webViewLoaded(args) {
            const webview: WebView = <WebView>args.object;
    webview.on(WebView.loadFinishedEvent, (webargs: LoadEventData) => {
                let message;
                if (!webargs.error) {
                    if (webargs.url.toLowerCase().indexOf('spotity') > -1) {
                        //Read the parameters and navigate
    
                    }
    
                    message = 'WebView finished loading of ' + webargs.url;
                } else {
                    message = 'Error loading ' + webargs.url + ': ' + webargs.error;
                }
            });
    }