I am trying google sign in with firebase and trying to load the page through pywebview.
from tkinter import *
import webview as webview
root = Tk()
win_width = root.winfo_screenwidth()
win_height = root.winfo_screenheight()
root.geometry("%dx%d" % (win_width, win_height))
webview.create_window(title='My Window', url='http://localhost:81',confirm_close=True)
webview.start()
root.destroy()
When opened, with browser it works fine. but when opened with my code and clicked on sign in, it shows
Unable to establish a connection with the popup. it may have been blocked by the browser.
What is the solution?
3
Answers
What’s going on?
As the error message says, the browser you use with the
webview
library (or actually a renderer) most probably does not allow popups.The code you provided does not fire any popups, but as you mentioned Firebase authentication in the tags, I believe it happens during this stage.
Solution
If this issue happens during the Firebase authentication indeed, the simplest solution would be to use the
auth.signInWithRedirect()
instead ofauth.signInWithPopup()
(see the documentation for more info).If you care about popups in general, you could try to change the renderer settings or even the renderer itself, however, it would be more troublesome.
This error message is usually caused by the browser’s popup blocker preventing the popup window from opening. To work around this issue, you can try disabling the popup blocker in your browser or configuring your browser to allow popups from the localhost domain.
Another solution is to use a different library to create a window for your webview, such as
pywebview
which allows you to create a window with JavaScript disabled. This can help to prevent the browser’s security features from blocking the popup window.You can try to add the following lines of code before creating the window
Also, for the localhost to work, you need to run your application on localhost. You can use any local server like XAMPP or
python -m http.server
command.You can also try using IP address instead of localhost and see if that works.
This happened to me before and the reason for me was that the default option for the webview was not allowing popups.
You can add new_instance: True when creating the window, so it allows the webview to open a new window.
or another option you can check if your browser blocks popups and allow them if so.