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

WASM not parsing on iOS 14 #119

Open
Willy-JL opened this issue Jul 4, 2024 · 3 comments · May be fixed by #120
Open

WASM not parsing on iOS 14 #119

Willy-JL opened this issue Jul 4, 2024 · 3 comments · May be fixed by #120

Comments

@Willy-JL
Copy link

Willy-JL commented Jul 4, 2024

I am on iOS 14 for jailbreak purposes, and Stremio web refuses to load. Although I am entirely unfamiliar with WASM, and with iOS Safari debugging, I spent the last 3 days trying to find any info at all on the issue. (In case it matters, I am on iOS 14.4.2 beta 2, jailbroken with unc0ver fugu14, and debugging over USB on linux with ios-webkit-debug-proxy and ios-safari-remote-debug-kit following the guide at https://jade.fyi/blog/debugging-ios-safari-from-linux/).

Small sidenote, there seems to be a separate problem, when an exception in WASM is thrown, the exception handling itself fails too, so no useful error messages relative to the WASM issue end up in browser console, instead just Unhandled Promise Rejection: DataCloneError: The object can not be cloned. is shown. How I am debugging this is by enabling "All Exceptions" breakpoint in Sources tab of debug-kit, and finding the exception message in the local variables of the debugger.

The actual root of the problem seems to be WASM instructions that iOS 14's Safari can't understand. Just as-is running from source, I encounter CompileError: WebAssemly.Module doesn't parse at byte 446: invalid opcode 194, in function at index 6. Converting to hex opcode 0xC2 and consulting https://pengowray.github.io/wasm-ops/, it appears that this is a i64.extend8_s instruction. Using wasm-tools confirms this: wasm-tools parse -t stremio_core_web_bg.wasm -o stremio_core_web_bg.wat and grep i64.extend8_s stremio_core_web_bg.wat gives a few results of this instruction in the assembly.

Looking around for any info on how to toggle features for wasm targets in rust, I stumbled upon this: rust-lang/rust#109807. It seems that this instruction is intended to be in use by default (atleast at this time), but it is not possible to disable it. One comment in that thread however, mentions a working solution with wasm-pack, as stremio-core-web uses too: rust-lang/rust#109807 (comment).

Adding:

[package.metadata.wasm-pack.profile.release]
wasm-opt = ["--signext-lowering"]

to Cargo.toml indeed created a .wasm without such instructions, but instead brought another issue.

Now, I get a LinkError: import function wbg:__wbindgen_number_new must be callable exception when Safari loads the WASM. The above comment mentioned extra rust flags, which when I tried they complained about requiring rust nightly. I tried installing that, had to delete the rust-toolchain.toml file, but still encountered the same error.

I am posting this to share my progress in debugging this issue and hoping to come to a solution, which I am currently stuck on and can't seem to find more information on.

@Willy-JL
Copy link
Author

Willy-JL commented Jul 4, 2024

🤦‍♂️ I was so focused on getting the extra rust flags and the nightly version working, that I missed the obvious hint from npm run build: after compiling the .wasm package, of course I needed to also copy over into the stremio-web instance I used for testing the stremio_core_web.js, bridge.js and worker.js files.

In the end, it seems like extra flags and and nightly toolchain are not required, simply the Cargo.toml configuration to remove the unsupported instructions was sufficient. The stremio-web homepage loaded successfully on my iOS 14 Safari. I will start trying to use it now and see if I encounter any other issues.

I'll leave this here since it could be useful for reference on debugging similar issues (had another one in the past with ffmpeg.wasm and had no clue how to debug iOS Safari). In the meantime, I will open a PR with the above change, since it turned out to be so simple.

@Willy-JL Willy-JL linked a pull request Jul 4, 2024 that will close this issue
@Willy-JL
Copy link
Author

Willy-JL commented Jul 4, 2024

This report on Reddit (another user) is likely also due to the same issue: https://www.reddit.com/r/Stremio/comments/1azni6e/web_app_broken_on_ios_14_purple_screen/

Same symptoms, and also on iOS 14.

@Willy-JL
Copy link
Author

To give an update on this, I have been able to use Stremio web as a PWA added to iOS home screen flawlessly thanks to the changes above, everything works as intended. I hope this can be merged soon, as it's a very simple change and allows a whole set of devices to finally use Stremio :D

For anyone wanting to run from source in the meantime, I found that you don't need to keep the web server running after adding to iOS home screen. So you can simply:

  • clone stremio-web
  • clone stremio-core-web from my fork
  • build stremio-core-web from the fixed branch
  • copy the resulting files to stremio-web/node_modules/@stremio/stremio-core-web
  • run stremio-web as normal
  • connect to it on your iOS device and add to Home Screen
  • stop stremio-web and continue using the app on iOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant