【问题标题】:How to enable incognito mode in PyQtWebEngine?如何在 PyQtWebEngine 中启用隐身模式?
【发布时间】:2021-06-01 16:46:42
【问题描述】:

我正在使用 PyQtWebEngine 制作一个网络浏览器,但是我将如何在其中提供隐身模式的功能。

【问题讨论】:

    标签: python pyqt5 qtwebengine


    【解决方案1】:

    答案在我在上一篇文章中已经指出的示例中:WebEngine Widgets Simple Browser Example。在Implementing Private Browsing 部分,他们指出提供与QWebEngineProfile::defaultProfile() 不同的QWebEngineProfile() 就足够了,因为后者默认由所有页面共享,这是在私密浏览中不搜索的内容。

    from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
    
    
    class WebView(QtWebEngineWidgets.QWebEngineView):
        def __init__(self, off_the_record=False, parent=None):
            super().__init__(parent)
            profile = (
                QtWebEngineWidgets.QWebEngineProfile()
                if off_the_record
                else QtWebEngineWidgets.QWebEngineProfile.defaultProfile()
            )
            page = QtWebEngineWidgets.QWebEnginePage(profile)
            self.setPage(page)
    
    
    if __name__ == "__main__":
        import sys
    
        app = QtWidgets.QApplication(sys.argv)
    
        view = WebView(off_the_record=True)
    
        view.load(QtCore.QUrl("https://www.qt.io"))
        view.show()
    
        sys.exit(app.exec_())
    

    【讨论】:

      猜你喜欢
      • 2022-11-11
      • 2021-01-09
      • 2022-08-12
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 2015-08-21
      相关资源
      最近更新 更多