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 #121: stylesheets/images rendering with puppeteer v10.2.0 #122

Merged
merged 2 commits into from
Aug 21, 2021

Conversation

mkalygin
Copy link
Contributor

@mkalygin mkalygin commented Aug 19, 2021

In puppeteer v10.2.0 they introduced changes to the way request interception handlers are processed:

It caused a race condition in processing between two handlers (page.once and page.on). So I fixed this problem by properly awaiting response and disabling interception.

@mkalygin mkalygin changed the title Fix stylesheets/images rendering with puppeteer v10.2.0 (#121) Fix stylesheets/images rendering with puppeteer v10.2.0 #121 Aug 19, 2021
@mkalygin mkalygin changed the title Fix stylesheets/images rendering with puppeteer v10.2.0 #121 Fix #121: stylesheets/images rendering with puppeteer v10.2.0 Aug 19, 2021
@abrom
Copy link
Contributor

abrom commented Aug 20, 2021

Good find @mkalygin 👍

Although I did see that Puppeteer will occasionally error out using this solution with:

Error: Request Interception is not enabled!

What did appear to work ok was:

      await page.setRequestInterception(true);
      let htmlIntercepted = false;
      page.on('request', request => {
        // We only want to intercept the first request - ie our HTML
        if (htmlIntercepted)
          request.continue();
        else {
          htmlIntercepted = true
          request.respond({ body: urlOrHtml === '' ? ' ' : urlOrHtml });
        }
      });

Thoughts?

@mkalygin
Copy link
Contributor Author

mkalygin commented Aug 20, 2021

@abrom I'm wondering how is it even possible, given that I use two await calls and they're guaranteed to be synchronous.

Are you saying that await request.respond isn't guaranteed to be fully processed?

Is there any way to repro it? Or are you referring to some previous observations of that issue?

Overall I'm fine with doing what you suggest. I just didn't see a reason to intercept subsequent requests with continue.

@abrom
Copy link
Contributor

abrom commented Aug 20, 2021

Good question! But I don't have an answer. I'm thinking it's a timing thing where the browser is going ahead and starting the next request BEFORE the request interception has been disabled. Maybe the error message is just a bit confusing?

In any case, easy enough to test it:

npm install [email protected]
bundle exec rspec spec/grover/processor_spec.rb

@mkalygin
Copy link
Contributor Author

mkalygin commented Aug 21, 2021

@abrom interesting, I can't reproduce the issue you mention on my local machine. The CI is all green too.

With your implementation the example code I provided in #121 doesn't work - it just hangs and quits execution by timeout.

@abrom
Copy link
Contributor

abrom commented Aug 21, 2021

I would note that the CI was only passing because it was set to test up to v10.1.0. I pushed an update in #123 to include v10.2.0 yesterday so if you rebase that should give a better idea of what the state of the issue is.

Something tells me we haven't got to the bottom of this if your fix crashes for me and mine hangs for you!

@abrom
Copy link
Contributor

abrom commented Aug 21, 2021

By the way, did you copy my entire snippet ? Note that it needs to be page.on instead of page.once (I expect that would cause the hanging issue you mentioned..)

@mkalygin
Copy link
Contributor Author

@abrom you're absolutely right, I didn't notice this change. :–) Updated the PR.

Copy link
Contributor

@abrom abrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @mkalygin thanks!

@abrom abrom merged commit 8d5291f into Studiosity:main Aug 21, 2021
@abrom
Copy link
Contributor

abrom commented Aug 21, 2021

FYI released in v1.0.3

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 this pull request may close these issues.

2 participants