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

    James

    01/17/2021, 10:44 PM
    Do you have an example of what you're trying to do exactly? I don't have anything directly to throw you, but take a look at the
    text
    handler in my post at https://jross.me/using-cloudflare-workers-htmlrewriter-to-extend-ghost-pro/#cloudflare-workers, and how I do the
    lastInTextNode
    stuff to get the full text of the entire element before doing my replacements.
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 10:47 PM
    Copy code
    html
    <div>abc<p>middle</p>xyz</div>
    I can't figure out a way to see that
    abc
    and
    xyz
    are siblings.
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 10:49 PM
    element
    gets called whenever we go up into a node, but
    text.lastInTextNode
    isn't exclusively going down a node. In the example above,
    abc
    is also
    lastInTextNode
    .
  • j

    James

    01/17/2021, 10:56 PM
    Hmm yeah. Due to the streaming nature of HTMLRewriter, I don't think there's a way to really know that unfortunately. I can't think of a way at least. https://up.jross.me/8lxkfas9
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 10:59 PM
    Alright, thanks for looking 🙂
  • j

    James

    01/17/2021, 11:04 PM
    https://community.cloudflare.com/t/non-streaming-htmlrewriter-response/119941 may be of interest. Similar-ish use-case with wanting to scan an entire element before doing anything with it.
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:08 PM
    It's a bit above me, but I think that's only working because we know that a
    body
    exists and will definitely follow the
    head
    ?
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:09 PM
    If I'm just parsing arbitrary HTML (inside a body), then there's no guarantee on any of the elements.
  • j

    James

    01/17/2021, 11:09 PM
    Yeah. Doing it generically for an entire document would be crazy. This works because there's at least some constraints with what you're expecting and looking for.
  • j

    James

    01/17/2021, 11:10 PM
    If no one has another solution, I guess the best one would be just finding a JS dom library and doing it synchronously after the document has been fetched
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:11 PM
    Yup, I'm just setting up parse5 now instead.
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:12 PM
    Honestly, no biggie. I just got obsessed with trying to make it work with HTMLRewriter. At least I learnt a bit more about how that works lol
  • j

    James

    01/17/2021, 11:13 PM
    Yeah I dived down a similar rabbit hole in that blog post with text chunks and getting that working as expected. Really cool stuff, within some constraints
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:18 PM

    https://i.imgur.com/g24X9RI.pngâ–¾

  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:18 PM
    Urgh
  • e

    Electroid

    01/17/2021, 11:20 PM
    Just to recap: you want to extract text from certain elements? But
    lastInTextNode
    also shows up before
    <p>
    so it makes it hard to get the whole text?
  • g

    Greg Brimble | Cloudflare Pages

    01/17/2021, 11:24 PM
    Yes. So as far as I can tell, it's impossible to differentiate between:
    Copy code
    html
    <div>abc</div><div>xyz</div>
    and
    Copy code
    html
    <div>abc<div>xyz</div></div>
    with HTMLRewriter, because they all come out as
    Copy code
    element: div
    text: abc (lastInTextNode)
    element: div
    text: xyz (lastInTextNode)
    once you combine any text chunks (as you're supposed to)
  • x

    Xenthys

    01/18/2021, 12:00 AM
    Hello, would anyone have recommendations about storing time series from Workers please? There's some data I'd like to save about every execution (aka. click) that'd allow me to do some stats and graphs. I've been unable to find much information, I don't believe Workers KV is powerful enough and it can also become pricy depending on how many clicks there are of course. I ignore if Workers DO would be a good fit either, though at the same time I might be missing something like "it's already included somewhere" and you only need to point Grafana there? Thanks in advance to anyone who has any idea, and whoever reads this… have a nice day! :)
  • a

    advaith

    01/18/2021, 12:02 AM
    oh hey xenthys
  • x

    Xenthys

    01/18/2021, 12:04 AM
    oh hey advaith, it's been a while, I've been seeing you contribute a lot to the datamining repo
  • j

    joe

    01/18/2021, 12:07 AM
    I haven't seen many people attempting time series
  • x

    Xenthys

    01/18/2021, 12:08 AM
    I would've thought time series are used everywhere, what are people doing otherwise :c
  • j

    joe

    01/18/2021, 12:11 AM
    Copy code
    +------------+
                           |            |
                           | Aggregator |
                           |            |
                           +-----+------+
                                 ^
                                 |
    +--------------+       +-----+------+       +--------------+
    |              |       |            |       |              |
    |    Client    +------>+   Worker   +------>+    Origin    |
    |              |       |            |       |              |
    +--------------+       +------------+       +--------------+
  • j

    joe

    01/18/2021, 12:11 AM
    something like that
  • j

    joe

    01/18/2021, 12:11 AM
    I'd assume would work
  • j

    joe

    01/18/2021, 12:12 AM
    but you are still reliant on an external aggregator of some sort to store & query that
  • j

    joe

    01/18/2021, 12:12 AM
    you are constrained by CPU time, which means anything intensive isn't going to be that easy (yet, #773219397422284820 will make it easier)
  • x

    Xenthys

    01/18/2021, 12:13 AM
    CPU time shouldn't be an issue to send some stats over the wire, it's not active computing
  • j

    joe

    01/18/2021, 12:13 AM
    yeah
  • x

    Xenthys

    01/18/2021, 12:14 AM
    and yeah it'd work, but aggregate with what and where remains the question, if I'm gonna depend on an external database hosted on a few machines that's gonna make Workers lose a part of their advantage of being an edge computing service
1...585960...2509Latest