Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Invoke event listener in windows safely to avoid causing uncaught errors in windows that have loaded external urls #5563

Merged

Conversation

0rvar
Copy link
Contributor

@0rvar 0rvar commented Nov 6, 2022

When opening a tauri window with an External URL, events sent with emit_all, including internal events like tauri://window-created, are still delivered.
Since these windows have not loaded the necessary code, the invocation fails and causes an uncaught javascript error in the window's webview.

Functionally speaking, this is fine, but it's not very neat and has some noticeable effects:

  • These errors will show up in the target websites error logging, if such is implemented.
  • During development of apps with an error view, these errors will show up as a big modal covering the content - see screenshot below.

Screenshot 2022-11-06 at 21 31 15

Screenshot 2022-11-08 at 21 38 50

This PR adds a simple safeguard that checks that the listener function exists before calling it.

What kind of change does this PR introduce?

  • Bugfix

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Implementation approach briefly discussed here: https://discord.com/channels/616186924390023171/986184094050316358/1038527853236592661

@0rvar 0rvar requested a review from a team as a code owner November 6, 2022 20:54
@0rvar 0rvar force-pushed the fix-events-emitted-in-external-url-windows branch from c63520d to 7af5edc Compare November 9, 2022 08:30
lucasfernog
lucasfernog previously approved these changes Dec 8, 2022
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason to use var instead of let?

core/tauri/src/manager.rs Outdated Show resolved Hide resolved
core/tauri/src/window.rs Outdated Show resolved Hide resolved
Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
@lucasfernog lucasfernog merged commit c14b1df into tauri-apps:dev Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants