selenium_tor 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -2
- data/CHANGELOG.md +11 -0
- data/README.md +25 -0
- data/lib/tor/driver.rb +39 -11
- data/lib/tor/options.rb +2 -2
- data/lib/tor/version.rb +1 -1
- data/selenium_tor.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aeb8724ddcdf0d7260330ca616651d54b94ce33c6a635c71ef5c5f3577de220
|
4
|
+
data.tar.gz: 12b5d264f6a774dab990148feb15179d0b7873e42eb5b1c4bb99e8383f5e5577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deafbf4cbbc646e2fef5dc1800bc009edceb72906d65dc071942d0c742a49dd6aa17ac4fe2f88fc8d36f909445b31378996073f7d44b8cff473db2e9e3f5d403
|
7
|
+
data.tar.gz: 71c615ce16eb80f696aaa4dc26d73459df4ce8c4b7d994998580be1d93405baa5dc9ee94f321e7494f1567f3bed1f48481e53149829c2e1671268a6069d9d91f
|
data/.rubocop.yml
CHANGED
@@ -10,8 +10,9 @@ AllCops:
|
|
10
10
|
Style/HashSyntax:
|
11
11
|
Enabled: false # yuk Ruby 3.1
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
Naming/MethodName:
|
14
|
+
Exclude:
|
15
|
+
- !ruby/regexp /test_.*\.rb$/ # for test_FOO constant tests
|
15
16
|
|
16
17
|
Security/Eval:
|
17
18
|
Exclude:
|
@@ -28,6 +29,9 @@ Style/RegexpLiteral:
|
|
28
29
|
Minitest/TestMethodName:
|
29
30
|
Enabled: true
|
30
31
|
|
32
|
+
Minitest/AssertTruthy:
|
33
|
+
Enabled: false
|
34
|
+
|
31
35
|
Minitest/TestFileName:
|
32
36
|
Exclude:
|
33
37
|
- test/features/fingerprinting/vglrun_test_fingerprintjs.rb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
## [1.2.0] - 2024-07-31
|
4
|
+
|
5
|
+
### Bug fixes
|
6
|
+
|
7
|
+
* [#11](https://gitlab.com/matzfan/selenium-tor/-/issues/11)
|
8
|
+
|
9
|
+
### New features
|
10
|
+
|
11
|
+
* add ability to change security level
|
12
|
+
* add ability to get new circuit for page ([#10](https://gitlab.com/matzfan/selenium-tor/-/issues/10))
|
13
|
+
|
3
14
|
## [1.1.0] - 2024-07-28
|
4
15
|
|
5
16
|
### Bug fixes
|
data/README.md
CHANGED
@@ -17,6 +17,10 @@ The above approach will hide your IP, but there is a good chance your browser's
|
|
17
17
|
|
18
18
|
## Known issues
|
19
19
|
|
20
|
+
Known issues are recorded [here](https://gitlab.com/matzfan/selenium-tor/-/issues).
|
21
|
+
|
22
|
+
### Fingerprinting
|
23
|
+
|
20
24
|
The gem uses Xvfb to allow Tor Browser to be manipulated headlessly. Xvfb in turn uses `llvmpipe` software acceleration which may lead to issues with WebGL fingerprinting - see [issue #7](https://gitlab.com/matzfan/selenium-tor/-/issues/7). If this is a problem we recommend using [VirtualGL](https://www.virtualgl.org) to force Xvfb to use your hardware driver instead. This is done by prepending your executable code with the command `vglrun`. For an example see the section below on testing. VirtualGL can be installed from a [package repo](https://virtualgl.org/Downloads/YUM).
|
21
25
|
|
22
26
|
## Installation
|
@@ -74,6 +78,27 @@ end
|
|
74
78
|
driver1&.quit
|
75
79
|
driver2&.quit
|
76
80
|
```
|
81
|
+
### Tor Browser specific functionality
|
82
|
+
|
83
|
+
You can get and set the secuirty level (shield icon in TB) as follows. 4 is 'Standard', 2 is 'Safer', 1 is 'Safest'.
|
84
|
+
```ruby
|
85
|
+
@driver = Selenium::WebDriver.for :tor
|
86
|
+
@driver.security_level
|
87
|
+
# => 4 - the default value
|
88
|
+
@driver.security_level = 1
|
89
|
+
@driver.security_level
|
90
|
+
# => 1
|
91
|
+
@driver.quit
|
92
|
+
```
|
93
|
+
You can get a new circuit for the current page ('New Tor circuit for this site' on TB's application menu):
|
94
|
+
```ruby
|
95
|
+
@driver = Selenium::WebDriver.for :tor
|
96
|
+
@driver.get 'https://example.com'
|
97
|
+
@driver.new_circuit_for_page # new circuit for the current page only
|
98
|
+
@driver.quit
|
99
|
+
```
|
100
|
+
### Miscellaneous
|
101
|
+
|
77
102
|
The `Selenium::WebDriver::Tor` namespace is used for `Driver`, `Options`, `Profile` and all tor-specific classes. Otherwise Selenium's `Selenium::WebDriver::Firefox` namespace is used.
|
78
103
|
|
79
104
|
Remote functionality is not tested, but may be if a suitable Tor Browser Docker container becomes available.
|
data/lib/tor/driver.rb
CHANGED
@@ -9,20 +9,23 @@ require_relative 'tor_process'
|
|
9
9
|
module Selenium
|
10
10
|
module WebDriver
|
11
11
|
module Tor
|
12
|
-
# delegate class
|
13
|
-
class
|
12
|
+
# delegate class
|
13
|
+
class DriverDelegate < Firefox::Driver; end
|
14
14
|
|
15
15
|
# tor driver
|
16
|
-
class Driver < DelegateClass(
|
16
|
+
class Driver < DelegateClass(DriverDelegate)
|
17
17
|
class TorNetworkError < StandardError; end
|
18
18
|
|
19
|
+
TB_SECURITY_LEVELS = [4, 2, 1].freeze
|
20
|
+
|
19
21
|
def initialize(options: nil, **)
|
20
22
|
@data_dir = Dir.mktmpdir
|
21
|
-
|
22
|
-
|
23
|
+
@options = options || Options.new # fix for issue #11, 'tis a puzzlement
|
24
|
+
add_torrc_path_to_options
|
25
|
+
@instance = DriverDelegate.new(options: @options, **)
|
26
|
+
install_extensions @instance
|
27
|
+
create_tor_process_and_start_tor @options.tor_opts
|
23
28
|
super(@instance)
|
24
|
-
install_extensions(@instance)
|
25
|
-
create_tor_process_and_start_tor options&.tor_opts
|
26
29
|
end
|
27
30
|
|
28
31
|
def browser
|
@@ -35,12 +38,37 @@ module Selenium
|
|
35
38
|
super
|
36
39
|
end
|
37
40
|
|
38
|
-
|
41
|
+
def security_level
|
42
|
+
old_context = context
|
43
|
+
self.context = 'chrome'
|
44
|
+
execute_script("return Services.prefs.getIntPref('browser.security_level.security_slider')")
|
45
|
+
ensure
|
46
|
+
self.context = old_context
|
47
|
+
end
|
39
48
|
|
40
|
-
def
|
41
|
-
|
49
|
+
def security_level=(int)
|
50
|
+
old_context = context
|
51
|
+
self.context = 'chrome'
|
52
|
+
raise(ArgumentError, 'Security level can be set to 4, 2 or 1') unless TB_SECURITY_LEVELS.include?(int)
|
53
|
+
|
54
|
+
execute_script("return Services.prefs.setIntPref('browser.security_level.security_slider', #{int})")
|
55
|
+
ensure
|
56
|
+
self.context = old_context if old_context
|
57
|
+
end
|
58
|
+
|
59
|
+
def new_circuit_for_page
|
60
|
+
old_context = context
|
61
|
+
self.context = 'chrome'
|
62
|
+
execute_script "ChromeUtils.importESModule('resource://gre/modules/TorDomainIsolator.sys.mjs');
|
63
|
+
TorDomainIsolator.newCircuitForDomain('#{current_url}')"
|
64
|
+
ensure
|
65
|
+
self.context = old_context
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
42
69
|
|
43
|
-
|
70
|
+
def add_torrc_path_to_options
|
71
|
+
@options.prefs['extensions.torlauncher.torrc_path'] = File.join(@data_dir, 'torrc')
|
44
72
|
end
|
45
73
|
|
46
74
|
def install_extensions(instance)
|
data/lib/tor/options.rb
CHANGED
@@ -26,9 +26,9 @@ module Selenium
|
|
26
26
|
def initialize(log_level: nil, **opts)
|
27
27
|
opts[:tor_opts] = opts.delete(:system_tor).opts if opts[:system_tor] # DEPRECATED 2.0
|
28
28
|
@tor_opts = opts[:tor_opts] ? opts.delete(:tor_opts) : {} # must be deleted before call to super
|
29
|
-
super(log_level: log_level, **tor_options(opts.delete(:prefs)).merge(opts))
|
30
29
|
do_start_tor_browser_script_stuff # stuff the start-tor-browser script in TBB does
|
31
|
-
copy_fonts # so we don't have to change dir before executing TB binary #2 and #9
|
30
|
+
copy_fonts # so we don't have to change dir before executing TB binary - issues #2 and #9
|
31
|
+
super(log_level: log_level, **tor_options(opts.delete(:prefs)).merge(opts))
|
32
32
|
end
|
33
33
|
|
34
34
|
private
|
data/lib/tor/version.rb
CHANGED
data/selenium_tor.gemspec
CHANGED
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
|
-
spec.
|
33
|
+
spec.add_dependency 'selenium-webdriver', '>= 4.23'
|
34
34
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selenium_tor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MatzFan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: selenium-webdriver
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4.
|
19
|
+
version: '4.23'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
26
|
+
version: '4.23'
|
27
27
|
description: An extension for Selenium::WebDriver that automates Tor Browser
|
28
28
|
email:
|
29
29
|
executables: []
|