flutter-client-sdk icon indicating copy to clipboard operation
flutter-client-sdk copied to clipboard

Errors when using Web Assembly (wasm)

Open luizpaulofranz opened this issue 10 months ago • 8 comments

Is this a support request? Yes

Describe the bug I have migrated our web project to web assembly (wasm), and after that, I am getting several CORS errors on launch darkly.

To reproduce Add the launchdarkly_flutter_client_sdk: ^4.7.0 on a web project make all required configurations and build it for wasm. When you try to access the web version, you will get a bunch of CORS errors.

Expected behavior No CORS errors.

Logs Error from the browser

       GET https://clientstream.launchdarkly.com/eval//eyJraW5kIjoibXVsdGkiLCJkZXZpY2UiOnsia2V5IjoiY2UzZDAwNDMtMjNhNy00NGNjLTlkYmMtZjM2N2E5ODg0MDAyIiwiYW5vbnltb3VzIjp0cnVlfSwibGRfYXBwbGljYXRpb24iOnsia2V5IjoiSER0MHlYc2RpbjZrbFBNcGlpaElUdVNIeFpOMG5yVktLVlpzemdIdWNJWT0iLCJuYW1lIjoib3R0b19hcHAiLCJpZCI6Im90dG9fYXBwIiwidmVyc2lvbk5hbWUiOiIxLjcuMyIsImxvY2FsZSI6ImVuLVVTIiwiZW52QXR0cmlidXRlc1ZlcnNpb24iOiIxLjAifX0= net::ERR_FAILED 301 (Moved Permanently)Understand this errorAI
192.168.3.109/:1 Access to resource at 'https://clientstream.launchdarkly.com/eval//eyJraW5kIjoibXVsdGkiLCJkZXZpY2UiOnsia2V5IjoiY2UzZDAwNDMtMjNhNy00NGNjLTlkYmMtZjM2N2E5ODg0MDAyIiwiYW5vbnltb3VzIjp0cnVlfSwibGRfYXBwbGljYXRpb24iOnsia2V5IjoiSER0MHlYc2RpbjZrbFBNcGlpaElUdVNIeFpOMG5yVktLVlpzemdIdWNJWT0iLCJuYW1lIjoib3R0b19hcHAiLCJpZCI6Im90dG9fYXBwIiwidmVyc2lvbk5hbWUiOiIxLjcuMyIsImxvY2FsZSI6ImVuLVVTIiwiZW52QXR0cmlidXRlc1ZlcnNpb24iOiIxLjAifX0=' from origin 'https://192.168.3.109' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 

// Most relevant part of the error:
No 'Access-Control-Allow-Origin' header is present on the requested resource. 

SDK version 4.7.0

Language version, developer tools Flutter 3.27.0 Framework • revision 8495dee1fd (5 weeks ago) • 2024-12-10 14:23:39 -0800 Engine • revision 83bacfc525 Tools • Dart 3.6.0 • DevTools 2.40.2

Additional context This error doesn't happen if I use normal web build, it only happens when I use wasm to build. It successful build, but we got these errors.

Another weird thing that we discovered is that when we are using the WASM build, the failing CORS requests of launch darkly are going with the wrong URL, like this: https://clientstream.launchdarkly.com/eval//eyJra...... -> Look after the eval. I believe there should appear the client ID. It's important enforce that if we use normal web builds (no wasm) this error doesn't happens.

Image

luizpaulofranz avatar Jan 13 '25 21:01 luizpaulofranz

I am seeing this as well. Any updates to this?

alexdecoder avatar Mar 04 '25 18:03 alexdecoder

Hello @luizpaulofranz and @alexdecoder, thank you for reporting this issue. Sorry that it took a while to respond to this. We have opened a ticket and will try to look into the issue. Does either of you have a sample project that can help us reproduce this faster?

Filed internally as SDK-1093.

louis-launchdarkly avatar Mar 05 '25 00:03 louis-launchdarkly

Is there any update on this issue?

sunderee avatar Apr 07 '25 12:04 sunderee

Sorry for the slow reply, the investigation so far found the current Flutter SDK is using a dependency (dart:html) that is not Web Assembly compatible. We are looking to replace that dependency and make sure the SDK still builds correctly for all platforms.

louis-launchdarkly avatar Apr 15 '25 23:04 louis-launchdarkly

Thank you for your answer. As far as I'm aware, Flutter has instructions on how to migrate from dart:html to package:web published on their site. If help from the community is needed, let us know.

sunderee avatar Apr 17 '25 12:04 sunderee

@luizpaulofranz @alexdecoder @sunderee launchdarkly_flutter_client_sdk version 4.11.0 has just been released to add support for WASM when using Flutter version 3.24.0 or higher.

abarker-launchdarkly avatar Apr 21 '25 19:04 abarker-launchdarkly

@luizpaulofranz @abarker-launchdarkly, even after upgrading to the latest version, I am seeing the below CORS errors:

Image

Image

alexdecoder avatar Apr 30 '25 17:04 alexdecoder

@alexdecoder I want to try and eliminate variables here. Can you do the following:

  • git clone https://github.com/launchdarkly/flutter-client-sdk.git
  • cd flutter-client-sdk/packages/flutter_client_sdk/example
  • flutter pub get
  • flutter run --dart-define LAUNCHDARKLY_CLIENT_SIDE_ID=<<insert your client id here>> -d Chrome --wasm

This should work with no errors and your network traffic should look similar to this:

Image

abarker-launchdarkly avatar May 01 '25 19:05 abarker-launchdarkly