Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

python - Open new blank window to perform social login using QWebEngineView in PyQt5

I was trying develop a webview app using QWebEngineView. The site uses social login (using firebase).

When I user click on login (say, facebook login), a popup opens. The user can login throught the new window and the window close after successfully login/failed to login.

By default the QWebEngineView doesn't suppor popup window, so I wrote

class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
    def createWindow(self, _type):
        page = WebEnginePage(self)
        page.urlChanged.connect(self.on_url_changed)
        return page

    @QtCore.pyqtSlot(QtCore.QUrl)
    def on_url_changed(self, url):
        page = self.sender()
        self.setUrl(url)
        print(url)
        page.deleteLater()

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.browser = QtWebEngineWidgets.QWebEngineView()
        page = WebEnginePage(self.browser)
        self.browser.setPage(page)
        self.browser.load(QtCore.QUrl("targeted_login_page"))

so that the popup window can be catched. It was a success but at the last step there appers a blank screen. If I try to refresh the page I got this error: Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared.

Then I tried the same process with android Native webview. And from the logcat, I got the message Scripts may close only the windows that were opened by them..

I think this is happening because the main window (which opened the new window) is no longer openned. So that the new window can't pass the data to the main window.

question from:https://stackoverflow.com/questions/66058470/open-new-blank-window-to-perform-social-login-using-qwebengineview-in-pyqt5

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...