0

I know how to communicate between C++ and Javascript in Qt WebEngine from this tutorial: https://myprogrammingnotes.com/communication-c-javascript-qt-webengine.html

But that is a case when I'm the author of loaded page so C++ and HTML parts are programmed by me. But is it possible to catch any javascript executed on any page loaded (like google.com etc)? Some kind of signal emitted when JS is executed so I could investigate function name and input args.QWebEnginePage->QWebEngineScriptCollection->scripts() return only my own injected scripts, it doesn't contain page scripts

Regards

Dibo
  • 1,159
  • 17
  • 34
  • QWebEnginePage::scripts() only returns the default scripts that are injected by the Qt developer, not by the developer of a web page. On the other hand there is no method to catch the detection of the execution of js. I think you have an XY problem, you could indicate what your goal is. – eyllanesc Feb 02 '20 at 22:53
  • Yes, that is what I thought `QWebEnginePage::scripts()` is for. About my goal: let say that I want to detect when user pause or change song on Spotify web player and do some thing on C++ side, this is a good example of what I want to do. Changing song on Spotify doesn't trigger urlchanged signal like for example on YouTube. Spotify is using internal javascripts – Dibo Feb 02 '20 at 23:16
  • With what you indicate valid my suspicion that you have an [XY problem](https://meta.stackexchange.com/questions/66377). That is another thing that could be done so I recommend you rewrite your question indicated that more realistic objective. – eyllanesc Feb 02 '20 at 23:20
  • Yes I agree but Spotify was only example and it is not main subject. General question is handling javascripts from webpage. In my tool I want to list them and notify when one is executed, some kind of inspection tool what uBlock or NoScript plugins for Chrome do – Dibo Feb 03 '20 at 00:14
  • uBlock does not track javascript changes but HTTP requests similar to adblock something that can be done with QWebEngineView as I show in this answer: https://stackoverflow.com/questions/53330056/pyqt5-pyside2-adblock/53330741#53330741. On the other hand I have not analyzed what NoScript does. – eyllanesc Feb 03 '20 at 00:18
  • I recommend you ask for something specific since your question is very generic, making your question probably not answered. – eyllanesc Feb 03 '20 at 00:20
  • NoScript does something similar to adblock or other blocking services: it analyzes the requests (http, https, etc.) and accordingly enables or disables the request. For example, let's say that you want the requests of the pages you access to only use secure sources, that is https, then any other http request will be blocked. – eyllanesc Feb 03 '20 at 00:56
  • Well, I'm pretty sure No. uBlock and NoScript are modyfing web content (for example by removing ads probably by analyzing
    . So it is something do on the fly. That is easy to do in QWebEngine but as I said it is not a case. uBlock plugin for Chrome (or Opera, Brave and even FireFox) has also feature which shows running scripts on the fly, with args and everything you want to know, as some kind of inspector tool for devs originaly added in webbrowsers. So it looks like uBlock can investigate everything what is going on on the webpage
    – Dibo Feb 03 '20 at 01:51
  • Personaly I think that it is Chrome and its WebExtensions, something which Chromium doesn't have (and QWebEngine is based on Chromium) – Dibo Feb 03 '20 at 01:51
  • Exactly, chromium and Qt WebEngine do not support extensions, but that does not imply that this layer cannot be implemented as Google-Chrome did, obviously that cannot be done with few lines of code but you can take as a basis the code of my answer that I pointed out in the previous comments, something similar based on workscript has implemented qutebrowser. – eyllanesc Feb 03 '20 at 01:56

0 Answers0