Open MichealAaron opened 2 months ago
Completely random suggestion which may or may not work;
I think I saw in another thread somewhere that you have to make a new page via await browser.newPage()
for some reason, cant use (await browser.pages())[0]
Description:
I am using Puppeteer with the puppeteer-extra package and the puppeteer-extra-plugin-adblocker plugin in my Node.js project, which is deployed on Google Cloud Functions. I have a function takeScreenshotWithOptions that takes a Params object, including a block_ads parameter. However, I am experiencing inconsistent ad blocking behavior. When I set block_ads to true or false, the ad blocking behavior is inconsistent. Sometimes ads are blocked with both settings until I restart the server.
Reproduction Steps:
Expected Behavior:
Actual Behavior:
Environment:
Additional Information:
Sample Code:
index.ts
ff.http('TypescriptFunction', async (req:ff.Request, res:ff.Response) => { try { const result = await takeScreenshotWithOptions(req.body); res.status(200).send(JSON.stringify({ 'screenshotUrl': result })); } catch (error) { console.error(error); res.status(500).send('Errors taking screenshot'); } });
import { Storage as GoogleStorage } from "@google-cloud/storage"; import puppeteer from 'puppeteer-extra'; import Adblocker from 'puppeteer-extra-plugin-adblocker';
export async function takeScreenshotWithOptions(params: Params): Promise {
//For Adblocking if (params.block_ads) { puppeteer.use(Adblocker({ blockTrackers: true })); }
const browser = await puppeteer.launch({ args: ["--no-sandbox"], headless: false, targetFilter: (target) => target.type() !== "other", }); const page = (await browser.pages())[0];
}