本文介绍了如何在 PyQtWebEngine 中启用隐身模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a web browser using PyQtWebEngine but how will I give the feature of incognito mode in it.

推荐答案

答案就在我在之前的帖子中已经指出的示例中:WebEngine 小部件简单浏览器示例.在实施隐私浏览 部分他们指出提供一个 QWebEngineProfile() 不同于 QWebEngineProfile::defaultProfile() 因为后者默认为所有页面共享,这是在隐私浏览中不会搜索的内容.

The answer is in the example that I already pointed out in a previous post: WebEngine Widgets Simple Browser Example. In the Implementing Private Browsing section they point out that it is enough to provide a QWebEngineProfile() different from QWebEngineProfile::defaultProfile() since the latter is shared by all pages by default, which is what is not searched for in a private browsing.

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_())

这篇关于如何在 PyQtWebEngine 中启用隐身模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:20