W
W
WD_KMS2020-02-12 17:05:13
Python
WD_KMS, 2020-02-12 17:05:13

How to enable web notifications in QtWebEngine?

from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage

Loading HTML which, when opened in a browser, asks for permission to send web notifications.
self.page = QWebEnginePage()
        self.page.Notifications = True
        self.page.setHtml(html)

using
messaging.requestPermission

But if you run html-ku in WebEngine, then the page itself with scripts is loaded, but the request is not displayed.

How to set the resolution of this from the back side?
Notification.permission
gives denied.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WD_KMS, 2020-02-13
@WD_KMS

class WebEnginePage(QWebEnginePage):
    def __init__(self, *args, **kwargs):
        QWebEnginePage.__init__(self, *args, **kwargs)
        self.featurePermissionRequested.connect(self.onFeaturePermissionRequested)

    def onFeaturePermissionRequested(self, url, feature):
        if feature == WebEnginePage.Notifications:
            self.setFeaturePermission(url, feature, QWebEnginePage.PermissionGrantedByUser)
        else:
            self.setFeaturePermission(url, feature, QWebEnginePage.PermissionDeniedByUser)

view = QWebEngineView()
page = WebEnginePage()
view.setPage(page)
view.load(QUrl("https://"))
page.setHtml(html)
view.show()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question