Home > Net >  How to run JavaScript code before document is fully loaded with QWebEngineView?
How to run JavaScript code before document is fully loaded with QWebEngineView?

Time:10-27

I would like to evaluate JavaScript before page's document is constructed and its scripts evaluated, in essence emulating Page.addScriptToEvaluateOnNewDocument of Chrome Devtools Protocol.

I tried to evaluate the JS code on loadStarted and loadProgress events of QWebEngineView but the script was evaluated only after page fully loaded.

CodePudding user response:

You can use the QWebEngineScript to do this. It allows you to set an injection point and execution world for your script (similar to e.g. greasemonkey).

  • Related