Re: Bug in QWebEngineProfile::setNotificationPresenter
Florian Bruhin <[email protected]> Fri, 22 May 2020 12:03:25 +0200
| Newsgroups | gmane.comp.python.pyqt-pykde |
|---|---|
| Message-ID | <[email protected]> |
On Fri, May 22, 2020 at 09:35:55AM +0100, Phil Thompson wrote: > On 21/05/2020 10:42, Florian Bruhin wrote: > > Hi, > > > > When running the attached example and clicking "authorize", then "show" > > 2-3 > > times, either a segfault or an exception like this will happen: > > > > TypeError: 'QWebEngineNotification' object is not callable > > > > As a workaround, show_notification_2 can be used instead, which > > re-registers > > the callback and makes things work fine. > > > > Looking at the implementation of setNotificationPresenter in > > qwebengineprofile.sip, it does "Py_DECREF(a0);", inside its wrapper, > > with a0 > > being the passed function. That seems to be wrong, as the function gets > > called > > multiple times with multiple notifications. > > > > Compare that to e.g. setCookieFilter in qwebenginecookiestore.sip where > > the > > callback isn't DECREF'd. > > Should be fixed in tonight's snapshot. Thanks! There seems to be a similiar issue surrounding the lifetime of the QWebEngineNotifcation object, though. Based on Qt's example, it should be possible to store the notification in the presenter and later e.g. call .click() or .close() on it: https://github.com/qt/qtwebengine/blob/v5.14.2/examples/webenginewidgets/notifications/notificationpopup.h#L132 However, when doing the same in PyQt (like simulated in the attached example), it looks like PyQt already deleted the underlying QWebEngineNotification object (probably because it uses an unique_ptr in its callback?): RuntimeError: wrapped C/C++ object of type QWebEngineNotification has been deleted Florian -- [email protected] (Mail/XMPP) | https://www.qutebrowser.org https://bruhin.software/ | https://github.com/sponsors/The-Compiler/ GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc I love long mails! | https://email.is-not-s.ms/
notifications2.py
(text/plain, 982 B)
import sys
from PyQt5.QtCore import QUrl, QTimer
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage, QWebEngineProfile
app = QApplication(sys.argv)
view = QWebEngineView()
def handle_feature_permission(origin, feature):
view.page().setFeaturePermission(origin, feature, QWebEnginePage.PermissionGrantedByUser)
view.page().featurePermissionRequested.connect(handle_feature_permission)
notifications = []
def close_notifications():
for notification in notifications:
notification.close()
def show_notification(notification):
QWebEngineProfile.defaultProfile().setNotificationPresenter(show_notification)
print(notification.message())
notifications.append(notification)
QTimer.singleShot(1000, close_notifications)
QWebEngineProfile.defaultProfile().setNotificationPresenter(show_notification)
view.load(QUrl("https://www.bennish.net/web-notifications.html"))
view.show()
app.exec_()
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE4E5WAAJAG47w528KkW6wyP1VoHIFAl7Ho2oACgkQkW6wyP1V oHKNOQ//bRE22djSMTrfQOQVOuRT4GUU1iRqLG4fHoYQmcPMlmFGk7YLAgjX6Y4K v59GONjHttkV0qvmC5VOaVbcCdeu8/Fi2CqnfitiUBTXb2NygRUtBAVs9kQ6rXXm aWmP7w6X7f7OyLok0pWJ/U9wCXakejPULLKmtOvwnyVY7mSdwoaqAn9jqW7uDOH/ /MnB5uP0M5VB7ewAoFb2M3b6DPx3cn5BdZa0I5S6+wrGS7dncKGQ3h/AOdmH7Srx HDl2VY0oWFE/0ZrCF21O1NWpcicJg7cPqgu5dSUbWfan8DgsEIGYceQcEjHrMqto P7KcrICT598paiMrJrSAiR7MPteLYnzX4EfU8Lx4r+I+cvRizbVtMTeU2N6CeK7s yiqu+wJnuk9abyCGSrDrUVi+vy+Z4B1EA7duMYB4OXacM5Upf0JkdbEbIbsdHO6A oQ845NdLcTGjTiNCidks/0MwlGNJO0DcFNfvznCmSBMTItXOGzawo3qGOgQlHklh UZArScZlEHBjRPuV+MRNANrg1GlCqznwuQU1BaLsQ1Q0ww19G3EM3iD/PoXyf8eP ChRfZDgyf5JOLMCseDnP7SS6s79+2J9MPyVjTKO7or86v7yiOtoPadbEheDmki9i Fk4YbovV9hd7j+CRzxK+roWqLflELCTChCBCoSCWRP5LK14fOq0= =B9MP -----END PGP SIGNATURE-----