r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.7k stars 552 forks source link

Error occers when `alert()` is called with non-string arguments #1506

Open yunline opened 14 hours ago

yunline commented 14 hours ago

Specification

Test Code:

import webview

html = """
<head>
<script>
function click_me() {
    // alert("hello") // this won't cause an error
    alert({hello:"world"}) // err
    // alert(114514.1919) // err
    // alert([1,2,3,4,5]) // err
};
</script>
</head>

<body>
<button style="width: 150px; height: 50px;", onclick="click_me()">Click me</button>
</body>
"""

window = webview.create_window('Window', html=html)
webview.start(debug=True)

Behavior:

Click the button, the messagebox is not out, an error occered. Error message:

[pywebview] Exception occurred during on_script_notify
Python.Runtime.PythonException: 'dict' value cannot be converted to System.String

The above exception was the direct cause of the following exception:

System.ArgumentException: 'dict' value cannot be converted to System.String in method System.Windows.Forms.DialogResult Show(System.String) ---> Python.Runtime.PythonException: 'dict' value cannot be converted to System.String
   --- 内部异常堆栈跟踪的结尾 ---

The above exception was the direct cause of the following exception:

System.AggregateException: 发生一个或多个错误。 ---> System.ArgumentException: 'dict' value cannot be converted to System.String in method System.Windows.Forms.DialogResult Show(System.String) ---> Python.Runtime.PythonException: 'dict' value cannot be converted to System.String
   --- 内部异常堆栈跟踪的结尾 ---
   --- 内部异常堆栈跟踪的结尾 ---
---> (内部异常 #0) System.ArgumentException: 'dict' value cannot be converted to System.String in method System.Windows.Forms.DialogResult Show(System.String) ---> Python.Runtime.PythonException: 'dict' value cannot be converted to System.String
   --- 内部异常堆栈跟踪的结尾 ---<---

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\yunline\AppData\Local\Programs\Python\Python311\Lib\site-packages\webview\platforms\edgechromium.py", line 194, in on_script_notify 
    WinForms.MessageBox.Show(func_param)
TypeError: No method matches given arguments for MessageBox.Show: (<class 'dict'>)
yunline commented 14 hours ago

Bug reproduce video : https://github.com/user-attachments/assets/43e87a23-eb81-44ea-b063-7db8d617e4c6