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

evaluate_js return None always #1503

Closed qaqFei closed 41 minutes ago

qaqFei commented 2 days ago

Specification

Description

in pyinstaller packed, evaluate_js return None always.

use pyinstaller to pack this:

import time
from threading import Thread

import webview

w = webview.create_window("test")

def f():
    time.sleep(3)
    print(w.evaluate_js("1+1;"))

Thread(target=f).start()
webview.start()

微信截图_20241019095504

Practicalities

r0x0r commented 2 days ago

Please try examples/evaluate_js.py and see if you can reproduce the problem.

qaqFei commented 2 days ago

i can reproduce the problem. 7021da4e079f415a8bb5d51993ee97a fb937e2969c22ae7036cc1bf94efb68

qaqFei commented 2 days ago

I ended up finding that on Microsoft.Web.WebView2.WinForms.WebView2, the result I get from the _callback function is None.

qaqFei commented 2 days ago

this func 微信截图_20241019191106

r0x0r commented 2 days ago

Do you get this error when running under pyinstaller or with source as well?

qaqFei commented 1 day ago

不好意思, 我无法理解 c73d2a9e7a5f976ff8af1579de46547

直接使用源码运行不会出现错误

pyinstaller log:

172 INFO: PyInstaller: 6.11.0, contrib hooks: 2024.9
173 INFO: Python: 3.12.0
181 INFO: Platform: Windows-10-10.0.19042-SP0
181 INFO: Python environment: C:\Users\QAQ\AppData\Local\Programs\Python\Python312
197 INFO: wrote C:\Users\QAQ\Desktop\evaluate_js.spec
197 INFO: Module search paths (PYTHONPATH):
['C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\pyinstaller.exe',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\DLLs',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\win32',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\win32\\lib',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\Pythonwin',
 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\setuptools\\_vendor',
 'C:\\Users\\QAQ\\Desktop']
pygame 2.6.1 (SDL 2.28.4, Python 3.12.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
556 INFO: checking Analysis
556 INFO: Building Analysis because Analysis-00.toc is non existent
556 INFO: Running Analysis Analysis-00.toc
556 INFO: Target bytecode optimization level: 0
556 INFO: Initializing module dependency graph...
556 INFO: Initializing module graph hook caches...
572 INFO: Analyzing base_library.zip ...
1400 INFO: Processing standard module hook 'hook-encodings.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
2150 INFO: Processing standard module hook 'hook-heapq.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
2884 INFO: Processing standard module hook 'hook-pickle.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
3852 INFO: Caching module dependency graph...
3946 INFO: Looking for Python shared library...
3946 INFO: Using Python shared library: C:\Users\QAQ\AppData\Local\Programs\Python\Python312\python312.dll
3946 INFO: Analyzing C:\Users\QAQ\Desktop\evaluate_js.py
3962 INFO: Processing standard module hook 'hook-webview.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
4009 INFO: Processing standard module hook 'hook-platform.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
4554 INFO: Processing standard module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
4631 INFO: Processing standard module hook 'hook-xml.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
5084 INFO: Processing pre-safe-import-module hook 'hook-typing_extensions.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
5084 INFO: SetuptoolsInfo: initializing cached setuptools info...
8411 INFO: Processing pre-safe-import-module hook 'hook-gi.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
8505 INFO: Processing standard module hook 'hook-clr.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
8521 INFO: Processing standard module hook 'hook-clr_loader.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
8599 INFO: Processing standard module hook 'hook-pycparser.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
8896 INFO: Processing standard module hook 'hook-setuptools.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
8896 INFO: Processing pre-safe-import-module hook 'hook-distutils.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
8958 INFO: Processing standard module hook 'hook-sysconfig.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
8958 INFO: Processing pre-safe-import-module hook 'hook-jaraco.functools.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
8972 INFO: Setuptools: 'jaraco.functools' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.jaraco.functools'!
8973 INFO: Processing pre-safe-import-module hook 'hook-more_itertools.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
8973 INFO: Setuptools: 'more_itertools' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.more_itertools'!
9096 INFO: Processing pre-safe-import-module hook 'hook-packaging.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9112 INFO: Processing standard module hook 'hook-packaging.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
9184 INFO: Processing pre-safe-import-module hook 'hook-jaraco.text.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9184 INFO: Setuptools: 'jaraco.text' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.jaraco.text'!
9189 INFO: Processing standard module hook 'hook-setuptools._vendor.jaraco.text.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
9189 INFO: Processing pre-safe-import-module hook 'hook-importlib_resources.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9189 INFO: Setuptools: 'importlib_resources' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.importlib_resources'!
9204 INFO: Processing pre-safe-import-module hook 'hook-zipp.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9204 INFO: Setuptools: 'zipp' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.zipp'!
9220 INFO: Processing pre-safe-import-module hook 'hook-jaraco.context.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9220 INFO: Setuptools: 'jaraco.context' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.jaraco.context'!
9392 INFO: Processing pre-safe-import-module hook 'hook-backports.tarfile.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9392 INFO: Setuptools: 'backports.tarfile' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.backports.tarfile'!
9470 INFO: Processing standard module hook 'hook-backports.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
9532 INFO: Processing pre-safe-import-module hook 'hook-importlib_metadata.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9532 INFO: Setuptools: 'importlib_metadata' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.importlib_metadata'!
9548 INFO: Processing standard module hook 'hook-setuptools._vendor.importlib_metadata.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
9720 INFO: Processing pre-safe-import-module hook 'hook-tomli.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
9720 INFO: Setuptools: 'tomli' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.tomli'!
10095 INFO: Processing standard module hook 'hook-pkg_resources.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
10392 INFO: Processing pre-safe-import-module hook 'hook-platformdirs.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
10392 INFO: Setuptools: 'platformdirs' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.platformdirs'!
10485 INFO: Processing pre-safe-import-module hook 'hook-wheel.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
10485 INFO: Setuptools: 'wheel' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.wheel'!
10829 INFO: Processing standard module hook 'hook-difflib.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
11141 INFO: Processing standard module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'
11204 INFO: Processing module hooks (post-graph stage)...
11282 INFO: Performing binary vs. data reclassification (21 entries)
11298 INFO: Looking for ctypes DLLs
11329 INFO: Analyzing run-time hooks ...
11329 INFO: Including run-time hook 'pyi_rth_inspect.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
11344 INFO: Including run-time hook 'pyi_rth_pkgres.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
11344 INFO: Including run-time hook 'pyi_rth_pkgutil.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
11344 INFO: Including run-time hook 'pyi_rth_multiprocessing.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
11344 INFO: Including run-time hook 'pyi_rth_setuptools.py' from 'C:\\Users\\QAQ\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
11360 INFO: Looking for dynamic libraries
11704 INFO: Extra DLL search directories (AddDllDirectory): []
11704 INFO: Extra DLL search directories (PATH): []
11876 INFO: Warnings written to C:\Users\QAQ\Desktop\build\evaluate_js\warn-evaluate_js.txt
11938 INFO: Graph cross-reference written to C:\Users\QAQ\Desktop\build\evaluate_js\xref-evaluate_js.html
11969 INFO: checking PYZ
11969 INFO: Building PYZ because PYZ-00.toc is non existent
11969 INFO: Building PYZ (ZlibArchive) C:\Users\QAQ\Desktop\build\evaluate_js\PYZ-00.pyz
12672 INFO: Building PYZ (ZlibArchive) C:\Users\QAQ\Desktop\build\evaluate_js\PYZ-00.pyz completed successfully.
12688 INFO: checking PKG
12688 INFO: Building PKG because PKG-00.toc is non existent
12688 INFO: Building PKG (CArchive) evaluate_js.pkg
12704 INFO: Building PKG (CArchive) evaluate_js.pkg completed successfully.
12719 INFO: Bootloader C:\Users\QAQ\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\run.exe
12719 INFO: checking EXE
12719 INFO: Building EXE because EXE-00.toc is non existent
12719 INFO: Building EXE from EXE-00.toc
12719 INFO: Copying bootloader EXE to C:\Users\QAQ\Desktop\build\evaluate_js\evaluate_js.exe
12735 INFO: Copying icon to EXE
12735 INFO: Copying 0 resources to EXE
12735 INFO: Embedding manifest in EXE
12735 INFO: Appending PKG archive to EXE
12735 INFO: Fixing EXE headers
12797 INFO: Building EXE from EXE-00.toc completed successfully.
12797 INFO: checking COLLECT
12797 INFO: Building COLLECT because COLLECT-00.toc is non existent
12797 INFO: Building COLLECT COLLECT-00.toc
12844 INFO: Building COLLECT COLLECT-00.toc completed successfully.
r0x0r commented 41 minutes ago

Fixed in 5.3.1