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

Ad blocking #7

Closed
sindresorhus opened this issue Feb 12, 2019 · 3 comments · Fixed by #98
Closed

Ad blocking #7

sindresorhus opened this issue Feb 12, 2019 · 3 comments · Fixed by #98
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@sindresorhus
Copy link
Owner

Would be awesome to have some kind of ad blocking to reduce noise in screenshots.

The best solution would be to use an existing ad blocker Chrome extension, like uBlock Origin, but it seems it's only possible to load extension when not in headless mode ({headless: false}), so the Chrome window would show for a few seconds.

https://gist.github.com/sindresorhus/bca2f7d0c8b31205fa3c9f328d548c70
https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#working-with-chrome-extensions

We could potentially make it opt-in and let the user know the downside.

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Feb 12, 2019
@Kikobeats
Copy link
Contributor

Kikobeats commented Apr 4, 2019

I recently added adblock at browserless.

You could use @browserless/goto or use adblocker directly.

It also addresses #11

In fact, the default rules lists are easylist + uBlock + cookies banners 🙂

Just need some urls to target to see if it's working as expected

@brandon93s
Copy link
Contributor

This could be implemented with request interceptors:

const blocklist = [...];

page.on('request', (request) => {
    // psuedo-code, regex or domain checks likely required
    if (blocklist.includes(request.url())) {
        request.abort();
	}

    request.continue();
  });

With this implementation, blocklist could be provided by the user -- either a list directly or a filepath.

@stvhanna
Copy link

@brandon93s How were you able to integrate this with capture-website? I tried the below but the page.on('request') is not called. @sindresorhus is this expected or possibly a bug?

      beforeScreenshot: async (page, browser) => {
        page.on('request', (request) => {
          console.log('request.url()', request.url());
          if (blocklist.includes(request.url())) {
            request.abort();
          }
          request.continue();
        });
      },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants