How to inject script on all subframes with callback in Qt WebEngine

Viewed 18

I need to inject a script that will run on all the subframes of the page, but also be able to get the result in a callback. I also don't have access to the page before it is created, so in 99.99% of the time my injected script will be injected after the page has fully loaded.

The QWebEnginePage::runJavaScript method is perfect, but it only runs in the main frame.

The only method I found for a script to run in all subframes is to use an QWebEngineScript and insert it in the QWebEnginePage::scripts(). There are two issues with this, as far as I tested:

  1. If I insert it after the page loads, the script is never run
  2. It doesn't provide support for callbacks. The only solution to this I have found is QWebChannel. I'd wish to avoid that at all costs, but can't go into details about why. In worst case scenario I will use webchannels if I can get over pt. 1

So my question is: how can I inject a script into a page after it loads and have it execute in all subframes?

0 Answers
Related