[英]How to enable incognito mode in PyQtWebEngine?
我正在使用 PyQtWebEngine 制作 web 瀏覽器,但我將如何在其中提供隱身模式的功能。
答案就在我在上一篇文章中已經指出的示例中: WebEngine Widgets Simple Browser Example 。 在實現私人瀏覽部分,他們指出提供與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_())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.