tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] Android tauri-plugin capabilities disallowed

Open bpevs opened this issue 10 months ago • 6 comments

Describe the bug

Works as expected for desktop build; issue only occurs when running on mobile (Only tried Android, not iOS)

In the last two beta releases of 2.0 tauri + tauri-plugin, I have been running into an issue where capability permissions won't allow my plugin to function. Without any code changes, and only updating:

tauri 2.0.0-beta.12 -> 2.0.0-beta.15 tauri-plugin 2.0.0-beta.10 -> 2.0.0-beta.12

My plugin has stopped functioning (only on android), and my client is throwing a new error: Uncaught (in promise) my-plugin.init not allowed on window main, webview main, allowed windows: , allowed webviews: , referenced by

My capabilities looks something like this:

{
  "$schema": "./schemas/mobile-schema.json",
  "identifier": "main-capability",
  "description": "Capability for the main window",
  "windows": ["main"],
  "permissions": [
    "my-plugin:allow-init",
    "my-plugin:allow-create-event",
    "my-plugin:allow-update-event",
...

Reproduction

I was able to reproduce the error here, using a similar setup: https://github.com/bpevs/tauri_diesel_example/tree/android

However, the behavior is not exactly matching with my private repo's issue; still trying to figure out why. Difference is that in this repo:

  1. this issue actually still happens on tauri 2.0.0-beta.12
  2. The issue can be worked around by delaying the tauri command (the initial todos fetch fails initially, but actually works when it re-fetches on adding a todo)
Screenshot 2024-04-16 at 12 57 08
04-18 14:51:19.626 17849 17927 E chromium: [ERROR:simple_file_enumerator.cc(21)] opendir /data/user/0/com.example.app/cache/WebView/Default/HTTP Cache/Code Cache/js: No such file or directory (2)
04-18 14:51:19.626 17849 17927 E chromium: [ERROR:simple_index_file.cc(614)] Could not reconstruct index from disk
04-18 14:51:19.627 17849 17884 I RustStdoutStderr: [ERROR:simple_file_enumerator.cc(21)] opendir /data/user/0/com.example.app/cache/WebView/Default/HTTP Cache/Code Cache/js: No such file or directory (2)
04-18 14:51:19.627 17849 17884 I RustStdoutStderr: [ERROR:simple_index_file.cc(614)] Could not reconstruct index from disk
04-18 14:51:19.734 17849 17881 W OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
04-18 14:51:19.734 17849 17881 W OpenGLRenderer: Failed to initialize 101010-2 format, error = EGL_SUCCESS
04-18 14:51:19.760 17849 17881 I Gralloc4: mapper 4.x is not supported
04-18 14:51:19.766 17849 17881 E OpenGLRenderer: Unable to match the desired swap behavior.
04-18 14:51:19.834 17849 17884 I RustStdoutStderr: s_glBindAttribLocation: bind attrib 0 name position
04-18 14:51:19.834 17849 17884 I RustStdoutStderr: s_glBindAttribLocation: bind attrib 1 name color
04-18 14:51:19.874 17849 17936 W cr_media: BLUETOOTH_CONNECT permission is missing.
04-18 14:51:19.876 17849 17936 W cr_media: registerBluetoothIntentsIfNeeded: Requires BLUETOOTH permission
04-18 14:51:20.118 17849 17849 E Tauri/Console: File:  - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'metadata')
04-18 14:51:20.120 17849 17849 E Tauri/Console: File:  - Line 1 - Msg: Uncaught TypeError: Cannot read properties of undefined (reading 'metadata')
04-18 14:51:20.292 17849 17849 E Tauri/Console: File: http://tauri.localhost/ - Line 26 - Msg: Uncaught (in promise) todos-db.list_todos not allowed on window main, webview main, allowed windows: , allowed webviews: , referenced by 

Expected behavior

In this example repo, the expected behavior is that the todos are fetched from sqlite, and returned via tauri invoke command.

Full tauri info output

WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Mac OS 14.4.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (environment override by RUSTUP_TOOLCHAIN)

[-] Packages
    - tauri [RUST]: 2.0.0-beta.15
    - tauri-build [RUST]: 2.0.0-beta.12
    - wry [RUST]: 0.39.1
    - tao [RUST]: 0.27.0
    - tauri-cli [RUST]: 2.0.0-beta.13
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.13

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../src-www
    - devUrl: http://0.0.0.0:3000/

Stack trace

No response

Additional context

No response

bpevs avatar Apr 18 '24 21:04 bpevs

It's also present when trying to use event:allow-listen.

hzoltan01 avatar Apr 18 '24 22:04 hzoltan01

also same for upload plugin

gato25 avatar Apr 20 '24 08:04 gato25

Same for me, I have mobile.json

{
  "$schema": "../gen/schemas/mobile-schema.json",
  "identifier": "mobile-capability",
  "description": "Capability for mobile",
  "webviews": [
    "main"
  ],
  "windows": [
    "main"
  ],
  "platforms": [
    "android",
    "iOS"
  ],
  "permissions": [
    "event:allow-emit",
    "event:allow-emit-to",
    "event:allow-listen",
    "event:allow-unlisten"
  ]
}

And desktop.json

{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "desktop-capability",
  "description": "Capability for desktop",
  "webviews": [
    "main"
  ],
  "windows": [
    "main"
  ],
  "platforms": [
    "linux",
    "macOS",
    "windows"
  ],
  "permissions": [
    "event:allow-emit",
    "event:allow-emit-to",
    "event:allow-listen",
    "event:allow-unlisten"
  ]
}

Everything works fine for the desktop (firing events from Rust and listening to them from JS), but no success on mobile.

yarn run v1.22.21
$ tauri info

[✔] Environment
    - OS: Ubuntu 22.04 X64
    ✔ webkit2gtk-4.1: 2.44.0
    ✔ rsvg2: 2.52.5
    ✔ rustc: 1.77.2 (25ef9e3d8 2024-04-09)
    ✔ cargo: 1.77.2 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 20.11.0
    - yarn: 1.22.21
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 2.0.0-beta.15
    - tauri-build [RUST]: 2.0.0-beta.12
    - wry [RUST]: 0.39.1
    - tao [RUST]: 0.27.0
    - tauri-cli [RUST]: 1.5.11
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.13

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../src

I also noticed the following error in Android Logcat

File: http://tauri.localhost/ - Line 0 - Msg: Uncaught (in promise) event.listen not allowed on window main, webview main, allowed windows: , allowed webviews: , referenced by

Biacode avatar Apr 23 '24 17:04 Biacode

I have the same issue. In development mode I can see how the first time I launch my app (it uses event:listen) I get this error:

Uncaught event.listen not allowed on window main, webview main, allowed windows: , allowed webviews: , referenced by 

But when I simply reload the webview (via the chromium debugger), the error disappears and everything works.

I think that indicates it's timing-related: When the rust code & webview code start up at roughly the same time, the permission gets rejected, but if the webview code waits for the rust code a bit, it works.

matheus23 avatar Apr 28 '24 13:04 matheus23

Getting the same for fs plugin on android

hilifit avatar May 03 '24 12:05 hilifit

same here

thep0y avatar May 10 '24 14:05 thep0y