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] Using adblocker and block-resources plugins together causes an error #611

Closed
byGits opened this issue Jan 21, 2022 · 2 comments
Closed
Labels
issue: bug report A bug has been reported needs triage

Comments

@byGits
Copy link

byGits commented Jan 21, 2022

Thank you very much for creating these plugins, they are awesome!

I just have an issue when using "adblocker" and "block-resources" plugins at the same time.

When I use them both I get this error: Request is already handled!

Removing either of the plugins causes the script to work again.

Code Example:

const puppeteer = require('puppeteer-extra');
const pluginProxy = require('puppeteer-extra-plugin-proxy');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha');
const AdblockerPlugin = require('puppeteer-extra-plugin-adblocker');
const blockResourcesPlugin = require('puppeteer-extra-plugin-block-resources');
const mysql = require('mysql');
const fs = require('fs-extra');

const configFile = require('./config');

puppeteer.use(AdblockerPlugin());
puppeteer.use(StealthPlugin());

puppeteer.use(require('puppeteer-extra-plugin-block-resources')({
    blockedTypes: new Set(['image', 'font'])
}));

let puppeteerArgs = [
    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--enable-features=NetworkService',
    '--ignore-certifcate-errors',
    '--ignore-certifcate-errors-spki-list',
    '--disable-dev-shm-usage',
];

let options = {
    headless: true,
    ignoreHTTPSErrors: true,
    userDataDir: './tmp',
    args: puppeteerArgs
}

// Remove data in /tmp directory
try {
    fs.unlink('./tmp/DevToolsActivePort');
    fs.removeSync('./tmp/Default');
} catch (e) {
    console.log('error: ' + e);
}

puppeteer.launch(options).then(async browser => {
    try {
        const page = await browser.newPage();

        await page.goto('https://example.com', { timeout: 10000 });
        
        await page.waitForSelector('button#id', { visible: true, timeout: 5000 });
        await page.click('button#id');
        
        // Wait
        await new Promise(r => setTimeout(r, 1500)).catch(() => { console.log('error'); process.exit(); });
        
        await page.solveRecaptchas();
        
        // Wait
        await new Promise(r => setTimeout(r, 1000)).catch(() => { console.log('error'); process.exit(); });
        
        var result = await page.$eval('span#spanid', element => element.innerHTML);

        console.log(result);

        // Clear cache & cookies
        const client = await page.target().createCDPSession();
        await client.send('Network.clearBrowserCookies');
        await client.send('Network.clearBrowserCache');

        await browser.close();

    } catch (e) {
        console.log('error: ' + e);
    } finally {
        await browser.close();
        process.exit();
    }
});
@byGits byGits added issue: bug report A bug has been reported needs triage labels Jan 21, 2022
@b5414
Copy link

b5414 commented Apr 27, 2022

same, with

puppeteer.use(stealth());
puppeteer.use(require('puppeteer-extra-plugin-adblocker')());

+-- puppeteer-extra-plugin-adblocker@2.12.0
+-- puppeteer-extra-plugin-stealth@2.9.0
+-- puppeteer-extra@3.2.3
+-- puppeteer-page-proxy@1.2.8
`-- puppeteer@13.0.1

@berstend
Copy link
Owner

Should be fixed through #592

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