-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[url_launcher] launchUrl always returns true for valid schemes on the web. #7229
Conversation
Since noopener is used to open URLs, there is no way to determine if the browser has succesfully opened a given URL. Therefore success is now assumed for supported schemes. Fixes flutter/flutter#139783.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance of adding a test? Most of the tests of this package are in the example/integration_test
directory.
@@ -109,7 +110,8 @@ class UrlLauncherPlugin extends UrlLauncherPlatform { | |||
@override | |||
Future<bool> launchUrl(String url, LaunchOptions options) async { | |||
final String? windowName = options.webOnlyWindowName; | |||
return openNewWindow(url, webOnlyWindowName: windowName) != null; | |||
openNewWindow(url, webOnlyWindowName: windowName); | |||
return canLaunch(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just return true;
, no need to call canLaunch
or anything else.
(Question: if canLaunch
returns false, does it prevent launchUrl
from actually attempting to open a browser tab with a bogus URL? I don't think it would, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning true
will break the url_launcher_web_test test.
I'll update the code and the test.
Question: if canLaunch returns false, does it prevent launchUrl from actually attempting to open a browser tab with a bogus URL? I don't think it would, right?
In the current setup it won't. If we would want that, we could do a canLaunch
earlier and bail-out. But I agree returning true is better; if the user of this package wants such behaviour he can do so himself by calling canLaunch
first in his own code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canLaunch
is not super valuable on the web, the browser doesn't know if it can handle a protocol and will just attempt to open anything, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Frank3K how about:
html.Window? openNewWindow(String url, {String? webOnlyWindowName})
becomes:bool openNewWindow(String url, {String? webOnlyWindowName})
If it does NOT call window.open
-> return false
If it calls window.open
-> return true
(regardless of what window.open returns)
Then the implementation of launchUrl
can be just:
return openNewWindow...
That way we can still return false
if the user really tries to mess up (like opening a disallowed protocol).
(I can incorporate those changes to this PR myself, if you think they make sense)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea 👍 . I applied the proposed changes and added a small test.
This PR is ready for re-review.
Thanks for your review.
I have checked the tests and they are already quite extensive. With the proposed |
Woops, dart format is complaining, I'll get that fixed. |
The flutter-dashboard flagged this as "not having tests" earlier, but it does now: opening a bogus scheme returns true, regardless of what the browser does. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
flutter/packages@551bde5...5cc0a01 2024-08-07 stuartmorgan@google.com [ci] Update repository for the release of Flutter 3.24 (flutter/packages#7331) 2024-08-07 engine-flutter-autoroll@skia.org Roll Flutter (stable) from b0850be to 80c2e84 (1397 revisions) (flutter/packages#7322) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.5 to 4.3.6 (flutter/packages#7330) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com [pigeon]: Bump io.mockk:mockk from 1.13.7 to 1.13.12 in /packages/pigeon/platform_tests/test_plugin/android (flutter/packages#7189) 2024-08-07 joonas.kerttula@codemate.com [google_maps_flutter] Marker clustering support (flutter/packages#4319) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.15 to 3.26.0 (flutter/packages#7329) 2024-08-07 engine-flutter-autoroll@skia.org Manual roll Flutter from 1dd7141 to 0a7f8af (23 revisions) (flutter/packages#7328) 2024-08-06 magder@google.com [image_picker_ios] Update image picker UI test query for iOS 18 (flutter/packages#7325) 2024-08-06 joonas.kerttula@codemate.com [google_maps_flutter] Add marker clustering support - iOS implementation (flutter/packages#6186) 2024-08-06 8014077+Frank3K@users.noreply.github.com [url_launcher] launchUrl always returns true for valid schemes on the web. (flutter/packages#7229) 2024-08-06 rexios@rexios.dev [google_maps_flutter] Add heatmap support (flutter/packages#3257) 2024-08-06 stuartmorgan@google.com [local_auth] Endorse macOS (flutter/packages#7274) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@551bde5...5cc0a01 2024-08-07 stuartmorgan@google.com [ci] Update repository for the release of Flutter 3.24 (flutter/packages#7331) 2024-08-07 engine-flutter-autoroll@skia.org Roll Flutter (stable) from b0850be to 80c2e84 (1397 revisions) (flutter/packages#7322) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.5 to 4.3.6 (flutter/packages#7330) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com [pigeon]: Bump io.mockk:mockk from 1.13.7 to 1.13.12 in /packages/pigeon/platform_tests/test_plugin/android (flutter/packages#7189) 2024-08-07 joonas.kerttula@codemate.com [google_maps_flutter] Marker clustering support (flutter/packages#4319) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.15 to 3.26.0 (flutter/packages#7329) 2024-08-07 engine-flutter-autoroll@skia.org Manual roll Flutter from 1dd7141 to 0a7f8af (23 revisions) (flutter/packages#7328) 2024-08-06 magder@google.com [image_picker_ios] Update image picker UI test query for iOS 18 (flutter/packages#7325) 2024-08-06 joonas.kerttula@codemate.com [google_maps_flutter] Add marker clustering support - iOS implementation (flutter/packages#6186) 2024-08-06 8014077+Frank3K@users.noreply.github.com [url_launcher] launchUrl always returns true for valid schemes on the web. (flutter/packages#7229) 2024-08-06 rexios@rexios.dev [google_maps_flutter] Add heatmap support (flutter/packages#3257) 2024-08-06 stuartmorgan@google.com [local_auth] Endorse macOS (flutter/packages#7274) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@551bde5...5cc0a01 2024-08-07 stuartmorgan@google.com [ci] Update repository for the release of Flutter 3.24 (flutter/packages#7331) 2024-08-07 engine-flutter-autoroll@skia.org Roll Flutter (stable) from b0850be to 80c2e84 (1397 revisions) (flutter/packages#7322) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.5 to 4.3.6 (flutter/packages#7330) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com [pigeon]: Bump io.mockk:mockk from 1.13.7 to 1.13.12 in /packages/pigeon/platform_tests/test_plugin/android (flutter/packages#7189) 2024-08-07 joonas.kerttula@codemate.com [google_maps_flutter] Marker clustering support (flutter/packages#4319) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.15 to 3.26.0 (flutter/packages#7329) 2024-08-07 engine-flutter-autoroll@skia.org Manual roll Flutter from 1dd7141 to 0a7f8af (23 revisions) (flutter/packages#7328) 2024-08-06 magder@google.com [image_picker_ios] Update image picker UI test query for iOS 18 (flutter/packages#7325) 2024-08-06 joonas.kerttula@codemate.com [google_maps_flutter] Add marker clustering support - iOS implementation (flutter/packages#6186) 2024-08-06 8014077+Frank3K@users.noreply.github.com [url_launcher] launchUrl always returns true for valid schemes on the web. (flutter/packages#7229) 2024-08-06 rexios@rexios.dev [google_maps_flutter] Add heatmap support (flutter/packages#3257) 2024-08-06 stuartmorgan@google.com [local_auth] Endorse macOS (flutter/packages#7274) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@551bde5...5cc0a01 2024-08-07 stuartmorgan@google.com [ci] Update repository for the release of Flutter 3.24 (flutter/packages#7331) 2024-08-07 engine-flutter-autoroll@skia.org Roll Flutter (stable) from b0850be to 80c2e84 (1397 revisions) (flutter/packages#7322) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.5 to 4.3.6 (flutter/packages#7330) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com [pigeon]: Bump io.mockk:mockk from 1.13.7 to 1.13.12 in /packages/pigeon/platform_tests/test_plugin/android (flutter/packages#7189) 2024-08-07 joonas.kerttula@codemate.com [google_maps_flutter] Marker clustering support (flutter/packages#4319) 2024-08-07 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.15 to 3.26.0 (flutter/packages#7329) 2024-08-07 engine-flutter-autoroll@skia.org Manual roll Flutter from 1dd7141 to 0a7f8af (23 revisions) (flutter/packages#7328) 2024-08-06 magder@google.com [image_picker_ios] Update image picker UI test query for iOS 18 (flutter/packages#7325) 2024-08-06 joonas.kerttula@codemate.com [google_maps_flutter] Add marker clustering support - iOS implementation (flutter/packages#6186) 2024-08-06 8014077+Frank3K@users.noreply.github.com [url_launcher] launchUrl always returns true for valid schemes on the web. (flutter/packages#7229) 2024-08-06 rexios@rexios.dev [google_maps_flutter] Add heatmap support (flutter/packages#3257) 2024-08-06 stuartmorgan@google.com [local_auth] Endorse macOS (flutter/packages#7274) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Description
Since
noopener
is used to open URLs, there is no way to determine if the browser has succesfully opened a given URL (MDN). Therefore success is now assumed for supported schemes.Fixes flutter/flutter#139783.
Implementation largely follows suggestions by @ditman written down in a comment.
The only exception is that
launchUrl
does not returns a hard-codedtrue
, but acanLaunch(url)
. That wayfalse
is returned for invalid schemes (e.g.javascript:
, as is checked in an integration test).Testing
Sample application
The following application can be used to validate the fix. Note that the
print
is executed using the current version of url_launcher_web (2.3.1) and that it does not execute when the fix from this PR is used.main.dart
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.