14:47
<eeeps>
zcorpan annevk: window.innerWidth is an integer, but when DPR != 1, the actual bounds may have a fractional part. This feels weird to me, but has it ever come up or been problematic?
17:23
<Domenic>
devsnek: I would use DOM access instead of regex, but that seems about right in general. Or use the URL, but I'm assuming that's not on the table for you.
17:23
<devsnek>
Domenic: you mean parse html -> insert thing -> stringify?
17:24
<Domenic>
devsnek: I mean if you're running JS then just do `document.head.firstChild` or something instead of regexing `document.outerHTML`.
17:25
<devsnek>
well it has to be inserted
17:25
<devsnek>
the metadata i mean
17:25
<Domenic>
Oh I thought you were talking about regexing it out, not inserting it
17:25
<Domenic>
On the insertion I'd just prefix it
17:25
<Domenic>
I think that works...
17:25
<devsnek>
sounds quirky
17:26
<Domenic>
http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=8325
17:27
<devsnek>
oh
17:27
<devsnek>
that's really cool
17:27
<devsnek>
thx
20:42
<Krinkle>
devsnek: assuming you can control the server, you could also add an attribute or export a native JS value.e.g. <html data-foo=""> a nd then document.documentElement.dataset.foo (or docEl.getAttribute('data-foo')), or e.g. <html><script>X_MYDATA={ "some": "data here"}</script> and then access the the X_MYDATA variable in JS anytime. the server could use a JSON encoder to export the data safely.
20:43
<devsnek>
Krinkle: can control the server, the main issue would be that parsing and stringifying the html would not be great for latency
20:43
<Krinkle>
devsnek: where would htere be parsing and stringifying of html?
20:44
<devsnek>
how do you insert tags in the document without knowing where to insert them
20:44
<Krinkle>
you want to use JS to read it, not to insert it, right?
20:44
<devsnek>
both
20:44
<Krinkle>
the server can presumably just print it as part of its HTML buffer.
20:45
<Krinkle>
how is the HTML page built?
20:45
<devsnek>
imagine an express middleware
20:45
<devsnek>
idk how the html page is built, i just have a string of html
20:45
<Krinkle>
hm.. that seems fragile to me, is there not any kind of contract you an establish with the surrounding server? I mean, what's to say there isn't another thing trying a similar thing then?
20:46
<devsnek>
there isn't
20:46
<Krinkle>
so you know nothing about the server, but you do know you're the only one trying to export data?
20:46
<Krinkle>
I suppose it might be a static html proxy/server?
20:47
<devsnek>
i mean there's no way to say someone else isn't also trying to do a similar thing at the same time
20:48
<devsnek>
https://www.moesif.com/blog/engineering/middleware/What-Is-HTTP-Middleware/
20:48
<Krinkle>
anyhow, if you can assume at least that it's a well-formed HTML document (doctype +html + head+ body, note that all these are strictly speaking optional) , then a limited string search for the first <head> seems reasonable enough to string-replace and add your <script> there. That way it is not prone to breaking if someone else does the same thing so long as you use different variable names.
20:50
<Krinkle>
e.g. <head><script>OTHERLIB=2</script><script>MYLIBDATA=1</script> will still do what you need, not so much if there's two HTML comments, that becomes harder to deal with.
20:50
<Krinkle>
of course if the original page does have something positional in its <head> then this would break what document.head.firstChild points to.
20:51
<Krinkle>
how does the consumer of the data arrive on the page, perhaps you can ship the data through there.
20:52
<Krinkle>
e.g. if you know the consumer is loaded late, you could choose to append the script at the end instead, the only reason to insert it early would be if you don't know when the consumer might look for it.
20:53
<Krinkle>
Use of lastChild/:last-child is relatively rare so would be less risky in terms of not breaking compat with the original documen