QtWebKit calls QWebPage::loadFinished ( false )
when a web page failed to load - but gives no clue as to why it failed.
How do I get a detailed error message, like HTTP response code or other message?
It turns out there are a couple ways to get more detail about failures:
Implement the onResourceRequested
and onResourceReceived
callbacks on page:
page.onResourceRequested = function (resource) {
log('resource requested: ' + resource.url);
}
page.onResourceReceived = function (resource) {
log('resource received: ' + resource.status + ' ' + resource.statusText + ' ' +
resource.contentType + ' ' + resource.url);
}
If you are looking for more detail still, you need to patch PhantomJS internals. Update its CustomPage object (in WebPage.cpp) to implement QTWebKit's ErrorExtension. Here is code you can add that does that:
protected:
bool supportsExtension(Extension extension) const {
if (extension == QWebPage::ErrorPageExtension)
{
return true;
}
return false;
}
bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0)
{
if (extension != QWebPage::ErrorPageExtension)
return false;
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
std::cerr << "Error loading " << qPrintable(errorOption->url.toString()) << std::endl;
if(errorOption->domain == QWebPage::QtNetwork)
std::cerr << "Network error (" << errorOption->error << "): ";
else if(errorOption->domain == QWebPage::Http)
std::cerr << "HTTP error (" << errorOption->error << "): ";
else if(errorOption->domain == QWebPage::WebKit)
std::cerr << "WebKit error (" << errorOption->error << "): ";
std::cerr << qPrintable(errorOption->errorString) << std::endl;
return false;
}
This will give you most of the error information, but you can still get onLoadFinished(success=false)
events without getting more detail. From my research, the primary cause of those is canceled load requests. QTWebKit sends a fail notification for cancellations, but doesn't report any detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With