selenium_tor 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99d3e4260b0873513c67db620d3057d61078b4c1cbae7b5c8c7b3e4cfdbbfbec
4
- data.tar.gz: bb02cb9d07024a4798723185f4103246dac9b4c008e3f20abec5f710426a26a6
3
+ metadata.gz: 6aeb8724ddcdf0d7260330ca616651d54b94ce33c6a635c71ef5c5f3577de220
4
+ data.tar.gz: 12b5d264f6a774dab990148feb15179d0b7873e42eb5b1c4bb99e8383f5e5577
5
5
  SHA512:
6
- metadata.gz: 654db110ca016a71d04b6def25d4befb86efc27cd2c0cce1ed7874834921d309262bc537b6b23bf8b77603b4d29960c88a10d83c8508ce6398b1d44a13577df1
7
- data.tar.gz: 7d7369f8055ca42c229079d8732ab49d8d1467af49d35c547528dd792f1208101abcd123a6f05873b9fee4b704863a364708fc9148850f798635b9f3f6b3b8da
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
- Layout/LineLength:
14
- Max: 120
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 so extensions can be added & connection to tor made
13
- class DriverNotYetConnectedToTorNetwork < Firefox::Driver; end
12
+ # delegate class
13
+ class DriverDelegate < Firefox::Driver; end
14
14
 
15
15
  # tor driver
16
- class Driver < DelegateClass(DriverNotYetConnectedToTorNetwork)
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
- add_torrc_path_to_options options
22
- @instance = DriverNotYetConnectedToTorNetwork.new(options: options, **)
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
- private
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 add_torrc_path_to_options(options)
41
- return unless options
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
- options.prefs['extensions.torlauncher.torrc_path'] = File.join(@data_dir, 'torrc')
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
@@ -3,7 +3,7 @@
3
3
  module Selenium
4
4
  module WebDriver
5
5
  module Tor
6
- VERSION = '1.1.0'
6
+ VERSION = '1.2.0'
7
7
  end
8
8
  end
9
9
  end
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.add_runtime_dependency 'selenium-webdriver', '~> 4.22'
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.1.0
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-28 00:00:00.000000000 Z
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.22'
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.22'
26
+ version: '4.23'
27
27
  description: An extension for Selenium::WebDriver that automates Tor Browser
28
28
  email:
29
29
  executables: []