How to intercept http/https calls after original WkWebview call? - ios

The iOS application we have has a WkWebview that tries to communicate with our server by calling a https endpoint. The server works similar to a proxy and all calls to our endpoint will then forward the request to the destination site. For example - in our app if we were to set our destination to https://www.google.com the application will translate that to https://server.com/http://www.google.com.
The problem we are trying to solve is the interception of all http/https calls after the original WkWebview call. This includes all resource calls like css and javascript files. We have tried to use a custom scheme handler but since we do not parse the html/css on the server side we cannot add a custom scheme to intercept all http/https calls.

You can add the interception logic inside the webview for example every request store url and current number of calls inside a hidden element , and check it's value periodically by evaluteJavaScript function of the webview for that element

Related

Completely replacing a request in a WebExtension

I'm looking to make a web extension for Firefox that stores HTML pages and other resources in local storage and serves them for offline viewing. To do that, I need to intercept requests that the browser makes for the pages and the content in them.
Problem is, I can't figure out how to do that. I've tried several approaches:
The webRequest API doesn't allow fulfilling a request entirely - it can only block or redirect a request, or edit the response after it's been done.
Service Workers can listen to the fetch event, which can do what I want, but calling navigator.serviceWorker.register in an addon page (the moz-extension://<id> domain) results in an error: DOMException: The operation is insecure. Relevant Firefox bug
I could possibly set up the service worker on a self hosted domain with a content script, but then it won't be completely offline.
Is there an API that I missed that can intercept requests from inside a web extension?

How to handle the request in the electron app (capture request, serve custom response)

I want to handle any API requests from the web app wrapped in the electron app. My intention was to keep the same API calls that web app delivered over the net will stay the same as when delivered as standalone electron app. In the latter I would capture API requests and serve responses created locally. Is it possible? I'm looking into WebRequest callbacks available through session.defaultSession.webRequest e.g. session.defaultSession.webRequest.onResponseStarted
Edit 02/01/2020
I've found also to use the ProtocolAPI but then I would have to modify my API calls which I want to intercept to use custom protocol when within electron wrapper which is not what I want (intercept request and serve custom response on electron).
Your web app will work 100%(*) the same in Electron as it does without. The (*) is the caveat that throwing the production flag on your web app may come with other side effects, and that may confuse things.
Just because Electron comes with its own native way to handle certain things, doesn't mean Electron will prevent you from doing things the way you've been doing thus far.
For example I'm doing all my client-server action via JQuery's .ajax() method and Sails.js's MVC action handlers. Electron hasn't interfered at all.
However, if you want Electron to interfere, you can do that. See the WebRequest part of the Electron API. In particular the first method on the page, onBeforeRequest, seems relevant to the requirement mentioned in your comment.

Intercept https requests for a single browser window only

I have two browser windows open, on one window I want to intercept the https request and replace the page content. Currently I'm doing this using using protocol.interceptBufferProtocol and it is working how I want it, but the https requests are being intercepted on the second window and it seems to be causing issues with the page loading.
Is there a way to only intercept requests on a specific window or a way to return the default behavior of the request?
Thanks

What is the difference between using Action.async and WS

I suppose both Action.async and WS (for web services) in Play Framework are based on HTTP and are used to receive HTTP requests and send HTTP responses. Both I suppose are asynchronous and can accept/reply JSON. Action.async could probably send back HTML as well in Response.
So are the two interchangeable if I want to create a micro-service (or a REST API)? Could I use either of them? I saw an example in which a user was added using Action but the list of user’s friends was retrieved using WS.
From Play documentation, it seems WS should be used when calling a HTTP from within the play application. Not sure why though.
‘Sometimes we would like to call other HTTP services from within a Play application. Play supports this via its WS library, which provides a way to make asynchronous HTTP calls through a WSClient instance.’

Javafx webview http response data

Is it possible to read the http request and response data from pages loading inside webview. What i want to do is get the binary data from a response after user clicks on a link inside the page in webview. Any help or clue would be greatly appreciated
Create your own URLStreamHandlerFactory initialized by URL.setURLStreamHandlerFactory which generates a URLStreamHandler that wraps the standard http and https URLStreamHandlers to intercept their traffic before forwarding.
Some of the concepts are explained in A New Era for Java Protocol Handlers whitepaper.
Another option is to listen to the WebEngine.location property and open a separate connection to a server to retrieve and process the binary data as needed. An example of this approach is the pdf handling code for the willow web browser.

Resources