stagehand icon indicating copy to clipboard operation
stagehand copied to clipboard

Stagehand with Ghostery, block Ads.

Open AdamGoodApp opened this issue 11 months ago • 0 comments

I can't seem to block any Ads using Stagehand and Ghostery playwright. I'm able to block Ads successfully using puppeteer with the same setup.

import { Page, BrowserContext, Stagehand } from "@browserbasehq/stagehand";
import { PlaywrightBlocker } from '@ghostery/adblocker-playwright';
import fetch from 'cross-fetch';
import dotenv from "dotenv";

dotenv.config();

export async function main({
  page,
  context,
  stagehand,
}: {
  page: Page; // Playwright Page with act, extract, and observe methods
  context: BrowserContext; // Playwright BrowserContext
  stagehand: Stagehand; // Stagehand instance
}) {

  const blocker = await PlaywrightBlocker.fromLists(fetch, [
    'https://easylist.to/easylist/easylist.txt',
    'https://raw.githubusercontent.com/uBlockOrigin/uAssets/refs/heads/master/filters/annoyances-others.txt',
    'https://raw.githubusercontent.com/uBlockOrigin/uAssets/refs/heads/master/filters/filters-2025.txt',
  ]);

  await blocker.enableBlockingInPage(page);
  await page.goto("https://www.cineby.app/movie/1064213");

}

AdamGoodApp avatar Feb 28 '25 12:02 AdamGoodApp