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

chore(adblock): setup priority #321

Merged
merged 5 commits into from Oct 19, 2021
Merged

chore(adblock): setup priority #321

merged 5 commits into from Oct 19, 2021

Conversation

Kikobeats
Copy link
Member

@Kikobeats Kikobeats commented Oct 19, 2021

According to Puppeteer API docs:

If you do intentionally want to use a different priority, higher priorities win over lower priorities. Negative priorities are allowed. For example, continue({}, 4) would win over continue({}, -2).

so:

  • abortTypes takes 2 priority (highest priority).
  • adblock takes priority 1.
  • any other user-defined interception will take 0 priority by default, not collisioning with the library priorities.

Related:

@Kikobeats
Copy link
Member Author

Kikobeats commented Oct 19, 2021

Hmm strange this is strange

DEBUG=browserless* browserless html https://meneame.net --abort-types stylesheet --abort-types fonts --abort-types image --abort-types media

CleanShot 2021-10-19 at 13 22 35@2x

Based on the priority configuration, block should be after before the continue 🤔

Maybe it is just a logging issue since logging order is not guaranteed?

engine.on('request-blocked', ({ url }) => debugAdblock('block', url))

const resourceType = req.resourceType()
if (!abortTypes.includes(resourceType)) {
debug('continue', { url: req.url(), resourceType })
return req.continue(req.continueRequestOverrides(), 2)
Copy link

Choose a reason for hiding this comment

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

Sorry if I am meddling where I don't belong 😅 This .continue({}, 2) will cause the request to continue even if adBlocker calls .abort('..',1). I think your intent might be to defer to other handlers by using .continue({}, 0) if abortTypes has no opinion about it?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, that was the intention; should I call isInterceptResolutionHandled to be sure about that?

Choose a reason for hiding this comment

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

When #7796 is approved (I hope soon), that method will be available and should definitely be used.

Also see the PR for a discussion on when to use a custom priority to continue a request.

Again sorry to jump in, I just found this issue and thought it was interesting because I’m learning a lot by how people are implementing support for cooperative mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

no problem 🙂 I did my best implementing the API and since there is not too examples out there probably the code can be rewritten in a better way

Choose a reason for hiding this comment

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

If you decide to change anything, I suggest using .continue({...},0) for this case :)

@benallfree
Copy link

puppeteer/puppeteer#7796 has been accepted by the Puppeteer team 👍

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.

None yet

2 participants