line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Selenium::Firefox::Binary; |
2
|
|
|
|
|
|
|
$Selenium::Firefox::Binary::VERSION = '1.49'; |
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Subroutines for locating and properly initializing the Firefox Binary |
7
|
1
|
|
|
1
|
|
30
|
use File::Which qw/which/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
8
|
1
|
|
|
1
|
|
438
|
use Selenium::Firefox::Profile; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
553
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
our @ISA = qw/Exporter/; |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw/firefox_path setup_firefox_binary_env/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _firefox_windows_path { |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# TODO: make this slightly less dumb |
17
|
|
|
|
|
|
|
my @program_files = ( |
18
|
|
|
|
|
|
|
$ENV{PROGRAMFILES} // 'C:\Program Files', |
19
|
0
|
|
0
|
0
|
|
|
$ENV{'PROGRAMFILES(X86)'} // 'C:\Program Files (x86)', |
|
|
|
0
|
|
|
|
|
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
foreach (@program_files) { |
23
|
0
|
|
|
|
|
|
my $binary_path = $_ . '\Mozilla Firefox\firefox.exe'; |
24
|
0
|
0
|
|
|
|
|
return $binary_path if -x $binary_path; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Fall back to a completely naive strategy |
28
|
|
|
|
|
|
|
warn |
29
|
0
|
|
|
|
|
|
q/We couldn't find a viable firefox.EXE; you may want to specify it via the binary attribute./; |
30
|
0
|
|
|
|
|
|
return which('firefox'); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _firefox_darwin_path { |
34
|
0
|
|
|
0
|
|
|
my $default_firefox = |
35
|
|
|
|
|
|
|
'/Applications/Firefox.app/Contents/MacOS/firefox-bin'; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
0
|
|
|
|
if ( -e $default_firefox && -x $default_firefox ) { |
38
|
0
|
|
|
|
|
|
return $default_firefox; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
0
|
|
|
|
|
|
return which('firefox-bin'); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _firefox_unix_path { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# TODO: maybe which('firefox3'), which('firefox2') ? |
48
|
0
|
|
0
|
0
|
|
|
return which('firefox') || '/usr/bin/firefox'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub firefox_path { |
53
|
0
|
|
|
0
|
1
|
|
my $path; |
54
|
0
|
0
|
|
|
|
|
if ( $^O eq 'MSWin32' ) { |
|
|
0
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$path = _firefox_windows_path(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( $^O eq 'darwin' ) { |
58
|
0
|
|
|
|
|
|
$path = _firefox_darwin_path(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
|
$path = _firefox_unix_path; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ( not -x $path ) { |
65
|
0
|
|
|
|
|
|
die $path . ' is not an executable file.'; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $path; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# We want the profile to persist to the end of the session, not just |
73
|
|
|
|
|
|
|
# the end of this function. |
74
|
|
|
|
|
|
|
my $profile; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub setup_firefox_binary_env { |
77
|
0
|
|
|
0
|
1
|
|
my ( $port, $marionette_port, $caller_profile ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
0
|
|
|
|
$profile = $caller_profile || Selenium::Firefox::Profile->new; |
80
|
0
|
|
|
|
|
|
$profile->add_webdriver( $port, $marionette_port ); |
81
|
0
|
|
|
|
|
|
$profile->add_marionette($marionette_port); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# For non-geckodriver/marionette startup, we instruct Firefox to |
84
|
|
|
|
|
|
|
# use the profile by specifying the appropriate environment |
85
|
|
|
|
|
|
|
# variables for it to hook onto. |
86
|
0
|
0
|
|
|
|
|
if ( !$marionette_port ) { |
87
|
0
|
|
|
|
|
|
$ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk; |
88
|
0
|
|
|
|
|
|
$ENV{'MOZ_NO_REMOTE'} = '1'; # able to launch multiple instances |
89
|
0
|
|
|
|
|
|
$ENV{'MOZ_CRASHREPORTER_DISABLE'} = '1'; # disable breakpad |
90
|
0
|
|
|
|
|
|
$ENV{'NO_EM_RESTART'} = |
91
|
|
|
|
|
|
|
'1'; # prevent the binary from detaching from the console.log |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
|
|
|
|
|
|
# In case the user created an old Firefox, which would've set |
95
|
|
|
|
|
|
|
# those ENV variables, and then wanted to create a new Firefox |
96
|
|
|
|
|
|
|
# afterwards, the env variables would still be around, and the |
97
|
|
|
|
|
|
|
# new Firefox would respect the XRE_PROFILE_PATH and try to |
98
|
|
|
|
|
|
|
# load it in the new geckodriver Firefox, which would cause an |
99
|
|
|
|
|
|
|
# extension compatibility check |
100
|
0
|
|
|
|
|
|
my @env_vars = qw/ |
101
|
|
|
|
|
|
|
XRE_PROFILE_PATH |
102
|
|
|
|
|
|
|
MOZ_NO_REMOTE |
103
|
|
|
|
|
|
|
MOZ_CRASHREPORTER_DISABLE |
104
|
|
|
|
|
|
|
NO_EM_RESTART |
105
|
|
|
|
|
|
|
/; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
foreach (@env_vars) { |
108
|
0
|
|
|
|
|
|
delete $ENV{$_}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return $profile; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |