How to use email obfuscation on a specific page when Worker is active?

My situation:

  • I disabled the ‘Email Address Obfuscation’ setting on my entire site (through the dashboard).
  • I handle every request to my website with a Cloudflare Worker.

The problem:

  • I made a Page Rule to enable ‘Email Address Obfuscation’ on a specific URL. That page rule does not nothing.
  • I used scrapeShield: true in my cf object in the Worker’s code. That does nothing.
  • (In both cases, I did empty the Cloudflare cache.)

My question:

  • How to enable email obfuscation on a specific URL when using workers?

Workers run before most of Cloudflare features.
You could use a encoded string in base-64.

On Worker
const email = btoa('mailto:[email protected]')

On Worker generated HTML you should have something like this.

<a href="javascript:window.location.href=atob('bWFpbHRvOnVzZXJAZXhhbXBsZS5jb20='">E-Mail</a>
1 Like

Thanks, I’m aware of those approaches and there are also 3rd-party JavaScript libraries that can obfuscate email addresses.

However, I think that Cloudflare’s solution has the potential to be ‘best in class’, and in theory they should be much better in detecting scraping bots than other solutions. :slight_smile:

That’s why I’d rather have Cloudflare’s feature working, instead of jumping immediately into a workaround.

From the documentation, it looks like Workers should be able to execute Cloudflare features, such as ScrapeShield. At least when it fetches content from your server.

If the output is entirely Worker-generated, maybe the process doesn’t go deep enough into Cloudflare to makes this stuff happen.