pywebview icon indicating copy to clipboard operation
pywebview copied to clipboard

Bug: EdgeChromium - state sometimes getting stuck

Open jeanbaptiste444 opened this issue 1 month ago • 4 comments

Hello,

I tried using the new state feature but sometimes the program execution gets stuck. After some investigation, I found that the issue comes from "edgechromium.py" specifically in the "evalutate_js" function.

For some reason, "self.webview.ExecuteScriptAsync(script)" occasionally doesn’t return anything, which means the "_callback" function is never called and the semaphore is never released.

I patched it by initializing the semaphore with "Semaphore(1)" instead of "Semaphore(0)". It seems to work but I'm not sure if this is a good solution.

Have you ever encounter this problem ?

jeanbaptiste444 avatar Nov 10 '25 10:11 jeanbaptiste444

Did you resolve this problem? If not, could you provide a minimal example demonstrating the bug?

r0x0r avatar Nov 16 '25 08:11 r0x0r

Hello, I created a small project that reproduces the bug. You can find it here https://github.com/jeanbaptiste444/pywebview-state-bug-example.git.

Build:

python -m venv env
pip install -e .
python main.py

Explaination: On the home page of this example, when you click the button, a POST form is sent to "/".

def index(self):
        if request.method == "POST":
            for i in range(10):
                print("a")
                self.window.state.progress = f"{i}/10"
                print("b")
       return render_template("index.html")

I added print("a") before and print("b") after state update in the loop. After clicking the button, when you look at the console, only 'a' is printed and the program execution gets stucked on the state update.

jeanbaptiste444 avatar Nov 16 '25 19:11 jeanbaptiste444

I don't know if this helps, but there is no problem when the post request is made from Javascript. I added a second button in my example that shows this.

jeanbaptiste444 avatar Nov 16 '25 19:11 jeanbaptiste444

The problem is in your code. When you submit the form, it results in a page refresh, which resets everything

r0x0r avatar Nov 25 '25 21:11 r0x0r