2

我已经开始将一些 QWebView 小部件嵌入到我的桌面应用程序 (PyQt) 中。
我使用 JQuery 和 CSS 来增强外观和可用性。
使用网络检查器调试我的 html 代码会很舒服。
如何在我的 QWebView 小部件中嵌入 Firebug Lite?

例如,我尝试了以下代码,但它不起作用:

html1 = """
<html debug="true">
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js#startOpened=true"></script>
    <script type="text/javascript">
    $(document).ready(function() { 
        $("body").css("background", "#f00");
        console.log("in here");
    });
    </script>

</head>
<body><h1>Hello!</h1></body>
</html>
"""
html2 = """
<html debug="true">
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.js"></script>
    <script type="text/javascript">
    $(document).ready(function() { 
        $("body").css("background", "#f00");
        var firebugLite = document.createElement("script");
        firebugLite.src = "https://getfirebug.com/firebug-lite.js";
        firebugLite.id = "firebug_lite";
        firebugLite.textContent = "{ startOpened: true }";
        document.getElementsByTagName("head")[0].appendChild(firebugLite);
        console.log("in here");
    });
    </script>
</head>
<body><h1>Hello!</h1></body>
</html>
"""    

if __name__ == '__main__':
    app = QApplication(sys.argv)
    view = QWebView()
    frame = view.page().mainFrame()
    frame.setHtml(html2)
    view.show()
    app.exec_()

html1 和 html2 具有相同的效果:body 变为红色但 Firebug 不显示。

PS 我的实际 html 代码无法使用外部客户端浏览器进行调试,
因为它使用 QT 资源和应用程序窗口对象。

4

1 回答 1

3

我已将此 JavaScript 添加到基于 WebKit 的项目中,也许这对 QWebView 也有帮助?

var firebugLite = document.createElement("script");
firebugLite.src = "https://getfirebug.com/firebug-lite.js";
firebugLite.id = "firebug_lite";
firebugLite.textContent = "{ startOpened: true }";
document.getElementsByTagName("head")[0].appendChild(firebugLite);
于 2011-06-18T19:15:52.507 回答