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

Open WebView Dev Tools on startup #1213

Closed
rx2347 opened this issue Feb 10, 2021 · 5 comments
Closed

Open WebView Dev Tools on startup #1213

rx2347 opened this issue Feb 10, 2021 · 5 comments
Labels
status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes

Comments

@rx2347
Copy link

rx2347 commented Feb 10, 2021

To debug it'd be very useful to have an option in the tauri.conf.json to open WebView Dev Tools on startup. AFAIK right now this always has to be done by right click and inspect an element, which gets annoying quite quickly if for some reason hot-reloading doesn't do it for you.

@pokecheater
Copy link

Sry but that is not the answer to the question. Thats a shortcut not a valid option to tell tauri always to open the devtools on startup.

@FabianLars
Copy link
Member

@pokecheater The PR linked above includes an example showing how you can open it on startup: 5832300#diff-cfab6e0634dd785c7949c059698552e4e8f6139ccbcdb29aeb6b4c29d57805b7.

issue 3776 linked below that is indeed something else completely but it can use this same api to fix the shortcut (which is probably why this issue was linked).

@pokecheater
Copy link

pokecheater commented Aug 31, 2023

@FabianLars
thx for your answer. I rly appreciate that you try to help me out. But the link just points to some code your dev team has changed. I do not understand it. It just shows me how awesome your dev team is in order to change code (# no sarcasm I think people who are developing in rust must be somekind of inhuman gods).

So here again: How to open the devtools automatically? This question still persists. Is there now a setting inside the tauri.conf.json or do I can open it with some tauri invoke call or something similar? I still have no idea.

thx in advance.

@FabianLars
Copy link
Member

There is no explicit config/setting, only the rust api and i meant to show you the example in the code comment not just the code itself since you'll have to use Rust to make the devtools open at startup.

If you bootstrap a new tauri app your main.rs file will have a small main function that should look like this

// [...]

fn main() {
   tauri::Builder::default()
     .invoke_handler(tauri::generate_handler![greet])
     .run(tauri::generate_context!())
     .expect("error while running tauri application");
}

Then we'll need to adapt it according to the example from above:

// [...]

use tauri::Manager;

fn main() {
   tauri::Builder::default()
     .setup(|app| {
       #[cfg(debug_assertions)]
       app.get_window("main").unwrap().open_devtools(); // `main` is the first window from tauri.conf.json without an explicit label
       Ok(())
     })
     .invoke_handler(tauri::generate_handler![greet])
     .run(tauri::generate_context!())
     .expect("error while running tauri application");
}

( The #[cfg] line makes sure this is not applied in production apps where devtools are disabled anyway )

@yunylz
Copy link

yunylz commented Aug 8, 2024

tauri::Builder::default()
     .setup(|app| {
       #[cfg(debug_assertions)]
       app.get_window("main").unwrap().open_devtools(); // `main` is the first window from tauri.conf.json without an explicit label
       Ok(())
     })
     .invoke_handler(tauri::generate_handler![greet])
     .run(tauri::generate_context!())
     .expect("error while running tauri application");

For V2:

pub fn run() {
    tauri::Builder::default()
        .setup(|app| {
            #[cfg(debug_assertions)]
            app.get_webview_window("main").unwrap().open_devtools(); 
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: upstream This issue is blocked by upstream dependencies and we need to wait or contribute upstream fixes
Projects
None yet
Development

No branches or pull requests

5 participants