feat: support configure a custom launch url for flutter web (#95002)
This commit is contained in:
@@ -228,6 +228,7 @@ abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopment
|
||||
webRunHeadless: featureFlags.isWebEnabled && boolArg('web-run-headless'),
|
||||
webBrowserDebugPort: browserDebugPort,
|
||||
webEnableExpressionEvaluation: featureFlags.isWebEnabled && boolArg('web-enable-expression-evaluation'),
|
||||
webLaunchUrl: featureFlags.isWebEnabled ? stringArg('web-launch-url') : null,
|
||||
vmserviceOutFile: stringArg('vmservice-out-file'),
|
||||
fastStart: argParser.options.containsKey('fast-start')
|
||||
&& boolArg('fast-start')
|
||||
|
||||
@@ -763,6 +763,7 @@ class DebuggingOptions {
|
||||
this.webRunHeadless = false,
|
||||
this.webBrowserDebugPort,
|
||||
this.webEnableExpressionEvaluation = false,
|
||||
this.webLaunchUrl,
|
||||
this.vmserviceOutFile,
|
||||
this.fastStart = false,
|
||||
this.nullAssertions = false,
|
||||
@@ -779,6 +780,7 @@ class DebuggingOptions {
|
||||
this.webUseSseForInjectedClient = true,
|
||||
this.webRunHeadless = false,
|
||||
this.webBrowserDebugPort,
|
||||
this.webLaunchUrl,
|
||||
this.cacheSkSL = false,
|
||||
this.traceAllowlist,
|
||||
}) : debuggingEnabled = false,
|
||||
@@ -852,6 +854,9 @@ class DebuggingOptions {
|
||||
/// Enable expression evaluation for web target.
|
||||
final bool webEnableExpressionEvaluation;
|
||||
|
||||
/// Allow developers to customize the browser's launch URL
|
||||
final String? webLaunchUrl;
|
||||
|
||||
/// A file where the VM Service URL should be written after the application is started.
|
||||
final String? vmserviceOutFile;
|
||||
final bool fastStart;
|
||||
|
||||
@@ -263,6 +263,10 @@ abstract class FlutterCommand extends Command<void> {
|
||||
help: 'Enables expression evaluation in the debugger.',
|
||||
hide: !verboseHelp,
|
||||
);
|
||||
argParser.addOption('web-launch-url',
|
||||
help: 'The URL to provide to the browser. Defaults to an HTTP URL with the host '
|
||||
'name of "--web-hostname", the port of "--web-port", and the path set to "/".',
|
||||
);
|
||||
}
|
||||
|
||||
void usesTargetOption() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../application_package.dart';
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
@@ -128,7 +129,17 @@ abstract class ChromiumDevice extends Device {
|
||||
}) async {
|
||||
// See [ResidentWebRunner.run] in flutter_tools/lib/src/resident_web_runner.dart
|
||||
// for the web initialization and server logic.
|
||||
final String url = platformArgs['uri']! as String;
|
||||
String url;
|
||||
if (debuggingOptions.webLaunchUrl != null) {
|
||||
final RegExp pattern = RegExp(r'^((http)?:\/\/)[^\s]+');
|
||||
if (pattern.hasMatch(debuggingOptions.webLaunchUrl!)) {
|
||||
url = debuggingOptions.webLaunchUrl!;
|
||||
} else {
|
||||
throwToolExit('"${debuggingOptions.webLaunchUrl}" is not a vaild HTTP URL.');
|
||||
}
|
||||
} else {
|
||||
url = platformArgs['uri']! as String;
|
||||
}
|
||||
final bool launchChrome = platformArgs['no-launch-chrome'] != true;
|
||||
if (launchChrome) {
|
||||
_chrome = await chromeLauncher.launch(
|
||||
|
||||
@@ -594,6 +594,30 @@ void main() {
|
||||
FileSystem: () => MemoryFileSystem.test(),
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('fails when "--web-launch-url" is not supported', () async {
|
||||
final RunCommand command = RunCommand();
|
||||
await expectLater(
|
||||
() => createTestCommandRunner(command).run(<String>[
|
||||
'run',
|
||||
'--web-launch-url=http://flutter.dev',
|
||||
]),
|
||||
throwsA(isException.having(
|
||||
(Exception exception) => exception.toString(),
|
||||
'toString',
|
||||
isNot(contains('web-launch-url')),
|
||||
)),
|
||||
);
|
||||
|
||||
final DebuggingOptions options = await command.createDebuggingOptions(true);
|
||||
expect(options.webLaunchUrl, 'http://flutter.dev');
|
||||
|
||||
final RegExp pattern = RegExp(r'^((http)?:\/\/)[^\s]+');
|
||||
expect(pattern.hasMatch(options.webLaunchUrl), true);
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
Logger: () => BufferLogger.test(),
|
||||
});
|
||||
}
|
||||
|
||||
class FakeDeviceManager extends Fake implements DeviceManager {
|
||||
|
||||
Reference in New Issue
Block a user