How to hide an element or section using cloudflare worker

Hi,
I came to know that, we can hide any element/section on a page using cloudflare workers?
Is it right?

Can you help me out, how can i do this??

looking forward to help…
Thanks.

https://developers.cloudflare.com/workers/runtime-apis/html-rewriter

Some example:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

class ElementRemover {
  element(element) {
	  element.remove()
  }
}

const rewriter = new HTMLRewriter()
	.on("#element-to-remove", new ElementRemover()) #select the element to remove, can be ID, class, tag name

async function handleRequest(request) {
  const res = await fetch(request)
  return rewriter.transform(res)
}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.