Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rnevesgg/grover
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: Studiosity/grover
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 7 commits
  • 8 files changed
  • 2 contributors

Commits on Jan 13, 2025

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f15b95d View commit details
  2. Bump version to 1.2.2

    abrom committed Jan 13, 2025

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    abrom Andrew Bromwich
    Copy the full SHA
    5a858c5 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    db1c420 View commit details

Commits on Jan 31, 2025

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ff760bb View commit details
  2. Bump version to 1.2.3

    abrom committed Jan 31, 2025

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    abrom Andrew Bromwich
    Copy the full SHA
    aeecb2c View commit details

Commits on Feb 6, 2025

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    abrom Andrew Bromwich
    Copy the full SHA
    fc7eef5 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    abrom Andrew Bromwich
    Copy the full SHA
    ef0992a View commit details
Showing with 94 additions and 14 deletions.
  1. +8 −4 .github/workflows/test.yml
  2. +9 −0 CHANGELOG.md
  3. +1 −2 Gemfile
  4. +61 −0 README.md
  5. +1 −1 grover.gemspec
  6. +12 −5 lib/grover/middleware.rb
  7. +1 −1 lib/grover/version.rb
  8. +1 −1 package.json
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@ on:
pull_request:
branches: [main]

env:
CC_TEST_REPORTER_ID: 5cfed40102c670b5c9e509730782b751939ddbe53fc57c317b718f635bab1ce8

jobs:
test:
runs-on: ubuntu-latest
@@ -17,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: ['3.3']
ruby-version: ['3.4']
node-version: ['18']
puppeteer-version: [
'18.2.1',
@@ -38,9 +41,12 @@ jobs:
node-version: '18'
puppeteer-version: '23.8.0'
- ruby-version: '3.3'
node-version: '18'
puppeteer-version: '23.8.0'
- ruby-version: '3.4'
node-version: '20'
puppeteer-version: '23.8.0'
- ruby-version: '3.3'
- ruby-version: '3.4'
node-version: '22'
puppeteer-version: '23.8.0'

@@ -81,5 +87,3 @@ jobs:

- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v3.2.0
env:
CC_TEST_REPORTER_ID: 5cfed40102c670b5c9e509730782b751939ddbe53fc57c317b718f635bab1ce8
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,14 @@
## Unreleased
- none

## [1.2,3](releases/tag/v1.2.3) - 2025-01-31
### Fixed
- [#281](https://github.com/Studiosity/grover/pull/281) Fix regression in middleware to support pre-Rack 3.x header key format ([@abrom][])

## [1.2,2](releases/tag/v1.2.2) - 2025-01-13
### Added
- [#275](https://github.com/Studiosity/grover/pull/275) Add support for Ruby 3.4 ([@murajun1978][])

## [1.2.1](releases/tag/v1.2.1) - 2024-11-26
### Added
- [#269](https://github.com/Studiosity/grover/pull/269) Add `evaluate_on_new_document` option ([@rasmus0201][])
@@ -348,3 +356,4 @@
[@jkowens]: https://github.com/jkowens
[@le0pard]: https://github.com/le0pard
[@rasmus0201]: https://github.com/rasmus0201
[@murajun1978]: https://github.com/murajun1978
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -17,6 +17,5 @@ gem 'rspec', '~> 3.13'
gem 'rubocop', '~> 1.68'
gem 'rubocop-rake', '~> 0.6'
gem 'rubocop-rspec', '~> 3.2'
gem 'simplecov', '~> 0.22.0'
gem 'sinatra', '~> 4.1'
# Limit simplecov to 0.17.x due to https://github.com/codeclimate/test-reporter/issues/413
gem 'simplecov', '~> 0.17', '< 0.18'
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -531,6 +531,67 @@ the HTML/JS you provide to Grover.
};
```
## "Failed to launch the browser process!" and "No usable sandbox!"
Errors around no usable sandbox are likely caused by changes to how linux secures itself with apparmor. This restricts
which applications are allowed to create sandboxes on the system, including and as required by puppeteer.
This resource talks about some of the options available, but note that it is talking in the context of DEVELOPER Chrome
builds: https://chromium.googlesource.com/chromium/src/+/main/docs/security/apparmor-userns-restrictions.md
However, that does point to what solutions might look like.
### Option 1. Use the version of Chrome that your system already allows
Most systems will likely have an apparmor profile for the system installed Chrome, so the easiest option may be to just
tell Grover to use that. eg:
```ruby
executable_path: '/opt/google/chrome/chrome' # this path may be different depending on your system
```
The problem with this solution is that puppeteer is somewhat designed to be run with a specific version of Chrome. If
you use the version installed on your system that may not match the puppeteer version, and as such may have
incompatibilities.

### Option 2. Tell your system to allow the Puppeteer installed Chrome
Alternatively, you could create a new apparmor profile for the puppeteer managed version of Chrome. Something like:
```shell
export PUPPETEER_CHROME_PATH=$(node -e "console.log(require('puppeteer').executablePath())")
cat | sudo tee /etc/apparmor.d/chrome <<EOF
abi <abi/4.0>,
include <tunables/global>
profile chrome $PUPPETEER_CHROME_PATH flags=(unconfined) {
userns,
# Site-specific additions and overrides. See local/README for details.
include if exists <local/chrome>
}
EOF
sudo service apparmor reload # reload AppArmor profiles to include the new one
```
However, it is important when using this method to also explicitly set the `executable_path` within your Grover code to
reference this same Puppeteer Chrome path. By default, if you don't explicitly specify the executable path, Puppeteer
will ACTUALLY use `chrome-headless-shell` and not `chrome`
(both would likely be installed in `~/.cache/puppeteer/` by default when installing the `puppeteer` NPM package).
See https://pptr.dev/guides/headless-modes

### Option 3. Tell your system to allow the Puppeteer installed headless shell version of Chrome
If you prefer not to overload the executable path, you could instead create an apparmor profile for
`chrome-headless-shell` as such:
```shell
export CHROME_HEADLESS_SHELL_PATH=$(find ~/.cache/puppeteer/chrome-headless-shell/ -executable -type f -name chrome-headless-shell -print -quit)
cat | sudo tee /etc/apparmor.d/chrome-headless-shell <<EOF
abi <abi/4.0>,
include <tunables/global>
profile chrome-headless-shell $CHROME_HEADLESS_SHELL_PATH flags=(unconfined) {
userns,
# Site-specific additions and overrides. See local/README for details.
include if exists <local/chrome>
}
EOF
sudo service apparmor reload # reload AppArmor profiles to include the new one
```

## Debugging
If you're having trouble with converting the HTML content, you can enable some debugging options to help. These can be
enabled as global options via `Grover.configure`, by passing through to the Grover initializer, or using meta tag
2 changes: 1 addition & 1 deletion grover.gemspec
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
SUMMARY
spec.homepage = 'https://github.com/Studiosity/grover'
spec.license = 'MIT'
spec.required_ruby_version = ['>= 3.0.0', '< 3.4.0']
spec.required_ruby_version = ['>= 3.0.0', '< 3.5.0']

# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
17 changes: 12 additions & 5 deletions lib/grover/middleware.rb
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ def ignore_request?
end

def html_content?(headers)
headers['content-type'] =~ %r{text/html|application/xhtml\+xml}
headers[lower_case_headers? ? 'content-type' : 'Content-Type'] =~ %r{text/html|application/xhtml\+xml}
end

def update_response(response, headers)
@@ -155,11 +155,12 @@ def fetch_cover_pdf(path)

def assign_headers(headers, body, content_type)
# Do not cache results
headers.delete 'etag'
headers.delete 'cache-control'
headers.delete(lower_case_headers? ? 'etag' : 'ETag')
headers.delete(lower_case_headers? ? 'cache-control' : 'Cache-Control')

headers['content-length'] = (body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers['content-type'] = content_type
headers[lower_case_headers? ? 'content-length' : 'Content-Length'] =
(body.respond_to?(:bytesize) ? body.bytesize : body.size).to_s
headers[lower_case_headers? ? 'content-type' : 'Content-Type'] = content_type
end

def configure_env_for_grover_request(env)
@@ -223,5 +224,11 @@ def scrub_env!(env)
env.delete 'CONTENT_LENGTH'
env.delete 'RAW_POST_DATA'
end

def lower_case_headers?
return @lower_case_headers if defined? @lower_case_headers

@lower_case_headers = Gem::Version.new(Rack.release) >= Gem::Version.new('3')
end
end
end
2 changes: 1 addition & 1 deletion lib/grover/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Grover
VERSION = '1.2.1'
VERSION = '1.2.3'
end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grover",
"version": "1.2.1",
"version": "1.2.3",
"description": "A Ruby gem to transform HTML into PDFs using Google Puppeteer/Chromium",
"repository": {
"type": "git",