Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in processor.js when using the vision_deficiency option #128

Merged
merged 2 commits into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/grover/js/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
// Emulate the media features, if specified
const mediaFeatures = options.mediaFeatures; delete options.mediaFeatures;
if (Array.isArray(mediaFeatures)) {
page.emulateMediaFeatures(mediaFeatures);
await page.emulateMediaFeatures(mediaFeatures);
}

// Emulate timezone (if provided)
Expand All @@ -100,28 +100,22 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
await page.emulateTimezone(timezone);
}

// Emulate vision deficiency (if provided)
const visionDeficiency = options.visionDeficiency; delete options.visionDeficiency;
if (visionDeficiency !== undefined) {
page.emulateVisionDeficiency(type);
}

// Bypass CSP (content security policy), if provided
const bypassCSP = options.bypassCSP; delete options.bypassCSP;
if (bypassCSP !== undefined) {
page.setBypassCSP(bypassCSP);
await page.setBypassCSP(bypassCSP);
}

// Add extra HTTP headers (if provided)
const extraHTTPHeaders = options.extraHTTPHeaders; delete options.extraHTTPHeaders;
if (extraHTTPHeaders !== undefined) {
page.setExtraHTTPHeaders(extraHTTPHeaders);
await page.setExtraHTTPHeaders(extraHTTPHeaders);
}

// Set geolocation (if provided)
const geolocation = options.geolocation; delete options.geolocation;
if (geolocation !== undefined) {
page.setGeolocation(geolocation);
await page.setGeolocation(geolocation);
}

const raiseOnRequestFailure = options.raiseOnRequestFailure; delete options.raiseOnRequestFailure;
Expand Down Expand Up @@ -201,6 +195,12 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
await page.waitForTimeout(waitForTimeout);
}

// Emulate vision deficiency (if provided)
const visionDeficiency = options.visionDeficiency; delete options.visionDeficiency;
if (visionDeficiency !== undefined) {
await page.emulateVisionDeficiency(visionDeficiency);
}

// If specified, focus on the specified selector
const focusSelector = options.focus; delete options.focus;
if (focusSelector !== undefined) {
Expand Down
13 changes: 13 additions & 0 deletions spec/grover/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,19 @@
end
end

# Only test `emulateVisionDeficiency` if the Puppeteer supports it
if puppeteer_version_on_or_after? '3.2.0'
context 'when vision deficiency is set to `deuteranopia`' do
let(:url_or_html) { '<html><body style="background-color: red"></body></html>' }
let(:options) { { 'visionDeficiency' => 'deuteranopia' } }

it { expect(convert.unpack('C*')).to start_with "\x89PNG\r\n\x1A\n".unpack('C*') }
it { expect(image.type).to eq 'PNG' }
it { expect(image.dimensions).to eq [800, 600] }
it { expect(mean_colour_statistics(image)).to eq %w[94 71 0] }
end
end

context 'when specifying type of `png`' do
let(:url_or_html) { '<html><body style="background-color: green"></body></html>' }
let(:options) { { type: 'png' } }
Expand Down