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

Config for evaluateOnNewDocument? #268

Closed
rasmus0201 opened this issue Nov 21, 2024 · 4 comments · Fixed by #269
Closed

Config for evaluateOnNewDocument? #268

rasmus0201 opened this issue Nov 21, 2024 · 4 comments · Fixed by #269

Comments

@rasmus0201
Copy link
Contributor

Hi. I'm trying to add a script to the page before the script execution starts (to set some env configs for the in-page JS)

This seems to be doable with page.evaluateOnNewDocument() in Puppeteer - https://pptr.dev/api/puppeteer.page.evaluateonnewdocument

Is this something you could be interested adding to Grover?

@abrom
Copy link
Contributor

abrom commented Nov 21, 2024

hey @rasmus0201, that sounds like a useful feature. I'd welcome a PR for it 😄

@abrom
Copy link
Contributor

abrom commented Nov 21, 2024

would be a case of following a similar pattern (and location) of these: https://github.com/Studiosity/grover/blob/main/lib/grover/js/processor.cjs#L107-L185

Then add a test to ensure we don't get regressions, likely in https://github.com/Studiosity/grover/blob/main/spec/grover/processor_spec.rb

Likely something like:

content 'when passing through evaluateOnNewDocument option' do
  let(:url_or_html) do
    <<-HTML
      <html>
        <body>
          Evaluate on new doc <span id="test">did not run</span>
          <script type="text/javascript">
            document.getElementById("test").innerHTML = window.preEvalContent;
          </script>
        </body>
      </html>
    HTML
  end
  let(:options) { { 'evaluateOnNewDocument' => 'window.preEvalContent = "ran!"' } }

  it { expect(pdf_text_content).to eq 'Evaluate on new doc ran!' }
end

i.e the only way this would pass is if that evaluate code had run before the page rendered. It wouldn't work with executeScript option for example.

@rasmus0201
Copy link
Contributor Author

Thank you - I will try and make a PR 😊

@rasmus0201
Copy link
Contributor Author

@abrom I've created #269

The new test is passing, though the whole test suite has some failures (at least on my machine)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants