Skip to content

Playwright ad blocker

Lena edited this page Jun 15, 2021 · 2 revisions

To block certain reources like popups:

const miniAdsDb= [
   'https://pagetoblock.com',
   'https://anotherpagetoblock.com'
]

await page.route('**/*',(route) => {
 const url = route.request().url();
if(miniAdsDb.some(d => url.startWith(d))) {
   route.abort();
}
else {
   route.continue();
}
});

Clone this wiki locally