0

I'm programming a very simple Qt-based application which will be interfacing some website. That website requires user to login with username/password and solved Captcha. Because of that Captcha, I decided to use QWebKit and just display the website for the user (and intercept cookies in my app). It works almost great. Almost, because I'm having a really strange problem.

On Linux my app worked like a charm. On 64bit Windows 7 (32 bit build with VS 2010) - it worked without problems too. But the same binary has a very strange issue under 32bit Windows 7. It works, but does not display Captcha images making logging in impossible. Of course, I used Dependency Walker and ensured that all the DLL's are accessible.

The Captcha is not a popular reCaptcha or something, but Minteye slider Captcha (BTW, in my humble opinion it is quite easy to solve by a computer). As you can see at the bottom of the page I linked to, this captcha downloads a series of images and user has to select the "correct" (ungarbled) one with a slider.

The problem is, that for no apparent reason, my app just doesn't show these images on 32bit Windows 7, while on 64bit version everything works. The code I'm using is very simple, but I'm posting it anyway:

loginView       = new QWebView();
QWebPage *page  = new QWebPage();
manager         = new QNetworkAccessManager();

loginView->setPage(page);
page->setNetworkAccessManager(manager);
jar = new QNetworkCookieJar();
manager->setCookieJar(jar);

page->mainFrame()->load(QUrl("http://site.to.open"));
loginView->show();

I verified with Wireshark that these images are indeed being downloaded from the server. I even changed user agent string to hardcoded one to be sure that the server doesn't mess up something only for for 32bit windows 7. Unless I'm missing something, the dialogue with the server is identical and the problem is on client's side.

The only thing that differs (and I'm pretty sure is connected to my problem) is behaviour of WebKit when trying to navigate to specific URL via developer tools (one can enable them in QWebKit, so did I). When I open the Javascript console for login page and enter:

window.location = "http://www.google.com"

It works on all my platforms. But, when I enter the address of one of the Captcha images:

window.location = "http://img2.minteye.com/slider/image.ashx...

Results vary. On Linux and 64bit Windows 7 it works and I can see an image. On problematic 32bit Windows 7, WebKit shows error Frame load interrupted by policy change and that's all. I have no idea what that error means and what "policy" changed. Google search didn't help me - I found posts by people complaining that they see this error, but nobody explained what causes it (WebKit source isn't super helpful too). If somebody knows, I might be able to get a workaround for my problem.

I'm also very courious, why this problem is present only on 32bit version of Windows 7.

user1234567
  • 1,832
  • 1
  • 18
  • 25
  • Hi, so long that I answered, I wonder if you could implement my example for your project. – Protomen May 03 '15 at 08:27
  • 1
    @GuilhermeNascimento: I wasn't working on that project when you posted your answer. I'll check if your solution works when I'll be able to. – user1234567 May 03 '15 at 21:51

2 Answers2

0

Seems like this is/was a bug in QtWebkit implementation, you can read more about it here: https://bugs.webkit.org/show_bug.cgi?id=37597

Which version of Qt and QtWebkit are you using ? It might be a good idea to try a newer version of Qt & QtWekbit.

If it helps in any case here is the code in Webkit which shows this error: http://src.chromium.org/svn/branches/WebKit/472/WebKit2/WebProcess/WebCoreSupport/qt/WebErrorsQt.cpp

Ahmad Mushtaq
  • 1,395
  • 1
  • 10
  • 32
  • I'm using latest stable Qt (4.8.3) which contains WebKit 534.34 (which is about one year old). If I won't find any other solution, I'll try with beta version of Qt 5. Thanks for help - I was thinking it may be a WebKit bug. – user1234567 Nov 26 '12 at 12:33
  • With Qt 5 it doesn't work too. I'm not sure it's the same problem, because developer tools don't work at all. I'm pretty convinced that they didn't update webkit and it's the same as in Qt 4... – user1234567 Nov 26 '12 at 15:14
  • I remember that starting Qt5, the webkit work was seperated from Qt, in order to be more modular. So you might be able to get a new module of QtWebkit, but I am not sure about that. – Ahmad Mushtaq Nov 28 '12 at 05:58
0

This is not a bug.

What happens is that this image was generated dynamically, probably Headers were misconfigured.

the Frame load interrupted by policy change occurs because the WebView tries to open something that is not "text/image" (is not supported).

You should use this ( https://stackoverflow.com/a/16782607/1518921 ):

//replace [QWebView] by your WebView
connect([QWebView]->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(downloadContent(QNetworkReply*)));

...

void [main class]::downloadContent(QNetworkReply *reply){
    //Replace "[main class]" by "Class" having the signs used in WebView.

    [QWebView]->stop();
    //solution: stop loading --replace [QWebView] by your WebView, 

    /*function to donwload*/
}

At this point if you have a download manager, it will ask to save the image instead of opening it, because the content is not supported.

Solutions:

  • What you can do is try to fix image headers.

  • if your server is not then there will be, then you will have to parse the header Content-type and see what type it is trying to send, having kind of content you will have to reimplement the QWebPage:

    virtual bool extension(Extension extension, const ExtensionOption *option = 0,
                           ExtensionReturn *output = 0);
    
    virtual bool supportsExtension(Extension extension) const;
    

Good luck.

Community
  • 1
  • 1
Protomen
  • 9,471
  • 9
  • 57
  • 124