File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -206,7 +206,13 @@ class BrowserTabInstance {
206206 }
207207
208208 Future <void > close () async {
209- await tab.wipConnection.target.closeTarget (tab.wipTab.id);
209+ // In Headless Chrome, we get Inspector.detached when we close the last
210+ // target rather than a response.
211+ await Future .any (< Future <Object >> [
212+ tab.wipConnection.onNotification
213+ .firstWhere ((n) => n.method == 'Inspector.detached' ),
214+ tab.wipConnection.target.closeTarget (tab.wipTab.id),
215+ ]);
210216 }
211217
212218 void _handleBrowserMessage (Map <dynamic , dynamic > message) {
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
1313import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
1414 as wip show ChromeTab;
1515
16+ // Change this if you want to be able to see Chrome opening while tests run
17+ // to aid debugging.
18+ const _useChromeHeadless = true ;
19+
1620class Chrome {
1721 factory Chrome .from (String executable) {
1822 return FileSystemEntity .isFileSync (executable)
@@ -66,6 +70,13 @@ class Chrome {
6670 '--user-data-dir=${getCreateChromeDataDir ()}' ,
6771 '--remote-debugging-port=$debugPort '
6872 ];
73+ if (_useChromeHeadless) {
74+ args.addAll (< String > [
75+ '--headless' ,
76+ '--disable-gpu' ,
77+ '--no-sandbox' ,
78+ ]);
79+ }
6980 if (url != null ) {
7081 args.add (url);
7182 }
@@ -207,7 +218,7 @@ class ChromeTab {
207218 }
208219
209220 Future <String > createNewTarget () {
210- return _wip.target.createTarget ('' );
221+ return _wip.target.createTarget ('about:blank ' );
211222 }
212223
213224 bool get isConnected => _wip != null ;
You can’t perform that action at this time.
0 commit comments