2

I've started to embed some QWebView widgets to my desktop application (PyQt).
I use JQuery and CSS to enhance appearance and usability.
It would be comfortable to debug my html code with a web inspector.
How can I embed Firebug Lite in my QWebView widgets?

E.g. I tried the following code and it doesn't work:

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 and html2 have the same effect: body turns into red but Firebug doesn't show up.

P.S. my actual html code can't be debug with an external client browser,
because it uses QT resources and application window objects.

pedrotech
  • 1,359
  • 10
  • 19

1 Answers1

3

I've added this JavaScript to my WebKit-based projects, maybe this helps for QWebView as well?

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);
mrk
  • 4,999
  • 3
  • 27
  • 42
  • It doesn't work. I've tried en vain this too: – pedrotech Jun 18 '11 at 19:42
  • Can you edit your question and add your PyQt code, specifically where you set the url or add html? – mrk Jun 18 '11 at 19:57
  • "It doesn't work" -- means you get JS errors? or just no Firebug Lite console/ui? – mrk Jun 18 '11 at 20:51
  • Do you get the small firebug icon in the lower right? I'm guessing not. How about adding a `console.log("in here")` perhaps in a $(document).ready() --- do you get any JS errors from that? – mrk Jun 18 '11 at 21:03