tauriでWindows上でproductionビルドでのみ画像が表示されない(fetchエラーが発生する)
作成:2021/12/25 0:00:00
更新:2021/12/25 0:00:00
(2021-12-25)
誰の役にも立たない気がするけどハマったのでメモ
起こったこと
tauri dev
で表示されていた画像がtauri build
でビルドしたバイナリではなぜか表示されなかった- Windowsでのみ起きてwsl上のLinuxでは起きなかった
- 試しに
tauri.conf.json
でdevPath
にビルド済みのアセットのローカルパスを書いてtauri dev
で起動してみたところ問題が再現
原因 (2021-12-25)
net::ERR_TOO_MANY_REDIRECTS
というエラーが発生していた- 読み込んでいた画像はhttpsでアクセスするとhttpにリダイレクトするようになっていた
- dev serverは通常 [http://localhost
のurl上にあるが、tauriではローカルアセットを読み込むときに
https://tauri.localhost というurlが内部で使われる - そしてWindows上のWebview2(というかChromium)は現在httpとhttpsの混合コンテンツをブロックし、https上のページではhttpリクエストが自動でhttpsにアップグレードされる
Chromium Blog: No More Mixed Messages About HTTPS
blog.chromium.org

- なのでhttp->https->httpの無限ループが発生し上記のエラーが発生していた
解決策 (2021-12-25)
@tauri-apps/api
のfetchを使う- ローカルアセットでもhttpを使わせることは難しそう
How to make tauri use http://tauri.localhost/ instead of https://tauri.localhost/ ? The page was blocked since the page was loaded over HTTPS. · Issue #3007 · tauri-apps/tauri · GitHub
Updated @2023-09-17: If anyone has encountered this problem, please pay attention to this PR: Allow http origin on Windows Is your feature request related to a problem? Please describe. WebView console shows the following errors when we ...
github.com