QWebInspector: how to switch tab manually

When I use QWebInspector (python, PyQT4), it always opens with the Elements tab turned on by default.
Is there a way to programmatically switch a tab to the network?

Now it looks like this: QWebInspector opens "Elements" tab

What I want to see: enter image description here

Script source:

import sys, PyQt4.QtCore, PyQt4.QtGui, PyQt4.QtWebKit if __name__ == '__main__': app = PyQt4.QtGui.QApplication(sys.argv) webview = PyQt4.QtWebKit.QWebView() inspector = PyQt4.QtWebKit.QWebInspector() webview.page().settings().setAttribute( PyQt4.QtWebKit.QWebSettings.DeveloperExtrasEnabled, True ) inspector.setPage(webview.page()) inspector.showMaximized() webview.load(PyQt4.QtCore.QUrl('http://yahoo.com')) app.exec_() 

Of course, the appropriate C ++ / QT method is suitable! Thanks!

+4
source share
1 answer

WebInspector is network based. You will need to get the first and only child inspector, this will be a QWebView.

Like:

 QList<QWidget*> list = inspector.findChildren<QWidget *>(); QWebView* wv =(QWebView*) list.at(0); 

Then connect to the javaScriptWindowObjectCleared signal of this view, and in the connected slot, execute javascript. For this you need an object. I called it someObject for example

 QObject::connect( wv->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), someObject, SLOT(openNetworkTab()) ); 

add a slot to someObject class:

 void openNetworkTab(){ wv->page()->mainFrame()->evaluateJavaScript("document.addEventListener('DOMContentLoaded',function(){setTimeout(function(){document.querySelector('.toolbar-item.network').click()},200);});"); } 

Delay 200 only to wait for all event bindings to initialize until the button is clicked

All classes of the inspector tab are listed here, just in case: .elements, .resources, .net, .scripts, .timeline, .profiles, .audits, .console

+2
source

Source: https://habr.com/ru/post/1502275/


All Articles