Git Product home page Git Product logo

request_data_webviewclient's Introduction

Request Data - WebViewClient

Android WebViewClient with a custom WebResourceRequest that contains the POST/PUT/... payload of XMLHttpRequest requests

This project is inspired by https://github.com/KeejOow/android-post-webview and draws some code from there.

When you need to display a webview to the user on which you need to intercept the HTTP calls and perform them yourself (for example to add additional security), you can do so on Android by registering a WebViewClient and implementing

WebResourceResponse shouldInterceptRequest(android.webkit.WebView webview, WebResourceRequest request)

Unfortunately, the request object passed to this method does not contain any POST data.

This project provides a hack around this limitation by injecting a script into the HTML that intercepts AJAX calls.

It provides the WriteHandlingWebViewClient class that extends WebViewClient and provides the

WebResourceResponse shouldInterceptRequest(final WebView view, WriteHandlingWebResourceRequest request)

method to override.

WriteHandlingWebResourceRequest extends WebResourceRequest, but provides the crucial method

public String getAjaxData()

which returns the data in the request body of the AJAX request.

Installation

  • Add the writeinterceptingwebview folder as a libarary module to your android project.
  • jCenter-Maven package will come as soon as I figure out how to do that ... Say what you want about pip, at least it's easy to upload a package.

Example usage

webView.setWebViewClient(new WriteHandlingWebViewClient() {
   @Override
   public boolean shouldOverrideUrlLoading(WebView view, WriteHandlingWebResourceRequest request) {
        // works the same as WebViewClient.shouldOverrideUrlLoading, 
        // but you have request.getAjaxData() which gives you the 
        // request body
   }
});

What about forms? What about other kind of http requests?

The library can probably be extended to work for forms too. In fact, https://github.com/KeejOow/android-post-webview shows how it's done. However, I wasn't happy with my adaption of this so far. Pull requests are welcome ...

request_data_webviewclient's People

Contributors

konstantinschubert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

request_data_webviewclient's Issues

I got this error

2019-04-09 18:24:12.224 8048-8510/W/System.err: java.lang.RuntimeException: interceptheader.html 2019-04-09 18:24:12.224 8048-8510/W/System.err: at xxxx.konstantinschubert.writeinterceptingwebview.WriteHandlingWebViewClient.injectInterceptToStream(WriteHandlingWebViewClient.java:124) 2019-04-09 18:24:12.225 8048-8510/ W/System.err: at xxxx.konstantinschubert.writeinterceptingwebview.WriteHandlingWebViewClient.injectIntercept(WriteHandlingWebViewClient.java:99) 2019-04-09 18:24:12.225 8048-8510/W/System.err: at xxxx.konstantinschubert.writeinterceptingwebview.WriteHandlingWebViewClient.shouldInterceptRequest(WriteHandlingWebViewClient.java:57) 2019-04-09 18:24:12.225 8048-8510/ W/System.err: at xH.a(SourceFile:54) 2019-04-09 18:24:12.225 8048-8510/ W/System.err: at aya.a(SourceFile:9)

Also what is this 'AJAXINTERCEPT' ? Shall you explain me..

private final String MARKER = "AJAXINTERCEPT";

Webview post interception

I have ajax website and i need to add headers to every request from my webview, even for post buttons inside website. What i need to do? Im trying to find solution for some days :(

POST requests are not recognized as ajax requests

Env: Emulator with Android 9

Repro: I setup my WebView according to the example provided on the main page of this library and load an url. The loaded page makes some GET requests and two POST requests afterwards, none of these requests is recognized as an ajax request. I will be glad to provide more details if required.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.