fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.29k stars 301 forks source link

Cannot run generated code in integration tests on Flutter web due to cross origin issues #2407

Open dtscalac opened 1 week ago

dtscalac commented 1 week ago

Is your feature request related to a problem? Please describe. flutter_rust_bridge generated code cannot be run in integration tests via flutter drive on Flutter web because the flutter drive command seems to not support the --web-header option described in https://cjycode.com/flutter_rust_bridge/manual/miscellaneous/web-cross-origin#when-flutter-run.

Attempting to run an integration test that tries to call code generated by the flutter_rust_bridge:

chromedriver --port=4444 --verbose

flutter drive --driver=test_driver/integration_tests.dart \
            --target=integration_test/catalyst_key_derivation_test.dart \
            -d web-server --browser-name=chrome --driver-port=4444 \
            --web-header="Cross-Origin-Opener-Policy=same-origin" \
            --web-header="Cross-Origin-Embedder-Policy=require-corp" \
            --web-browser-flag="--disable-web-security" \
            --web-browser-flag="--user-data-dir=/tmp/chrome-dir" \
            --profile --verbose --no-headless

Resulting in:

Screenshot 2024-11-11 at 19 51 07

Describe the solution you'd like Make it possible to run flutter_rust_bridge generated code in integration tests on Flutter web.

Since it seems that flutter drive doesn't support the --web-header option a usual approach would be to use --disable-web-security flag for chrome. When this flag is set the flutter_rust_bridge should no longer throw missing cross-origin headers errors since we made the browser not require these headers.

I'm not sure if --disable-web-security bypasses all issues related to cross-origin and shared buffers though it would seem like a perfect solution if it worked.

Describe alternatives you've considered Tried setting up my own web-server that adds the missing cross-origin headers however it looks like this solution is not compatible with flutter drive which always runs it's own web-server which we don't control.

welcome[bot] commented 1 week ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 1 week ago

I'm not sure if --disable-web-security bypasses all issues related to cross-origin and shared buffers though it would seem like a perfect solution if it worked.

That looks pretty reasonable!

It seems this is not a but of flutter_rust_bridge, but something that we can issue/PR to Flutter.

Btw, the header for flutter run was PRed in https://github.com/flutter/flutter/pull/136297 by @aran to support easier usage of flutter_rust_bridge. For flutter drive maybe able to mimic that PR.

dtscalac commented 1 week ago

Btw, the header for flutter run was PRed in https://github.com/flutter/flutter/pull/136297 by @aran to support easier usage of flutter_rust_bridge. For flutter drive maybe able to mimic that PR.

Thank you for the recommendation. I will contribute during this weekend the option to add custom headers to flutter drive command in the flutter repository. Should we keep this issue open as reference that I can issue to justify the need for extra options?

fzyzcjy commented 1 week ago

Sure, feel free to leave this issue open!

dtscalac commented 5 days ago

Raised an issue in flutter repository: https://github.com/flutter/flutter/issues/159037

Will link the flutter's PR to the flutter issue once it is ready.