Skip to content

Commit 8e7ce04

Browse files
authored
Add support for Firefox browser (#297)
1 parent 52407a0 commit 8e7ce04

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ jobs:
7070
- name: Install Puppeteer
7171
run: npm install puppeteer@${{ matrix.puppeteer-version }}
7272

73+
- name: Install Firefox
74+
if: ${{ matrix.puppeteer-version != '22.15.0' }}
75+
run: npx puppeteer browsers install firefox@stable
76+
7377
- name: Install Imagemagick
7478
uses: mfinelli/setup-imagemagick@v5
7579

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ The Chrome/Chromium executable path can be overridden with the `executable_path`
168168
Supplementary JavaScript can be executed on the page (after render and before conversion to PDF/image)
169169
by passing it to the `execute_script` option.
170170

171-
```javascript
171+
```ruby
172172
Grover.new(<some url>, execute_script: 'document.getElementsByTagName("footer")[0].innerText = "Hey"').to_pdf
173173
```
174174

175175
You can also evaluate JavaScript on the page before any of its scripts is run, by passing it a string to the `evaluate_on_new_document` option. See https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.page.evaluateonnewdocument.md
176176

177-
```javascript
177+
```ruby
178178
Grover.new(<some url>, evaluate_on_new_document: 'window.someConfig = "some value"').to_pdf
179179
```
180180

@@ -186,6 +186,14 @@ only really makes sense if you're calling Grover directly (and not via middlewar
186186
Grover.new('<some URI with basic authentication', username: 'the username', password: 'super secret').to_pdf
187187
```
188188

189+
#### Firefox
190+
191+
Grover can drive Firefox by specifying the `browser` option
192+
193+
```ruby
194+
Grover.new('<some URI>', browser: 'firefox').to_pdf
195+
```
196+
189197
#### Remote Chromium
190198

191199
By default, Grover launches a local Chromium instance. You can connect to a remote/external

lib/grover/js/processor.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ const _processPage = (async (convertAction, uriOrHtml, options) => {
9292
launchParams.args = launchParams.args.concat(args);
9393
}
9494

95+
// Set browser type if given
96+
const browserType = options.browser; delete options.browser;
97+
if (browserType) {
98+
launchParams.browser = browserType;
99+
}
100+
95101
// Set executable path if given
96102
const executablePath = options.executablePath; delete options.executablePath;
97103
if (executablePath) {

spec/grover/processor_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,19 @@
10851085
end
10861086
end
10871087
end
1088+
1089+
# < v23 of puppeteer has issues installing the latest firefox versions (bz2 vs xz compression used for packaging)
1090+
if puppeteer_version_on_or_after? '23'
1091+
context 'when specifying Firefox browser' do
1092+
let(:options) { { 'browser' => 'firefox', 'executablePath' => firefox_path } }
1093+
let(:firefox_path) { Dir[File.expand_path('~/.cache/puppeteer/firefox/**/firefox')].last }
1094+
let(:url_or_html) { 'http://localhost:4567/headers' }
1095+
1096+
it { expect(pdf_text_content).to match(/Request contained \d+ headers/) }
1097+
it { expect(pdf_text_content).to include '1. host localhost:4567' }
1098+
it { expect(pdf_text_content).to match %r{\d\. user-agent Mozilla/5.0 .* Firefox/} }
1099+
end
1100+
end
10881101
end
10891102

10901103
context 'when converting to an image' do

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
if ENV['CI'] == 'true'
1818
# Retry
1919
config.verbose_retry = true
20-
config.default_retry_count = 2
20+
config.default_retry_count = 3
2121
config.default_sleep_interval = 5
2222
end
2323

0 commit comments

Comments
 (0)