Skip to content

Commit

Permalink
Improve error message when no WS endpoint was read from Chrome
Browse files Browse the repository at this point in the history
Inspired by GH #61
  • Loading branch information
Max Maischein committed Aug 15, 2021
1 parent 0a8d8f3 commit 5bb4389
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/WWW/Mechanize/Chrome.pm
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ sub read_devtools_url( $self, $fh, $lines = 10 ) {
my $line = <$fh>;
last unless defined $line;
$line =~ s!\s+$!!;
#$self->log('trace', "[[$line]]");
$self->log('trace', "[[$line]]");
if( $line =~ m!^DevTools listening on (ws:\S+)$!) {
$devtools_url = $1;
$self->log('trace', "Found ws endpoint from child output as '$devtools_url'");
Expand Down Expand Up @@ -1029,6 +1029,14 @@ sub _spawn_new_chrome_instance( $self, $options ) {
$options->{ endpoint } = $self->read_devtools_url( $chrome_stdout );
close $chrome_stdout;

if( ! $options->{endpoint} ) {
die join ' ',
"Could not read websocket endpoint from Chrome output.",
"Do you maybe have a non-debug instance of Chrome",
"already running?"
;
};

# set up host/port here so it can be used later by other instances
my $ws = URI->new( $options->{endpoint});
$options->{port} = $ws->port;
Expand Down

0 comments on commit 5bb4389

Please sign in to comment.