diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ea38f1..1ab808e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,6 +70,10 @@ jobs: - name: Install Puppeteer run: npm install puppeteer@${{ matrix.puppeteer-version }} + - name: Install Firefox + if: ${{ matrix.puppeteer-version != '22.15.0' }} + run: npx puppeteer browsers install firefox@stable + - name: Install Imagemagick uses: mfinelli/setup-imagemagick@v5 diff --git a/README.md b/README.md index 0e7151e..703864b 100644 --- a/README.md +++ b/README.md @@ -168,13 +168,13 @@ The Chrome/Chromium executable path can be overridden with the `executable_path` Supplementary JavaScript can be executed on the page (after render and before conversion to PDF/image) by passing it to the `execute_script` option. -```javascript +```ruby Grover.new(, execute_script: 'document.getElementsByTagName("footer")[0].innerText = "Hey"').to_pdf ``` 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 -```javascript +```ruby Grover.new(, evaluate_on_new_document: 'window.someConfig = "some value"').to_pdf ``` @@ -186,6 +186,14 @@ only really makes sense if you're calling Grover directly (and not via middlewar Grover.new('', browser: 'firefox').to_pdf +``` + #### Remote Chromium By default, Grover launches a local Chromium instance. You can connect to a remote/external diff --git a/lib/grover/js/processor.cjs b/lib/grover/js/processor.cjs index 4655415..76271f0 100644 --- a/lib/grover/js/processor.cjs +++ b/lib/grover/js/processor.cjs @@ -92,6 +92,12 @@ const _processPage = (async (convertAction, uriOrHtml, options) => { launchParams.args = launchParams.args.concat(args); } + // Set browser type if given + const browserType = options.browser; delete options.browser; + if (browserType) { + launchParams.browser = browserType; + } + // Set executable path if given const executablePath = options.executablePath; delete options.executablePath; if (executablePath) { diff --git a/spec/grover/processor_spec.rb b/spec/grover/processor_spec.rb index 5ed9158..d74e532 100644 --- a/spec/grover/processor_spec.rb +++ b/spec/grover/processor_spec.rb @@ -1085,6 +1085,19 @@ end end end + + # < v23 of puppeteer has issues installing the latest firefox versions (bz2 vs xz compression used for packaging) + if puppeteer_version_on_or_after? '23' + context 'when specifying Firefox browser' do + let(:options) { { 'browser' => 'firefox', 'executablePath' => firefox_path } } + let(:firefox_path) { Dir[File.expand_path('~/.cache/puppeteer/firefox/**/firefox')].last } + let(:url_or_html) { 'http://localhost:4567/headers' } + + it { expect(pdf_text_content).to match(/Request contained \d+ headers/) } + it { expect(pdf_text_content).to include '1. host localhost:4567' } + it { expect(pdf_text_content).to match %r{\d\. user-agent Mozilla/5.0 .* Firefox/} } + end + end end context 'when converting to an image' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 215d140..044eea2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,7 @@ if ENV['CI'] == 'true' # Retry config.verbose_retry = true - config.default_retry_count = 2 + config.default_retry_count = 3 config.default_sleep_interval = 5 end