Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Setting attribute using HTMLRewriter on Cloudflare worker

I am trying to set the value attribute of my #email field via a Cloudflare worker.

I define my email as test@test.com but how can I send this into ElementHandler ?

At the moment I am able to set the value attribute to be XXXX and this works successfully.

async function handleRequest(request) {

  const newResponse = new Response(response.body, response)

  const email = 'test@test.com';

  return new HTMLRewriter()
     .on("#email", new ElementHandler())
     .transform(newResponse)

}

class ElementHandler {
   element(e) {
     e.setAttribute('value', 'XXXX')
   }
}

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request))
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can give your ElementHandler class a constructor that accepts parameters which you store in properties of the object:

class ElementHandler {
  constructor(value) {
    this.value = value;
  }

  element(e) {
    e.setAttribute('value', this.value)
  }
}

Then construct it like:

new ElementHandler(email)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!