I'm implementing an OAuth 2.0 login, which uses a server-side redirect to 'http://localhost/?code=abcdef' to pass the necessary data to the client application.
But the TWebBrowser.BeforeNavigate2 event is not fired in this case.
I've searched my head off, trying to find a way to detect server-side redirects (and handle them myself) within the TWebBrowser control (if possible at all).
As a workaround, I've implemented the TWebBrowser.NavigateComplete2 event. But because there's no HTTP-server running at the localhost (usually) this takes some time before it's fired.
I'd like to detect the redirect before the webbrowser tries to navigate to it and parse the data of URL myself and skip navigating to the localhost.
By default, TWebBrowser does not fire an event for a redirect. OnBeforeNavigate2 is fired for the initial URL before the redirect, and then OnNavigateComplete is fired after the redirect. You can compare the URL provided by the two events to know whether a redirect happened or not.
However, if you enable the browser's DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION flag, you will then get an OnBeforeNavigate2 event for a redirect, and can cancel the redirect if desired.
To enable the flag, you need to implement the IDocHostUIHandler.GetHostInfo() interface method.
If you are using 10.0 Seattle or later, TWebBrowser already implements IDocHostUIHandler for you, so just derive from TWebBrowser and override GetHostInfo() as needed.
Otherwise, for earlier versions, you can write a separate class that implements IDocHostUIHandler, and then you can query the browser for its ICustomDoc interface and call its SetUIHandler() method.
Related
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
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
Is it possible for a Chrome Packaged App to listen to events fired by a webview inside the ChromeApp?
My ChromeApp loads a webview on startup. I would like to be able to fire events from the webview so I can access local chrome.app functions.
The function I would like to use now is "close window" (so I can close the ChromeApp from the webview that is inside the ChromeApp). In the future I would like to be able to access the Storage API from the webview.
<webview> supports a restricted set of standard DOM events out of the box. For your "close window" interception, the aptly named close event is probably the best fit.
If you want to establish a kind of communication channel between a webview guest and your app in the general case, as in your second use case with accessing Storage API, you have a couple of options:
You can use <webview>.contentWindow.postMessage to post messages into the guest page and return replies in the reverse direction.
You can also inject pieces of JavaScript into your webview guest using <webview>.executeScript. This way you can, for example, attach a click event handler to a button within the guest that will do something that you need to do in the execution context of your app (of course, for that your event handler has to be a closure). Or, you can gather some information from within the guest and return in to the app in the executeScript's callback.
Finally, there is <webview>.insertCSS - not a fit for your needs, but I'm mentioning it to complete the set of methods you can use to interact with or alter the webview guest.
i have to develop a java-applet which redirects to another webpage. Normaly i use the "showDocument(URL ul)"-method to do that. But in this case i have to send a lot of data to this page. So i need to do it via POST. But showDocument just allows GET-method.
My question: Is it possible to do a redirect to another webpage from within a japplet AND to send POST Data in the same request (like showDocument() but with POST data)? - I know that i can do a POST request from within the applet - but this will happen in the applet's context.
It's a bit complicated because the script from which the applet is called, runs on a client-auth protected server. So i need to do the requests with the browser (because he will be authenticated) - if i do these requests from within the applet, the applet have to authenticate again...
thanx
daniel
Directly with the Java Applet API this is not possible - showDocument is the only thing you have, and it supports only GET. You may be able to do something like this with the JavaScript bridge (i.e. call javascript functions from the applet, which then send the POST request to the server like the browser would (and show the result in a new browser window), but I never used this.
The reason I don't want to go the browser plugin way is that you need to implement it for various browsers.
Like xpi for firefox, browser helper object for IE.
My target platform is only windows, and I just want the alternative of browser plugin to call a client side programe after instructed when the user is browser the web page.
Is that viable?
The only "viable" solution would be to register a protocol handler system-wide so say addresses starting with "myprotocol://" trigger your app. Users will still need to install your program and your program will only have access to the parameters passed by that protocol handler, so you will have to evaluate on your own if it's worth it.
Also note that some browsers or settings might show a confirmation message before using your new protocol for the first time, so users should be informed on what to do (and warned that this prompt is part of the normal workings of your app).