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

Web: DriftRemoteException WebAssembly.instantiateStreaming is not a function #187

Closed
gokhanmeteerturk opened this issue Sep 29, 2023 · 3 comments

Comments

@gokhanmeteerturk
Copy link

gokhanmeteerturk commented Sep 29, 2023

I'm having an error on mobile devices when browser is 'Chrome Mobile iOS 92', 'Mobile Safari 13.1', 'Samsung Internet 22' etc:

DriftRemoteException
NoSuchMethodError: method not found: 'instantiateStreaming'
(self.WebAssembly.instantiateStreaming is not a function.
(In 'self.WebAssembly.instantiateStreaming(a,o)',
'self.WebAssembly.instantiateStreaming' is undefined)
)

I know that JavaScript built-in: WebAssembly: instantiateStreaming is not supported by those browsers:
https://caniuse.com/?search=instantiatestreaming

But I'm not sure why my drift setup uses instantiateStreaming or if this is expected for those browsers.

When checked with https://drift.simonbinder.eu/web/ it says:

WasmStorageImplementation.unsafeIndexedDb

I'm using:

   final db = await WasmDatabase.open(
      databaseName: 'todo-app',
      sqlite3Uri: Uri.parse('sqlite3.wasm'),
      driftWorkerUri: Uri.parse('drift_worker.js'),
    );

Headers:

  Cross-Origin-Opener-Policy: same-origin
  Cross-Origin-Embedder-Policy: require-corp

drift versions: tried with 2.11 and 2.12.2

Using WasmStorageImplementation.unsafeIndexedDb due to unsupported browser features: {MissingBrowserFeature.sharedWorkers, MissingBrowserFeature.fileSystemAccess, MissingBrowserFeature.sharedArrayBuffers}

@simolus3 simolus3 transferred this issue from simolus3/drift Sep 30, 2023
@simolus3
Copy link
Owner

Thanks for the report! The sqlite3 Dart package, which drift uses internally to open the database, uses WebAssembly.instantiateStreaming to download the sqlite3 engine.

I have added a fallback, but I don't have access to older browsers to try it out. Could you replace your drift worker with https://storage.googleapis.com/simon-public-euw3/assets/drift_worker.js and see if that fixes the issue on those browsers?

@gokhanmeteerturk
Copy link
Author

Thank you for the fallback. Unfortunately there seems to be a problem with it.
Now I have this error message from DriftRemoteException:

Error: WebAssembly.Module doesn't parse at byte 241: invalid opcode 192, in function at index 85

(I'm using browserstack to test it right now. Apparently it has free plan for open source projects)

@simolus3
Copy link
Owner

simolus3 commented Oct 2, 2023

WebAssembly.Module doesn't parse at byte 241: invalid opcode 192

This is because llvm uses sign-extension features by default, which are not available in the WebAssembly MVP version supported by these old browsers. I've tried transforming these with binaryen, but then these browsers complain about imported functions using 64-bit ints, something we need to implement custom file systems. The binaryen pass supposed to lower those crashed for me, so it seems like there's nothing I could do about it.

WebAssembly is a new web technology and we support recent versions of major browsers. That already took a lot of work, expanding this to support even older versions (which sometimes have buggy implementations as well) seems infeasible to me.

@simolus3 simolus3 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
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

No branches or pull requests

2 participants