mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[web] Adding profile parameter to firefox (#18792)
* opening firefox with a given profile * use .dart_tool for temporary directory. delete the directory if exits before creation
This commit is contained in:
parent
1482d9b05e
commit
201dc00cb9
@ -8,11 +8,13 @@ import 'dart:io';
|
||||
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports
|
||||
|
||||
import 'browser.dart';
|
||||
import 'firefox_installer.dart';
|
||||
import 'common.dart';
|
||||
import 'environment.dart';
|
||||
import 'firefox_installer.dart';
|
||||
|
||||
/// A class for running an instance of Firefox.
|
||||
///
|
||||
@ -43,13 +45,31 @@ class Firefox extends Browser {
|
||||
infoLog: isCirrus ? stdout : DevNull(),
|
||||
);
|
||||
|
||||
// Using a profile on opening will prevent popups related to profiles.
|
||||
final _profile = '''
|
||||
user_pref("browser.shell.checkDefaultBrowser", false);
|
||||
user_pref("dom.disable_open_during_load", false);
|
||||
user_pref("dom.max_script_run_time", 0);
|
||||
''';
|
||||
|
||||
final Directory temporaryProfileDirectory = Directory(
|
||||
path.join(environment.webUiDartToolDir.path, 'firefox_profile'));
|
||||
|
||||
// A good source of various Firefox Command Line options:
|
||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#Browser
|
||||
//
|
||||
var dir = createTempDir();
|
||||
if (temporaryProfileDirectory.existsSync()) {
|
||||
temporaryProfileDirectory.deleteSync();
|
||||
}
|
||||
temporaryProfileDirectory.createSync(recursive: true);
|
||||
|
||||
File(path.join(temporaryProfileDirectory.path, 'prefs.js'))
|
||||
.writeAsStringSync(_profile);
|
||||
bool isMac = Platform.isMacOS;
|
||||
var args = [
|
||||
url.toString(),
|
||||
'--profile',
|
||||
'${temporaryProfileDirectory.path}',
|
||||
'--headless',
|
||||
'-width $kMaxScreenshotWidth',
|
||||
'-height $kMaxScreenshotHeight',
|
||||
@ -59,14 +79,14 @@ class Firefox extends Browser {
|
||||
];
|
||||
|
||||
final Process process =
|
||||
await Process.start(installation.executable, args,
|
||||
workingDirectory: dir);
|
||||
await Process.start(installation.executable, args);
|
||||
|
||||
remoteDebuggerCompleter.complete(
|
||||
getRemoteDebuggerUrl(Uri.parse('http://localhost:$kDevtoolsPort')));
|
||||
|
||||
unawaited(process.exitCode
|
||||
.then((_) => Directory(dir).deleteSync(recursive: true)));
|
||||
unawaited(process.exitCode.then((_) {
|
||||
temporaryProfileDirectory.deleteSync(recursive: true);
|
||||
}));
|
||||
|
||||
return process;
|
||||
}, remoteDebuggerCompleter.future);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user