Bug in QWebEngineProfile::setNotificationPresenter

Florian Bruhin me at the-compiler.org
Fri May 22 11:03:25 BST 2020

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:


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


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, 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)


notifications = []

def close_notifications():
    for notification in notifications:

def show_notification(notification):
    QTimer.singleShot(1000, close_notifications)



-------------- 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/20200522/4f34e75d/attachment.sig>

More information about the PyQt mailing list