Repository navigation
[Core] Handle JavaScript injection failures without native callback exceptions - #1854
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The narrow exception-handling changes preserve successful initialization, with no unresolved findings.
0 open findings
What changed in this PR
Hardens pywebview’s shared JavaScript injection path so resource and execution failures are handled without escaping native callbacks or blocking load waiters.
Changes:
- Catches resource-loading and initial injection errors; template errors identify the failing file.
- Adds unit and native-window regressions for failure handling and bridge readiness.
- Documents the behavior in the changelog.
| File | Description |
|---|---|
webview/util.py |
Guards injection failures and improves template diagnostics. |
tests/test_util.py |
Tests failure handling, successful injection, and diagnostics. |
tests/test_js_api.py |
Adds a malformed-resource native-window regression. |
docs/CHANGELOG.md |
Documents the shared injection fix. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Owner
|
@copilot please fix the merge conflicts in this pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JavaScript resource failures currently escape
inject_pywebview()on the native navigation callback's thread. In a contaminated application build, a straycustomize 2.jsretained%(text_select)sbut received no template parameters, raisingKeyErrorthrough Cocoa'swebView_didFinishNavigation_and aborting the process. Missing/unreadable resources reach the same unguarded call. Separately, the initialrun_js(js_code)is outside the worker's exception handler and can leaveloadedwaiters blocked.This change catches resource-loading failures at the shared injection boundary and includes the filename in template-format errors. It also moves the initial script execution inside the existing worker handler. Failure sets
loaded, consistently with the existing API-injection failure path, but never sets_pywebviewready. Scripts are not silently skipped and resource loading/discovery rules stay unchanged.Validation on macOS / Python 3.11:
pytest tests/test_util.py tests/test_js_api.py tests/test_load_html.py -q: 45 passed, including the existing bridge and HTML-loading tests.The fix is in the shared injection code; backend modules are unchanged. Native Windows/Linux/Android backends and the full integration suite have not been run locally.