ferrum-har 1.0.0 → 1.0.2
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/README.md +23 -4
- data/lib/ferrum/har/command_extension.rb +15 -7
- data/lib/ferrum/har/options_extension.rb +15 -3
- data/lib/ferrum/har/page_extension.rb +11 -6
- data/lib/ferrum/har/version.rb +1 -1
- data/lib/ferrum/har.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae66c86e06740c5afb98f7633cbf466c71935fd406de55f196ec0c5a92668ed2
|
4
|
+
data.tar.gz: 5da78a09c0f1b07987c9497edaf20f542d0b37e827d944c936a72ad019b44b5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc7dd1f84801f144725b561ed64a0a3c5d54c5b165c053da47a407b9682bcac4cfc62ba7294eea2eef8160744e17c54f845f926fb43dc00f03cef347e3ef511f
|
7
|
+
data.tar.gz: 6d793bb6ea3ff0df10a1b1b5c7576a546a91a5b00108c83491952c768b3e94f32b369ad8666ce8ed7f72ed4f940b7927730ee1605b3f5f0883936504c9e67a63
|
data/README.md
CHANGED
@@ -18,15 +18,18 @@ gem "ferrum-har"
|
|
18
18
|
```
|
19
19
|
|
20
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
|
22
|
-
|
23
|
-
|
21
|
+
to the way Chrome handles extensions which means you must use [Chrome For Testing](https://developer.chrome.com/blog/chrome-for-testing)
|
22
|
+
to use ferrum-har. This involves downloading that Chrome version as a binary.
|
23
|
+
|
24
|
+
A rake task is provided to help you download the binary, supplied by the [selenium_chrome_helper](https://github.com/pepito2k/selenium_chrome_helper) gem.
|
25
|
+
It will put it in a folder called `.chrome-for-testing` in your project root. To execute it, run:
|
24
26
|
|
25
27
|
```bash
|
26
28
|
bundle exec rake chrome:install
|
27
29
|
```
|
28
30
|
|
29
|
-
Alternatively you can use the ENV `BROWSER_PATH` to point to the binary location.
|
31
|
+
Alternatively you can use the ENV `BROWSER_PATH` to point to the binary location. Note, you can't
|
32
|
+
point it to your standard Chrome installation, it must be the Chrome Testing binary.
|
30
33
|
|
31
34
|
## Usage
|
32
35
|
|
@@ -74,10 +77,26 @@ For further reading, a full list of Chrome switches can be found
|
|
74
77
|
`ferrum-har` uses [semantic versioning](https://semver.org/), so major version changes will usually
|
75
78
|
require additional actions to be taken upgrading from one major version to another.
|
76
79
|
|
80
|
+
## Persistent Chrome profile
|
81
|
+
|
82
|
+
You can specify the ENV `FERRUM_HAR_BROWSER_CONFIG_DIR` to point to a persistent Chrome profile dir
|
83
|
+
between runs. This will allow you to do slow setup once, then do fast reruns of your tests. Note
|
84
|
+
this should only be used for development purposes, your tests should not rely on a persistent
|
85
|
+
profile in CI.
|
86
|
+
|
87
|
+
See the [spec/acceptance/test.rb](https://github.com/hlascelles/ferrum-har/blob/master/spec/acceptance/test.rb) for
|
88
|
+
an example of how to use this.
|
89
|
+
|
90
|
+
## Single file example
|
91
|
+
|
92
|
+
A single file example of how to use `ferrum-har` can be found in [spec/acceptance/test.rb](https://github.com/hlascelles/ferrum-har/blob/master/spec/acceptance/test.rb).
|
93
|
+
|
77
94
|
## Changelog
|
78
95
|
|
79
96
|
A full changelog can be found here: [CHANGELOG.md](https://github.com/hlascelles/ferrum-har/blob/master/CHANGELOG.md)
|
80
97
|
|
98
|
+
```
|
99
|
+
|
81
100
|
## Further work
|
82
101
|
|
83
102
|
Some ideas for improvements.
|
@@ -6,19 +6,27 @@ module Ferrum
|
|
6
6
|
class ConfigurationError < RuntimeError
|
7
7
|
end
|
8
8
|
|
9
|
+
class << self
|
10
|
+
def find_chrome_for_testing_binary
|
11
|
+
Dir.glob(".chrome-for-testing/**/chrome").max_by { |p| Gem::Version.new(p.split("/")[1]) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
module BrowserCommandExtension
|
10
16
|
def merge_options
|
11
17
|
super.tap do |options|
|
12
18
|
check_har_related_browser_options(options)
|
13
19
|
end
|
14
20
|
|
15
|
-
@path = ENV["BROWSER_PATH"] ||
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
@path = ENV["BROWSER_PATH"] || Ferrum::Har.find_chrome_for_testing_binary
|
22
|
+
|
23
|
+
return if @path
|
24
|
+
|
25
|
+
raise <<~ERR
|
26
|
+
Browser path not found. Please set BROWSER_PATH environment variable, or trigger a download of Chrome Testing by using:
|
27
|
+
|
28
|
+
bundle exec rake chrome:install
|
29
|
+
ERR
|
22
30
|
end
|
23
31
|
|
24
32
|
private def check_har_related_browser_options(options)
|
@@ -6,9 +6,11 @@ module Ferrum
|
|
6
6
|
module Har
|
7
7
|
module OptionsExtension
|
8
8
|
def merge_default(flags, options)
|
9
|
-
super
|
10
|
-
|
11
|
-
|
9
|
+
original_result = super
|
10
|
+
# We have to remove the "disable-extensions" option from the default browser extension
|
11
|
+
# list because the ferrum-har gem requires an (internal) extension to work.
|
12
|
+
changed =
|
13
|
+
original_result
|
12
14
|
.except("disable-extensions")
|
13
15
|
# At some point past v134 this stopped extensions loading properly in the first tab.
|
14
16
|
.except("no-startup-window")
|
@@ -16,6 +18,16 @@ module Ferrum
|
|
16
18
|
"auto-open-devtools-for-tabs" => nil, # Chrome devtools must be open to invoke getHAR
|
17
19
|
"load-extension" => "#{Ferrum::Har::GEM_DIR}/extension", # Extension that gets the HAR
|
18
20
|
)
|
21
|
+
|
22
|
+
# To get a custom config dir to work, we have to remove the "disable-web-security" option
|
23
|
+
if ENV["FERRUM_HAR_BROWSER_CONFIG_DIR"]
|
24
|
+
changed =
|
25
|
+
changed
|
26
|
+
.except("disable-web-security")
|
27
|
+
.merge("user-data-dir" => ENV["FERRUM_HAR_BROWSER_CONFIG_DIR"])
|
28
|
+
end
|
29
|
+
|
30
|
+
changed
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
@@ -12,7 +12,7 @@ module Ferrum
|
|
12
12
|
def har
|
13
13
|
network.wait_for_idle
|
14
14
|
execute("document.ferrumHarRequested = true;")
|
15
|
-
|
15
|
+
har_hash_result = Ferrum::Utils::Attempt.with_retry(
|
16
16
|
errors: [HarNotReadyError],
|
17
17
|
# 10 seconds
|
18
18
|
max: 20,
|
@@ -21,13 +21,18 @@ module Ferrum
|
|
21
21
|
found = evaluate("document.ferrumHar;")
|
22
22
|
raise HarNotReadyError unless found
|
23
23
|
|
24
|
-
found
|
24
|
+
inlined_har = Base64.decode64(found)
|
25
|
+
har_hash = JSON.parse(inlined_har)
|
26
|
+
raise HarNotReadyError, "Result does not appear to be a HAR" unless har_hash.key?("log")
|
27
|
+
|
28
|
+
entries = har_hash.dig("log", "entries")
|
29
|
+
# If entries is nil or empty, the HAR is not ready yet.
|
30
|
+
raise HarNotReadyError if entries.nil? || entries.empty?
|
31
|
+
|
32
|
+
har_hash
|
25
33
|
end
|
26
|
-
inlined_har = Base64.decode64(base64_encoded_har)
|
27
|
-
har_hash = JSON.parse(inlined_har)
|
28
|
-
raise "Result does not appear to be a HAR" unless har_hash.key?("log")
|
29
34
|
|
30
|
-
JSON.pretty_generate(
|
35
|
+
JSON.pretty_generate(har_hash_result)
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
data/lib/ferrum/har/version.rb
CHANGED
data/lib/ferrum/har.rb
CHANGED
@@ -7,6 +7,13 @@ require "ferrum/har/command_extension"
|
|
7
7
|
require "ferrum/har/page_extension"
|
8
8
|
require "ferrum/har/options_extension"
|
9
9
|
|
10
|
+
# The chrome downloader helper
|
11
|
+
if Gem.loaded_specs.key?("rake")
|
12
|
+
require "selenium_chrome_helper"
|
13
|
+
require "rake"
|
14
|
+
load "tasks/install.rake" # Load the chrome testing downloader task
|
15
|
+
end
|
16
|
+
|
10
17
|
module Ferrum
|
11
18
|
module Har
|
12
19
|
GEM_DIR = File.expand_path("../..", __dir__)
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Lascelles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|