tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] Load image error on Ubuntu.

Open Luciennnnnnn opened this issue 3 years ago • 18 comments

Describe the bug

image I got this error when I load image on Ubuntu, everything works on Mac and Windows.

Reproduction

No response

Expected behavior

No response

Platform and versions

Environment
  › OS: Ubuntu 20.04 X64
  › Node.js: 16.15.1
  › npm: 8.11.0
  › pnpm: 6.11.0
  › yarn: 1.22.15
  › rustup: 1.24.3
  › rustc: 1.61.0
  › cargo: 1.61.0
  › Rust toolchain: stable-x86_64-unknown-linux-gnu 

Packages
  › @tauri-apps/cli [NPM]: 1.0.0
  › @tauri-apps/api [NPM]: 1.0.1
  › tauri [RUST]: 1.0.0,
  › tauri-build [RUST]: 1.0.0,
  › tao [RUST]: 0.11.2,
  › wry [RUST]: 0.18.3,

App
  › build-type: bundle
  › CSP: default-src 'self' customprotocol: asset: https://asset.localhost; img-src 'self' asset: https://asset.localhost
  › distDir: ../dist
  › devPath: http://localhost:3000/
  › framework: Vue.js

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

Stack trace

No response

Additional context

No response

Luciennnnnnn avatar Jun 28 '22 02:06 Luciennnnnnn

Can you share how you're loading the asset? Is it a fetch?

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

This is a CORS issue - we set the headers on macOS and Windows (that's why it works on those platforms) but webkit2gtk only added support for this recently, so we can't update yet :/

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

Can you share how you're loading the asset? Is it a fetch?

I load image using this code: image

Luciennnnnnn avatar Jun 28 '22 04:06 Luciennnnnnn

This is a CORS issue - we set the headers on macOS and Windows (that's why it works on those platforms) but webkit2gtk only added support for this recently, so we can't update yet :/

Is that mean webkit2gtk already supports this? Can tauri update for that?

Luciennnnnnn avatar Jun 28 '22 04:06 Luciennnnnnn

We're working to update it - but it's complicated, see #3961

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

In your specific case it works if you remove i.crossOrigin = 'Anonymous' @LuoXin-s

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

It wouldn't work if you were using fetch() but for video/img tags it works just fine.

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

In your specific case it works if you remove i.crossOrigin = 'Anonymous' @LuoXin-s

I remember that if I remove i.crossOrigin = 'Anonymous', there is another problem. that's why I added that. I'll test again and make a response to you.

Luciennnnnnn avatar Jun 28 '22 04:06 Luciennnnnnn

We're working to update it - but it's complicated, see #3961

ok

Luciennnnnnn avatar Jun 28 '22 04:06 Luciennnnnnn

@lucasfernog If I remove i.crossOrigin = 'Anonymous', I can't export canvas to dataurl. I load image into canvas, and export it to image. image

Luciennnnnnn avatar Jun 28 '22 04:06 Luciennnnnnn

Ahh that's also a CORS issue. If the images are small (and you're not loading several images) you could read the files directly and parse them for the image element but that's.. hard and suboptimal.

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

@wusyong do you know if there's a way to disable CORS checks for custom protocols on Linux?

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

Ahh that's also a CORS issue. If the images are small (and you're not loading several images) you could read the files directly and parse them for the image element but that's.. hard and suboptimal.

I need to operate many images and they are large usually.

Luciennnnnnn avatar Jun 28 '22 04:06 Luciennnnnnn

Reference discussions: https://github.com/tauri-apps/tauri/issues/2327#issuecomment-898887548 https://github.com/tauri-apps/wry/issues/366#issuecomment-898201274 https://github.com/tauri-apps/wry/issues/348

lucasfernog avatar Jun 28 '22 04:06 lucasfernog

I tried to use https://webkitgtk.org/reference/webkit2gtk/stable/WebKitSecurityManager.html#webkit-security-manager-register-uri-scheme-as-cors-enabled but it didn't help :/

lucasfernog avatar Jun 28 '22 05:06 lucasfernog

@lucasfernog Hi, any progress on this problem?

Luciennnnnnn avatar Jul 13 '22 12:07 Luciennnnnnn

@LuoXin-s Not really :/ I'll need to implement asset protocol functionality inside the tauri protocol.

lucasfernog avatar Aug 02 '22 22:08 lucasfernog

@wusyong do you know if there's a way to disable CORS checks for custom protocols on Linux?

Sorry I think I missed this mention. There's the updated webkit2gtk but I haven't added because some data race issues. If you can bring a minimum example to wry. I'll test it along the way.

wusyong avatar Aug 03 '22 05:08 wusyong