w3c/long-animation-frames

[LoAF] Use `sourceLine` and `sourceColumn` instead of `sourceCharPosition` for attribution

Opened this issue · 8 comments

Source maps use line and column in order to map generated code to the matching line and column in the original file. It would make it a lot easier to link from the code attribution in a LoAF to the original source code if the LoAF could include sourceLine and sourceColumn.

Otherwise if you have some thoughts about how to achieve this using the sourceCharPosition I would be very interested. Or even more information about what that position refers to e.g. do line breaks count as 1 char?

I agree that this would be a lot more convenient for developers to see line/column instead of char position. In an earlier prototype that is actually how it worked.

However-- Noam noticed that this was a perf regression, because it requires parsing the text (in order to find all the newline characters). This isn't something that happens typically and so it is expensive to do automatically.


I wonder if it could be possible to request this type of parsing explicitly, after the LoAF fires, only once we know there is a client that is interested?

Thanks for the reply!

For more context, I'm sending the LoAF to an observability tool for later use and I'm trying to link the sourceCharPosition to the matching development file.
Agreed that natively paying that cost for every LoAF is probably not great. A way to opt-in to it would be a good alternative.

I tried to replicate this in user space by using fetch and only-if-cached request in order to retrieve the source file content if it exists in the browser cache. I then compute the sourceLine and sourceColumn from the sourceCharPosition provided by the LoAF and it seems to work well.

However it would be even better with the opt-in API you're suggesting.

yes you're absolutely right! However I'm working on an observability tool and I want to collect LoAFs for our users and link to their source code automatically.

So my constraints are:

  • I don't have access to the minified file on the server side
  • I do have access to source maps because users have a way to send them to us through an API

This is why I did that way. However it's good enough for a POC but I'm probably gonna hit CORS issues. If the opt-in API you were suggesting existed, I could let our users opt-in to that computation and accept the performance hit as a trade off to being able to monitor LoAFs.

@mmocny Coming back to your idea about performing the parsing only once we know there is a client that is interested. What would be a good way to advocate for that and see if it could actually get included down the line?

I think you just did :P

@noamr for thoughts.

I think this is better done in a service-worker than in the browser... Put the service worker between the document and the server that gives you the script, and tee the response stream to some processor that returns an array of line breaks. It should be trivial to create a get_line_and_col(source_char_position, array_of_line_breaks) function based on a similar function in chromium code.

Hey @noamr, thank you so much for your reply! Alright, sounds like a good path forward I'm going to give it a shot.