Skip to content

Commit

Permalink
Add waitForSelectorOptions support
Browse files Browse the repository at this point in the history
  • Loading branch information
andmcgregor committed Jun 22, 2020
1 parent fd0f109 commit 228681e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## Unreleased
- None
- [#64](https://github.com/Studiosity/grover/pull/64) Add waitForSelector support ([@andmcgregor][])

## [0.12.1](releases/tag/v0.12.1) - 2020-05-12
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Launch parameter args can also be provided using a meta tag:
For `wait_until` option, default for URLs is `networkidle2` and for HTML content `networkidle0`.
For available options see https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagegotourl-options

The `wait_for_selector` option can also be used to wait until an element appears on the page.
The `wait_for_selector` option can also be used to wait until an element appears on the page. Additional waiting parameters can be set with the `wait_for_selector_options` options hash. For available options, see: https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagewaitforselectorselector-options.

The Chrome/Chromium executable path can be overridden with the `executable_path` option.

Expand Down
3 changes: 2 additions & 1 deletion lib/grover/js/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {

// If specified, wait for selector
const waitForSelector = options.waitForSelector; delete options.waitForSelector;
const waitForSelectorOptions = options.waitForSelectorOptions; delete options.waitForSelectorOptions;
if (waitForSelector !== undefined) {
await page.waitForSelector(waitForSelector)
await page.waitForSelector(waitForSelector, waitForSelectorOptions)
}

// If we're running puppeteer in headless mode, return the converted PDF
Expand Down
29 changes: 28 additions & 1 deletion spec/grover/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
<script>
setTimeout(function() {
document.body.innerHTML = '<h1>Hey there</h1>'
document.body.innerHTML = '<h1>Hey there</h1>';
}, 100);
</script>
</html>
Expand All @@ -411,6 +411,33 @@

it { expect(pdf_text_content).to eq "#{date} Hey there http://www.example.net/foo/bar 1/1" }
end

context 'when wait for selector option is specified with options' do
let(:url_or_html) do
<<-HTML
<html>
<body>
<p id="loading">Loading</p>
</body>
<script>
setTimeout(function() {
document.getElementById('loading').remove()
}, 100);
</script>
</html>
HTML
end
let(:options) do
basic_header_footer_options.merge(
'waitForSelector' => '#loading',
'waitForSelectorOptions' => { 'hidden' => true }
)
end
let(:date) { Date.today.strftime '%-m/%-d/%Y' }

it { expect(pdf_text_content).to eq "#{date} http://www.example.net/foo/bar 1/1" }
end
end

context 'when converting to an image' do
Expand Down

0 comments on commit 228681e

Please sign in to comment.