2 08. App Debugging
nothingismagick edited this page 2020-01-03 11:45:21 +01:00

Debugging

With all the moving pieces in tauri, you may need to investigate what is happening - or going wrong. There are several consoles that will help you discover what's going on where and give you insight into what is going wrong.

Rust Console

When you run a tauri app (except when it has been bundled and you are running that bundle) you will have a rust console available. This is in the terminal where you ran e.g. tauri dev. You can use the following code to print something to that console from within a rust file:

println!("Message from rust: {}", msg);

Sometimes you may have an error in your rust code, and the rust compiler can give you lots of information. If, for example, tauri dev crashes, you can rerun it like this on Linux and MacOS:

RUST_DEBUG=1 tauri dev

or like this on MS Windows:

set RUST_DEBUG=1
tauri dev

This will give you a granular stack trace. Generally speaking, the rust compiler will help you by giving you detailed information about the issue, such as:

For more information about this error, try `rustc --explain E0433`

Webview JS Console

Linux & MacOS

Right click in the webview, and choose Inspect Element. This will open up a web-inspector, as you are used to seeing and using it.

Windows

If you enable the Edge backend (web-view = { version = "*", features = ["edge"] } in Cargo.toml) you can use the standalone Edge DevTools app.

This enables you to connect the dev tools to your Rust-backed web view as if it were a normal Edge window. (Thanks to @dkaste for providing the solution in this issue.

If you are using MSHTML, then you will probably have to use firebug:

<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>

See this thread for more information.

Create a debugging BUILD

There are cases where you might need to inspect the JS console in the final bundle, so tauri provides a simple command to create a debugging bundle:

local:  yarn tauri build --debug
global: tauri build --debug

Like the normal build and dev processes, the first time you run this it will take more time than subsequent runs. However, the final bundled app will be placed in src-tauri/target/debug/bundle. That app will ship with the development console enabled.

Run your app from the terminal

You can also run a built app from the terminal, which will also give you the rust compiler notes (in case of errors) or your println messages. Just find the file src-tauri/target/release/app and either double click it (but be warned, the terminal will close on errors) or just run it in directly in your console.

Next Step:

Modes