1

I try to adapt a Web application to use in a GUI, created with PyQt6. When I load the application in QWebEngineView widget I'm capable to debug its JavaScript routines in a normal way using a Chrome browser launched in parallel.
The debugging shows that window.open(...) command in my JavaScript code goes without exceptions/errors and even creates a new window, having window.opener attribute among others.

I don't understand, however, is it possible to view the document of this new window in a certain other widget in my PyQt application and access its content from the main JavaScript code? Should I use QTabWidget or any other one for this?
Or I can control Web documents in other QWebEngineView widgets in my GUI with injected scripts only and forget about window.open(...) command?

  • 1
    The html/js documentation is of little use here, read that related to QWebEnginePage. For instance, [`createWindow()`](https://doc.qt.io/qt-6/qwebenginepage.html#createWindow). – musicamante Aug 23 '22 at 06:53
  • @musicamante, thanks for the suggestion! Indeed it is asserted in the documentation your link point to that "In the cases when the window creation is being triggered by JavaScript, apart from reimplementing this method the application must also set `QWebEngineSettings::JavascriptCanOpenWindows` to true in order for the method to get called". I will check how this might work. – Kostiantyn Ivashchenko Aug 23 '22 at 12:10

1 Answers1

0

You should be able to. The documentation states that window.open returns a windowProxy object, so you should be able to use the returned object from that and traverse the DOM, execute scripts etc.

It would look something like this: var newWindowObj = window.open(...), and then act on the newWindowObj however you need.

Sergey
  • 1,608
  • 1
  • 27
  • 40
  • I already use exactly the same code: `const editableWindow = window.open(window.origin, "EditedPage"); window.myProjectData.editableWindow = editableWindow;`. Unfortunately it doesn't work this way, the stored `editableWindow` is empty. But even if we suggest for a moment the window is available I do not know how to put its content into a PyQt application GUI. – Kostiantyn Ivashchenko Aug 23 '22 at 00:22