Bug in QWebEngineProfile::setNotificationPresenter

Florian Bruhin me at the-compiler.org
Thu May 21 10:42:06 BST 2020


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.

Florian

-- 
me at the-compiler.org (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/
-------------- next part --------------
import sys

from PyQt5.QtCore import QUrl
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)

def show_notification(notification):
    print(notification.message())

def show_notification_2(notification):
    QWebEngineProfile.defaultProfile().setNotificationPresenter(show_notification_2)
    print(notification.message())

QWebEngineProfile.defaultProfile().setNotificationPresenter(show_notification)
# QWebEngineProfile.defaultProfile().setNotificationPresenter(show_notification_2)

view.load(QUrl("https://www.bennish.net/web-notifications.html"))
view.show()

app.exec_()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200521/9bd389a2/attachment.sig>


More information about the PyQt mailing list