ferrum-har 0.1.3 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 140d6f93cceb0ee84d05e449aa1fb5a8680a562002850a6ac6e8aeb475505f12
4
- data.tar.gz: 14dbb30ee107b7562e3167c44d8cd6460bb5d52a7dd1856caa849dd2e4c1b0f6
3
+ metadata.gz: 652f3679a70306ac244d2a0627a3609da85ae96c8360365c3b21c1cb315b994c
4
+ data.tar.gz: 77443a4e93f2e05dfbc63b3370176778c2857a4bdf8663c4c953a88f6eca635d
5
5
  SHA512:
6
- metadata.gz: a157840990fdadd2b2dc4c42a9e0464f3b2ef1206da1c3cbd8c7f703d7e4ce5e309298eb25c43818907099fccb4d92329506fa56399f21edcc1e5f9980769b5c
7
- data.tar.gz: dc280c46aa7285b6dbbaa0f11af62a7279e6d4272b9320171d06da3a1059950f307b5b6d294677d75206eac95f46278480062f0f7f2044e3aced3040ecc3ca71
6
+ metadata.gz: '0358163ac7ff98f450c9027f2909713d8d5fcfafb0e0668de62d3de288b62912b2109a091340236bb3719b12a92e159be0ab3f379fb3137120f4e900110ec536'
7
+ data.tar.gz: 6b5aab790b3d341338734b73527bdc3532613fc2248b3b291d1cf856b96b0444bb3073ca4f8fbe053ae5db806807a0f00834304ed22cb950602a15f324e0d32a
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  ferrum-har
2
2
  ================
3
3
 
4
- [![Gem Version](https://img.shields.io/gem/v/ferrum-har?color=green)](https://img.shields.io/gem/v/ferrum-har?color=green)
4
+ [![Gem Version](https://img.shields.io/gem/v/ferrum-har?color=green)](https://rubygems.org/gems/ferrum-har)
5
+ [![specs workflow](https://github.com/hlascelles/ferrum-har/actions/workflows/specs.yml/badge.svg)](https://github.com/hlascelles/ferrum-har/actions)
6
+ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
7
 
6
8
  [ferrum-har](https://github.com/hlascelles/ferrum-har) is a gem that adds the ability to capture
7
9
  [HAR](https://en.wikipedia.org/wiki/HAR_(file_format)) files while running tests
@@ -15,6 +17,17 @@ Add ferrum-har to your Gemfile and `bundle install`:
15
17
  gem "ferrum-har"
16
18
  ```
17
19
 
20
+ Since version 1.0, we have had to support [a change](https://developer.chrome.com/blog/extension-news-june-2025#deprecations)
21
+ to the way Chrome handles extensions. You must
22
+ use Chrome Testing to use ferrum-har. A rake task is provided to help you download a chrome binary.
23
+ It will put it in a folder called
24
+
25
+ ```bash
26
+ bundle exec rake chrome:install
27
+ ```
28
+
29
+ Alternatively you can use the ENV `BROWSER_PATH` to point to the binary location.
30
+
18
31
  ## Usage
19
32
 
20
33
  Use [ferrum](https://github.com/rubycdp/ferrum) as normal and call the `har` method on
@@ -27,6 +40,7 @@ test run. This is mandatory to obtain the HAR from Chrome.
27
40
  browser = Ferrum::Browser.new
28
41
  page = browser.create_page
29
42
  page.go_to("https://www.bbc.co.uk")
43
+ page.network.wait_for_idle
30
44
 
31
45
  # Returns the HAR as a JSON string
32
46
  puts page.har
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module is prepended to Ferrum::Browser::Command to check options required by ferrum-har
4
+ module Ferrum
5
+ module Har
6
+ class ConfigurationError < RuntimeError
7
+ end
8
+
9
+ module BrowserCommandExtension
10
+ def merge_options
11
+ super.tap do |options|
12
+ check_har_related_browser_options(options)
13
+ end
14
+
15
+ @path = ENV["BROWSER_PATH"] ||
16
+ begin
17
+ # Find the one in the temp download dir.
18
+ Dir.glob(".chrome-for-testing/*/chrome-linux64/chrome").max_by { |p|
19
+ Gem::Version.new(p.split("/")[1])
20
+ }
21
+ end
22
+ end
23
+
24
+ private def check_har_related_browser_options(options)
25
+ options = options.transform_keys(&:to_s)
26
+
27
+ check_disable_extensions_option(options)
28
+ check_load_extension_option(options)
29
+ check_auto_open_option(options)
30
+ check_headless_option(options)
31
+ end
32
+
33
+ private def check_disable_extensions_option(options)
34
+ disable_extensions_option_value = options.key?("disable-extensions")
35
+ return unless disable_extensions_option_value
36
+
37
+ raise Ferrum::Har::ConfigurationError, <<~MSG
38
+ The ferrum-har gem requires the 'disable-extensions' browser option to be absent,
39
+ ie: extensions should be allowed. The gem will do this for you automatically, but if you
40
+ override the value, then ferrum-har will not work.
41
+
42
+ It was found to be set to '#{disable_extensions_option_value}'.
43
+ MSG
44
+ end
45
+
46
+ private def check_load_extension_option(options)
47
+ load_extension_option_value = options["load-extension"]
48
+ return unless load_extension_option_value != "#{Ferrum::Har::GEM_DIR}/extension"
49
+
50
+ raise Ferrum::Har::ConfigurationError, <<~MSG
51
+ The ferrum-har gem requires the 'load-extension' browser option to be set to
52
+ '#{Ferrum::Har::GEM_DIR}/extension'. It will do this for you automatically, but if you
53
+ override the value, then ferrum-har will not work.
54
+
55
+ It was found to be set to '#{load_extension_option_value}'.
56
+ MSG
57
+ end
58
+
59
+ private def check_auto_open_option(options)
60
+ auto_open_value = options["auto-open-devtools-for-tabs"]
61
+ return if auto_open_value.nil?
62
+
63
+ raise Ferrum::Har::ConfigurationError, <<~MSG
64
+ The ferrum-har gem requires the 'auto-open-devtools-for-tabs' browser option be enabled,
65
+ '#{Ferrum::Har::GEM_DIR}/extension'. It will do this for you automatically, but if you
66
+ override the value, then ferrum-har will not work.
67
+ ie: set to nil.
68
+
69
+ It was found to be set to '#{auto_open_value}'.
70
+ MSG
71
+ end
72
+
73
+ private def check_headless_option(options)
74
+ headless_value = options["headless"]
75
+ return unless options.key?("headless") && [false, nil].include?(headless_value)
76
+
77
+ raise Ferrum::Har::ConfigurationError, <<~MSG
78
+ If you are using ferrum headless, the ferrum-har gem requires the browser
79
+ option 'headless' to be set to 'new' instead of true or nil. Read this for more details:
80
+ https://developer.chrome.com/docs/chromium/new-headless
81
+
82
+ It was found to be set to '#{headless_value}'.
83
+ MSG
84
+ end
85
+ end
86
+ end
87
+ end
@@ -10,6 +10,8 @@ module Ferrum
10
10
  # We have to remove the "disable-extensions" option from the default browser extension
11
11
  # list because the ferrum-har gem requires an (internal) extension to work.
12
12
  .except("disable-extensions")
13
+ # At some point past v134 this stopped extensions loading properly in the first tab.
14
+ .except("no-startup-window")
13
15
  .merge(
14
16
  "auto-open-devtools-for-tabs" => nil, # Chrome devtools must be open to invoke getHAR
15
17
  "load-extension" => "#{Ferrum::Har::GEM_DIR}/extension", # Extension that gets the HAR
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ferrum
4
4
  module Har
5
- VERSION = "0.1.3"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
data/lib/ferrum/har.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "ferrum"
4
4
  require "ferrum/browser/options/chrome"
5
5
  require "ferrum/har/version"
6
+ require "ferrum/har/command_extension"
6
7
  require "ferrum/har/page_extension"
7
8
  require "ferrum/har/options_extension"
8
9
 
@@ -17,3 +18,6 @@ Ferrum::Page.prepend(Ferrum::Har::PageExtension)
17
18
 
18
19
  # Add the #merge_default method to Ferrum::Browser::Options::Chrome
19
20
  Ferrum::Browser::Options::Chrome.prepend(Ferrum::Har::OptionsExtension)
21
+
22
+ # Add the #check_har_related_browser_options method to Ferrum::Browser::Command
23
+ Ferrum::Browser::Command.prepend(Ferrum::Har::BrowserCommandExtension)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferrum-har
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Lascelles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-22 00:00:00.000000000 Z
11
+ date: 2025-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: selenium_chrome_helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Rubygem to convert ferrum traffic to HAR files
42
56
  email:
43
57
  - harry@harrylascelles.com
@@ -52,6 +66,7 @@ files:
52
66
  - extension/panel.html
53
67
  - extension/panel.js
54
68
  - lib/ferrum/har.rb
69
+ - lib/ferrum/har/command_extension.rb
55
70
  - lib/ferrum/har/options_extension.rb
56
71
  - lib/ferrum/har/page_extension.rb
57
72
  - lib/ferrum/har/version.rb
@@ -73,14 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
88
  requirements:
74
89
  - - ">="
75
90
  - !ruby/object:Gem::Version
76
- version: '3.0'
91
+ version: '0'
77
92
  required_rubygems_version: !ruby/object:Gem::Requirement
78
93
  requirements:
79
94
  - - ">="
80
95
  - !ruby/object:Gem::Version
81
96
  version: '0'
82
97
  requirements: []
83
- rubygems_version: 3.5.3
98
+ rubygems_version: 3.5.22
84
99
  signing_key:
85
100
  specification_version: 4
86
101
  summary: Rubygem to convert ferrum traffic to HAR files