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

[bug] on_web_resource_request not working in dev mode #5708

Closed
matthme opened this issue Nov 28, 2022 · 7 comments
Closed

[bug] on_web_resource_request not working in dev mode #5708

matthme opened this issue Nov 28, 2022 · 7 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@matthme
Copy link
Contributor

matthme commented Nov 28, 2022

Describe the bug

In dev mode, i.e. when running npm run tauri dev the method on_web_resource_request of the WundowBuilder seems to be ignored.

Reproduction

  1. Run sh <(curl https://create.tauri.app/sh) on linux.
  2. Choose npm as the package manager and Vue-ts as the frontend framework.
  3. Add the following setup hook to src-tauri/src/main.rs:
        .setup(|app| {
            use tauri::WindowBuilder;
            use tauri::WindowUrl;
            let _window = WindowBuilder::new(
                &app.handle(),
                String::from("some_label"),
                WindowUrl::App("index.html".into()),
            ).on_web_resource_request(move |request, response| {
              println!("Received request: {:?}", request);
            }).build();

            Ok(())
        })

  1. Run npm run tauri dev and see that the print statement is not being triggered.
  2. Build the app via npm run tauri build and see that the print statement is being triggered when running the AppImage.

Expected behavior

I expect .on_web_resource_request() to also work in dev mode.

Platform and versions

Environment
› OS: Ubuntu 22.04 X64
› Node.js: 16.11.1
› npm: 8.0.0
› pnpm: Not installed!
› yarn: 1.22.19
› rustup: 1.25.1
› rustc: 1.64.0
› cargo: 1.64.0
› Rust toolchain: stable-x86_64-unknown-linux-gnu

Packages
› @tauri-apps/cli [NPM]: 1.2.1
› @tauri-apps/api [NPM]: 1.2.0
› tauri [RUST]: 1.2.1,
› tauri-build [RUST]: 1.2.1,
› tao [RUST]: 0.15.6,
› wry [RUST]: 0.22.5,

App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: Vue.js

App directory structure
├─ dist
├─ node_modules
├─ src-tauri
├─ src
├─ .vscode
└─ public

Stack trace

No response

Additional context

No response

@matthme matthme added status: needs triage This issue needs to triage, applied to new issues type: bug labels Nov 28, 2022
@FabianLars
Copy link
Member

This is expected and documented:
grafik

Thank you for your report.

@matthme
Copy link
Contributor Author

matthme commented Nov 28, 2022

Oh that's a big pitty. It was working before I updated to tauri 1.2.0 so I didn't really think about looking into the docs. I guess something changed under the hood when running npm run tauri dev.

@FabianLars
Copy link
Member

The only change to tauri dev was that it now serves the frontend files, if your devPath is a file path and not a url, via an internal dev server to enable hot reloading.

@matthme
Copy link
Contributor Author

matthme commented Nov 28, 2022

Yes, that's probably it. I had a file path and it was working before at least without hot-reloading (if I needed hot-reloading I took care of it myself by running my own dev server and then on_web_resource_request was indeed not working). Now my iteration frequency has just dropped a lot :/ Is there a way to disable hot-reloading?

@FabianLars
Copy link
Member

FabianLars commented Nov 28, 2022

No, i think it's hard coded. idk if that works but you could try setting tauri://localhost as the devPath.

If that doesn't work i'd suggest using tauri build --debug --b none, preferably in a script which can stops/start the app too (the script would need to take care of a potential beforeDevCommand too).
cargo run or cargo run --features custom-protocol in your src-tauri dir should work too.

p.s. feel free to open a feature request asking for a built-in way to disable it (no promises).

@matthme
Copy link
Contributor Author

matthme commented Nov 28, 2022

Thank you! tauri://localhost alone didn't work, because it seems to expect a port number. But cargo run in src-tauri did :)

I think a feature request would be overkill in this case, especially since on_web_resource_request may at some be supported in dev mode anyway.

@amrbashir
Copy link
Member

@matthme next version will have --no-dev-server option to disable the dev server for static files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

3 participants