-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathedge.pl
87 lines (73 loc) · 2.23 KB
/
edge.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!perl -w
package WWW::Mechanize::Edge;
use Carp qw(croak);
use Moo;
use Filter::signatures;
use feature 'signatures';
no warnings 'experimental::signatures';
extends 'WWW::Mechanize::Chrome';
# c:\Users\Corion\AppData\Local\Microsoft\WindowsApps\MicrosoftEdge.exe
# Returns additional directories where the default executable can be found
# on this OS
sub additional_executable_search_directories( $class, $os_style=$^O ) {
my @search;
if( $os_style =~ /MSWin/i ) {
push @search,
map { "$_\\Microsoft\\WindowsApps" }
grep {defined}
($ENV{'LOCALAPPDATA'},
);
}
@search
}
sub default_executable_names( $class, @other ) {
my @program_names
= grep { defined($_) } (
$ENV{EDGE_BIN},
@other,
);
if( ! @program_names ) {
push @program_names,
$^O =~ /mswin/i ? 'MicrosoftEdge.exe'
: ()
#: $^O =~ /darwin/i ? 'Google Chrome'
#: ('google-chrome', 'chromium-browser')
};
@program_names
}
sub build_command_line( $class, $options ) {
my @program_names = $class->default_executable_names( $options->{launch_exe} );
warn "[[@program_names]]";
my( $program, $error) = $class->find_executable(\@program_names);
croak $error if ! $program;
$options->{port} ||= 9222
if ! exists $options->{port};
push @{ $options->{ launch_arg }}, '--devtools-server-port', $options->{ port };
$options->{ launch_arg } ||= [];
# We will need a magic cookie so we find the tab that pops up
$options->{ start_url } ||= "about:blank";
push @{ $options->{ launch_arg }}, "$options->{start_url}"
if exists $options->{start_url};
my @cmd=( $program, @{ $options->{launch_arg}} );
@cmd
};
sub _setup_driver_future( $self, %options ) {
$self->driver->connect(
#new_tab => !$options{ reuse },
tab => qr/^about:blank$/i,
)->catch( sub(@args) {
my $err = $args[0];
if( ref $args[1] eq 'HASH') {
$err .= $args[1]->{Reason};
};
Future->fail( $err );
})
}
1;
package main;
use strict;
use Log::Log4perl ':easy';
Log::Log4perl->easy_init($TRACE);
my $mech = WWW::Mechanize::Edge->new(
);
$mech->get('https://example.com');