Results 1 to 3 of 3

Thread: [QtWebKit] Inject JavaScript properly when DOM loads..

  1. #1
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy [QtWebKit] Inject JavaScript properly when DOM loads..

    Hi there

    I'd like to make a web browser that can integrate an extension like Greasemonkey (using custom JavaScript scripts).

    I already know about evaluateJavaScript(const QString &scriptSource), but there's... a problem.

    Indeed, I can't inject JS properly. If I call this function using the signal loadStarted(), the JavaScript will be injected before page is rendered, means it won't wok at all. If I call it using the signal loadFinished(), it will be way too slow! Especially when you have a slow internet, like myself...
    The only solution I found is using loadProgress(int), and injecting script around 70% of loading, but it's slow and not accurate.

    I need to find a signal that can tell me if DOM is loaded, like greasemonkey does...

    Do you have any ideas? Thank you in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [QtWebKit] Inject JavaScript properly when DOM loads..

    In my opinion you can't inject the script before the page is fully loaded as the script can reference part of the document that is not loaded yet. You want the script to execute "onLoad", you don't need it earlier. In other words the resources may not be loaded yet but the raw page body has to be fully present (and before onLoad is triggered). You can either intercept the page content before it goes into webkit and inject a onLoad attribute to the body element or simply execute your work with the loadFinished() signal or QWebFrame::initialLayoutCompleted() signal. I'm lazy and I'm triggering my functionality with loadFinished().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    fab_74 (27th March 2011)

  4. #3
    Join Date
    Mar 2011
    Posts
    10
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QtWebKit] Inject JavaScript properly when DOM loads..

    May you live forever. That was EXACTLY what I wanted. It works perfectly with initialLayoutCompleted(). I don't know how I can thank you... thank you so much!

Similar Threads

  1. QTWebKit, out of control Javascript CPU usage
    By Dkamerad in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2014, 06:01
  2. Replies: 3
    Last Post: 21st October 2012, 13:31
  3. Replies: 3
    Last Post: 25th February 2010, 09:53
  4. QtWebKit access HTML manipulated by javascript
    By rbp in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2009, 03:29
  5. QtWebkit and JavaScript error messages
    By Diph in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2009, 12:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.