wry icon indicating copy to clipboard operation
wry copied to clipboard

Unable to get response from custom protocol when using `with_html`

Open fzdwx opened this issue 2 years ago • 12 comments

Describe the bug fetch can not resolve body

Steps To Reproduce

The minimum reproducible code is here: https://github.com/fzdwx/wry-demo

Expected behavior console.log(res.body) is not null

Screenshots

response have value, is hello

image

but fetch can not reslove

image image

Platform and Versions (please complete the following information):

❯ cargo tauri info  

Environment
  › OS: Arch Linux Unknown X64
  › Node.js: 19.6.0
  › npm: 8.19.2
  › pnpm: 7.18.0
  › yarn: 1.22.19
  › rustup: 1.25.1
  › rustc: 1.69.0-nightly
  › cargo: 1.69.0-nightly
  › Rust toolchain: nightly-x86_64-unknown-linux-gnu 

Would you want to assign yourself to resolve this bug?

  • [ ] Yes
  • [x] No

Additional context

mybe https://bugs.webkit.org/show_bug.cgi?id=229034 ?

fzdwx avatar Feb 23 '23 15:02 fzdwx

What's webkitgtk version from your devices?

Edit: I believe your sample also doesn't work. Could you give more context about it? It would be best it's a wry example that I can test directly.

wusyong avatar Feb 23 '23 16:02 wusyong

What's webkitgtk version from your devices?

Edit: I believe your sample also doesn't work. Could you give more context about it? It would be best it's a wry example that I can test directly.

From my project https://github.com/fzdwx/popup-translation, and the webkitgtk version i will take you tomorrow.

fzdwx avatar Feb 23 '23 16:02 fzdwx

@fzdwx I'm really glad it's a wry project already. But I couldn't find a way to open devtool and run a fetch command. What are the steps to do it?

wusyong avatar Feb 23 '23 17:02 wusyong

Sorry, my bed. Append args -p google hello


And click button on the page

fzdwx avatar Feb 23 '23 23:02 fzdwx

Hello, my webkitgkt version is :

❯ yay -Q webkit2gtk
webkit2gtk 2.38.4-1

I upgrade to 2.38.5-1, it dont's work yet

fzdwx avatar Feb 24 '23 00:02 fzdwx

The minimum reproducible code is here: https://github.com/fzdwx/wry-demo

I find use with_url, fetch response body is not null ! @wusyong

fzdwx avatar Feb 24 '23 05:02 fzdwx

@fzdwx Thanks for the example again! Sorry I'm during vacation right now but I can tell you with_html on Linux doesn't really behave like http:// origin. It has many caveats which tauri doesn't really use it. It's recommended to just use custom protocol URL scheme and call with_url.

wusyong avatar Feb 26 '23 07:02 wusyong

Thanks you for your reply ! But with_url only load once on window create, i want to send my request to my rust application.

If you need my help later, please call me anytime.

fzdwx avatar Feb 26 '23 07:02 fzdwx

From your use case (popup-translation), it looks like you already created the webview window and made it invisible from the start. Maybe you can create a webview window with with_url("wry://dev/google") anyway? It shouldn't be a problem, even if it's an empty webpage.

wusyong avatar Feb 26 '23 07:02 wusyong

@wusyong Thanks ! But I have to think about how to change my code .

fzdwx avatar Feb 26 '23 08:02 fzdwx

Okay I think the cause is we set the origin to http://localhost. https://github.com/tauri-apps/wry/blob/dev/src/webview/webkitgtk/mod.rs#L366 We can expose an option to set it, but this will only work on macOS and Linux I'm afraid.

wusyong avatar Feb 27 '23 07:02 wusyong

Has anyone managed to address this? I'm stuck here

J-Cake avatar Aug 28 '24 08:08 J-Cake