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

[Bug] BlockResourcesPlugin does not work alongside with AdblockerPlugin. #585

Closed
Aex12 opened this issue Oct 27, 2021 · 3 comments
Closed
Labels
issue: bug report A bug has been reported needs triage

Comments

@Aex12
Copy link

Aex12 commented Oct 27, 2021

Describe the bug
Whenever you try to enable both plugins alongside, BlockResourcesPlugin stops working. I've set up to block images, stylesheets and media types, and it works fine when AdblockerPlugin is not enabled, but if you enable both, BlockResourcesPlugin stop blocking the provided resources.

Code Snippet

const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const BlockResourcesPlugin = require('puppeteer-extra-plugin-block-resources');
const AdblockerPlugin = require('puppeteer-extra-plugin-adblocker');

puppeteer.use(StealthPlugin());
puppeteer.use(AdblockerPlugin());
puppeteer.use(BlockResourcesPlugin({ 
	blockedTypes: new Set(['image', 'stylesheet', 'media']),
}));

(async () => {
  const browser = await puppeteer.launch({ headless: true });
  const page = await browser.newPage();
  await page.goto('https://www.google.com/');
  await page.screenshot({ path: 'example.png' });

  await browser.close();
})()

Steps to reproduce
After running the above code snippet, check the example.png image created to see that styles and images are in fact loaded. If we remove AdblockerPlugin from the equation, the screenshot is as expected, without styles nor images.

Versions

System:
OS: Linux 5.14 Fedora 34 (Thirty Four) 34 (Thirty Four)
CPU: (16) x64 AMD Ryzen 7 3800X 8-Core Processor
Memory: 1.95 GB / 15.54 GB
Container: Yes
Shell: 5.1.0 - /bin/bash
Binaries:
Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
Yarn: 1.22.15 - ~/.nvm/versions/node/v14.17.4/bin/yarn
npm: 6.14.14 - ~/.nvm/versions/node/v14.17.4/bin/npm
npmPackages:
puppeteer: ^10.4.0 => 10.4.0
puppeteer-extra: ^3.2.3 => 3.2.3
puppeteer-extra-plugin-adblocker: ^2.12.0 => 2.12.0
puppeteer-extra-plugin-block-resources: ^2.3.0 => 2.3.0
puppeteer-extra-plugin-stealth: ^2.9.0 => 2.9.0

@Aex12 Aex12 added issue: bug report A bug has been reported needs triage labels Oct 27, 2021
@MeikyuuTrader
Copy link

MeikyuuTrader commented May 8, 2022

I'm getting a request already handled error when enabling puppeteer page proxy and both adblocker plugin and block resources. But everything works fine if I disabled the adblocker.

/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26
        throw new Error(message);
              ^

Error: Request is already handled!
    at assert (/node_modules/puppeteer/lib/cjs/puppeteer/common/assert.js:26:15)
    at HTTPRequest.abort (/node_modules/puppeteer/lib/cjs/puppeteer/common/HTTPRequest.js:453:32)
    at requestHandler (/node_modules/puppeteer-page-proxy/src/core/proxy.js:41:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async $ppp_request_listener (/node_modules/puppeteer-page-proxy/src/core/proxy.js:82:9)
    at async HTTPRequest.finalizeInterceptions (/node_modules/puppeteer/lib/cjs/puppeteer/common/HTTPRequest.js:151:9)

Versions

"puppeteer": "^13.7.0",
"puppeteer-extra": "^3.2.3",
"puppeteer-extra-plugin-adblocker": "^2.12.0",
"puppeteer-extra-plugin-block-resources": "^2.3.0",
"puppeteer-extra-plugin-stealth": "^2.9.0",
"puppeteer-page-proxy": "^1.2.8"

@MeikyuuTrader
Copy link

MeikyuuTrader commented May 8, 2022

Not sure if this would work, but mentioned a potential solution SnowLew #5334.

However, since this removes existing page listeners, does that mean the adblocker plugin no longer works? Also, the above code MUST be called before page.goto(URL), otherwise it wouldn't block resources. Then it kinda seems like the adblocker part would no longer work, since that request listener was removed and a new one added.

Perhaps, a solution would be to implement the ad blocker AND resource blocker in the same request listener, thus no conflicts.

@berstend
Copy link
Owner

berstend commented Jul 8, 2022

This is fixed in #592 :)

@berstend berstend closed this as completed Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug report A bug has been reported needs triage
Projects
None yet
Development

No branches or pull requests

3 participants