https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • d

    dave

    02/22/2023, 7:16 PM
    if I'm adding an unsub header at the top, is this the sane way to do it?
    Copy code
    typescript
                class  ElementHandler {
                    element(element: Element) {
                        console.log(`Incoming element: ${element.tagName}`);
    
                        element.prepend("<p>Unsubscribe</p>", {html: true});
                    }
                }
                  
    
                const rewriter = new HTMLRewriter().on('body', new ElementHandler())
                const amp_content_value_rewritten = await rewriter.transform(new Response(amp_content.value.toString()));
    
                console.debug(await amp_content_value_rewritten.text());
  • p

    p0

    02/22/2023, 7:24 PM
    Does the workers unbound pricing model only charge for CPU seconds, or would it also charge for the time executing something like an HTTP Request?
  • u

    0xf

    02/22/2023, 7:27 PM
    I deployed a worker, whyo do simple select query on a d1 db, and the response time is ~200ms, I thought it would be ~40ms and not x4 times the time 😄
  • s

    Skye

    02/22/2023, 7:27 PM
    It's an alpha product - response times aren't going to be the best just yet
  • u

    0xf

    02/22/2023, 7:28 PM
    is d1 replicated in different regions?
  • s

    Skye

    02/22/2023, 7:29 PM
    Not yet
  • u

    0xf

    02/22/2023, 7:29 PM
    Cool, when will it be ready for production?
  • s

    Skye

    02/22/2023, 7:30 PM
    No timeline
  • u

    0xf

    02/22/2023, 7:32 PM
    btw why i getting forbidden as response time to time 😭
  • k

    kian

    02/22/2023, 7:32 PM
    Seems fine to me
  • p

    p0

    02/22/2023, 7:32 PM
    does anyone know if workers unbound times you for http requests?
  • k

    kian

    02/22/2023, 7:32 PM
    Time spent waiting for a response? Yes
  • p

    p0

    02/22/2023, 7:32 PM
    But bundled doesn't?
  • k

    kian

    02/22/2023, 7:33 PM
    Nope
  • p

    p0

    02/22/2023, 7:33 PM
    I see
  • k

    kian

    02/22/2023, 7:33 PM
    Unbound bills you on duration (wall clock time) whereas Bundled's limit is just 50ms of CPU time
  • p

    p0

    02/22/2023, 7:33 PM
    gotcha
  • d

    dave

    02/22/2023, 8:00 PM
    Copy code
    [ERROR] Uncaught (in promise) TypeError: Parser error: Unsupported pseudo-class or pseudo-element in selector.
    
      const rewriter = new HTMLRewriter().on('div:unsub', new ElementHandler())
  • d

    dave

    02/22/2023, 8:00 PM
    How is this invalid...?
  • d

    dave

    02/22/2023, 8:01 PM
    I'm copying it straight out of the docs
  • j

    James

    02/22/2023, 8:02 PM
    From where? What's
    unsub
    ? 👀
  • d

    dave

    02/22/2023, 8:02 PM
    https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/#async-handlers
  • j

    James

    02/22/2023, 8:03 PM
    Errr, I dunno what that's trying to do, that's weird. You probably want
    div.unsub
    if you have a div with class
    unsub
  • d

    dave

    02/22/2023, 8:03 PM
    oh, I think it's
    div#unsub
    😄
  • j

    James

    02/22/2023, 8:04 PM
    or
    #unsub
    if you have a div with ID
    unsub
    , yeah
  • j

    James

    02/22/2023, 8:04 PM
    It uses pretty standard
    querySelector
    notation
  • j

    James

    02/22/2023, 8:07 PM
    fixed https://github.com/cloudflare/cloudflare-docs/pull/7744
  • d

    dave

    02/22/2023, 8:07 PM
    thanks!
  • d

    dave

    02/22/2023, 8:07 PM
    is there a built in way to verify that a handler was run at least once?
  • j

    James

    02/22/2023, 8:09 PM
    Not to my knowledge
1...229923002301...2509Latest