Problem with ROMs whose size isn't a multiple of 1024 bytes
The compression algorithm in the JS function generateAndSaveUF2 doesn't support the ROM size that isn't a multiple of 1024 bytes.
This is the likely cause of the problem with N64 240p test suite ROM that I reported before whose size is 6421760 bytes = 6271.25 KiB.
The generateAndSaveUF2 calculates the number of chunks as num_chunks = Math.floor(rom.fileSize / chunk_size) where chunk_size = 1024 so it doesn't handle the last incomplete chunk in any way.
Another bug I found is using Uint16Array that produce native-endian byte stream. It's unlikely that someone will open the converter code on a big-endian machine but it's still a bug.
I'm translating your JS code to Go so such bugs easily reveal themselves.
Thanks for finding the root cause. If you have the time to create a PR, I’d be happy to merge a fix in the repo https://github.com/kbeckmann/PicoCart64/tree/gh-pages
I have a prototype but can't test it before evening. I'm not a JavaScript programmer so it may be not an optimal solution.