PyQt and WebKit integration: unexpected limitation [fixed]
By Romain Wednesday, September 10 2008 - 09:27 UTC - Tech - Permalink
By Romain Wednesday, September 10 2008 - 09:27 UTC - Tech - Permalink
For the one that don't know Qt, this is a huge and mature framework for developing GUI & more on different platform (to read, multi-platform). I already did some development using Qt and C++ (especially when I was working at the GERAD).
As, with Marcin, we wanted to have a look at some technologies that involved a browser etc. I decided to look at Qt and the almost-fresh WebKit integration.
The integration of WebKit in a framework like Qt, allows the developer to embed supposedly in a easy manner a browser that supports the basic web technologies which are HTML, CSS and JavaScript (it seems that Flash is going to be supported soon, and anyway, one can write its own plugin in order to interact with some specific content) in its application.
And indeed it is easy... I used PyQt in order to develop a very simple prototype and see what we are able to do with this new technology. As I know already Python and Qt, it was easy to me to start and be kinda effective. So, in few hours of work, documentation reading and trying to understand why and how the Python version of Qt was using such or such thing compared to the C++ version, I got this workable browser that allows dynamic JavaScript injection through a console, view the source and a simple encoding converter (click on the image to see the full screen-shot):
At this point, I was actually very excited, less than 500 lines of Python in order to create that... was kinda worth few days of work in order to create a useful tool: the Swiss Army Knife of the Pen-Test.
My next and logic step was to extend the current tool in order to have the tamper-data like capabilities (eg. being able to hijack the HTTP request and then tampering the GET/POST data).
And here come the problems... it's apparently not possible to get the current request then reply when using the WebKit widget in Qt (QWebView). I tried to use a delegate QNetworkAccessManager in order to overload the POST/GET request since this object is use to set the proxies etc. but nothing... I think they just didn't open this possibility for some reason.
Oh well, I then stop developing this prototype and will try to contact Qt experts/developers just to figure out if there is no other way to do it. I thought of a solution which would be to have my own HTTP manager using QHttp in order to do the request, get the response etc. and then sending the content to the browser; this would be great in a webapps scanner, but for the use that I wanted with, that would create huge limitation for the user-interaction and especially for Ajax applications. So, the prototype stays here until I find a solution or Qt open their network management under the QWebView widget...
Fixed:
An update to let you know that I actually fixed the problem, it was really stupid from me, but I should really care when the method are virtual or not before overloading it or not :/ shame on me!
So now, I am able to have a firefox/tamper-data/firebug in one tool :)
Comments
Nice looking tool, I was thinking of creating one along the same lines as you, but for some reason I can't get the proxy stuff to work right.. can you give a good example..?
Hello, I'm seeking informations about the interaction between a little JavaScript program in a HTML page and an PyQt application wich open this HTML page with QWebView.
Do you have some hints ?
Hello and thanks for your answer. For example with the following HTML page opened in QWebView, how can a PyQt application knows the value of the javascript variable nom, and how can we define a slot wich will tell to the PyQt application that the function affiche() has been called ?
The HTML page is here : http://christophe_bal.club.fr/TestJ... .
With this kind of feature it would be possible to use HTLM pages to show pictures and then to know on wich picture the user has clicked.
I believe that 4.5 will introduce better functions for what you wanna do, but for the mean time, I would suggest you to simply use the function:
QWebFrame::evaluateJavaScript
You can simply get the output of it (as QVariant if I remember correctly).
"I believe that 4.5 will introduce better functions for what you wanna do". Where is there information about that ? I think that I will be patient.
The functionnality using JS is not essential in my project for the moment. Indeed, I would like to make a simple interface to SymPy, so I would like the formulas to appear as pictures, and that's why I would need to know which formula is clicked.
Nice project! I read somewhere that 4.5 would introduce javascript debugging capabilities -- this would require a better manipulation of javascript components (DOM, AST, etc.).
edit: Hmm, my mistake, it's for 4.6:
http://labs.trolltech.com/blogs/200...
Thanks for all of this.
Thanks... I had a hard time figuring out where to start myself... By the way in case anybody else is looking for an example I found one here:
http://diotavelli.net/PyQtWiki/Usin...
Hello, this project seams to be interesting ! Did you released the source code ? (I'm interested about it.)
Check it out here: https://bitbucket.org/neuroo/blacks...
It's an awesome piece of work!