diff --git a/lib/web_ui/dev/common.dart b/lib/web_ui/dev/common.dart
index ad7d15bb84dce..535af6a3b09c9 100644
--- a/lib/web_ui/dev/common.dart
+++ b/lib/web_ui/dev/common.dart
@@ -50,7 +50,7 @@ abstract class PlatformBinding {
String getChromeExecutablePath(io.Directory versionDir);
String getFirefoxExecutablePath(io.Directory versionDir);
String getFirefoxLatestVersionUrl();
- String getSafariSystemExecutablePath();
+ String getMacApplicationLauncher();
String getCommandToRunEdge();
}
@@ -85,7 +85,7 @@ class _WindowsBinding implements PlatformBinding {
'https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US';
@override
- String getSafariSystemExecutablePath() =>
+ String getMacApplicationLauncher() =>
throw UnsupportedError('Safari is not supported on Windows');
@override
@@ -120,7 +120,7 @@ class _LinuxBinding implements PlatformBinding {
'https://download.mozilla.org/?product=firefox-latest&os=linux64&lang=en-US';
@override
- String getSafariSystemExecutablePath() =>
+ String getMacApplicationLauncher() =>
throw UnsupportedError('Safari is not supported on Linux');
@override
@@ -161,8 +161,7 @@ class _MacBinding implements PlatformBinding {
'https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US';
@override
- String getSafariSystemExecutablePath() =>
- '/Applications/Safari.app/Contents/MacOS/Safari';
+ String getMacApplicationLauncher() => 'open';
@override
String getCommandToRunEdge() =>
diff --git a/lib/web_ui/dev/safari.dart b/lib/web_ui/dev/safari.dart
index f96bd7cbf7772..1898aea88e520 100644
--- a/lib/web_ui/dev/safari.dart
+++ b/lib/web_ui/dev/safari.dart
@@ -3,16 +3,8 @@
// found in the LICENSE file.
import 'dart:async';
-import 'dart:convert';
import 'dart:io';
-import 'environment.dart';
-
-import 'package:path/path.dart' as path;
-import 'package:pedantic/pedantic.dart';
-
-import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
-
import 'browser.dart';
import 'safari_installation.dart';
import 'common.dart';
@@ -43,21 +35,22 @@ class Safari extends Browser {
infoLog: DevNull(),
);
- // Safari will only open files (not general URLs) via the command-line
- // API, so we create a dummy file to redirect it to the page we actually
- // want it to load.
- final Directory redirectDir = Directory(
- path.join(environment.webUiDartToolDir.path),
- );
- final redirect = path.join(redirectDir.path, 'redirect.html');
- File(redirect).writeAsStringSync(
- '');
-
- var process =
- await Process.start(installation.executable, [redirect] /* args */);
-
- unawaited(process.exitCode
- .then((_) => File(redirect).deleteSync(recursive: true)));
+ // In the latest versions of MacOs opening Safari browser with a file brings
+ // a popup which halts the test.
+ // The following list of arguments needs to be provided to the `open` command
+ // to open Safari for a given URL. In summary they provide a new instance
+ // to open, that instance to wait for opening the url until Safari launches,
+ // provide Safari bundles identifier.
+ // The details copied from `man open` on MacOS.
+ // TODO(nurhan): https://github.com/flutter/flutter/issues/50809
+ var process = await Process.start(installation.executable, [
+ '-F', // Open a fresh application with no persistant state.
+ '-W', // Open to wait until the applications it opens.
+ '-n', // Open a new instance of the application.
+ '-b', // Specifies the bundle identifier for the application to use.
+ 'com.apple.Safari', // Bundle identifier for Safari.
+ '${url.toString()}'
+ ]);
return process;
});
diff --git a/lib/web_ui/dev/safari_installation.dart b/lib/web_ui/dev/safari_installation.dart
index 2f651d72d2202..94d1e851ad80e 100644
--- a/lib/web_ui/dev/safari_installation.dart
+++ b/lib/web_ui/dev/safari_installation.dart
@@ -70,7 +70,7 @@ Future getOrInstallSafari(
infoLog.writeln('Using the system version that is already installed.');
return BrowserInstallation(
version: 'system',
- executable: PlatformBinding.instance.getSafariSystemExecutablePath(),
+ executable: PlatformBinding.instance.getMacApplicationLauncher(),
);
} else {
infoLog.writeln('Unsupported version $requestedVersion.');