Increase share limit #58
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The current share feature has a hard limit of 2047 characters after gzip and url-encoding. This is due to browser limitations on how long a query param value can be.
Also it doesn't support sharing code with emojis.
Solution
It turns out that the fragment (#) part of the url is more suited to this purpose than the query param. It actually isn't sent to the server and instead is only parsed on the client. Because of that, browsers don't restrict the size of the fragment portion of the URL to the same extent that they do with query params. Practically, chrome does limit the size of the URL to 2MB so that's what I set as the limit.
Gemini Deep Research actually discovered this for me, although I did write all of the code by hand: https://g.co/gemini/share/9712e01a0afe
Supporting unicode was as simple as processing each character in the array buffer one by one instead of all at once. This is probably slower but sharing doesn't have to be realtime
Example:
I went ahead and copied an entire copy of Frankenstein. Attempting to run the "code" will crash the interpreter but the share function works just fine!
Screen.Recording.2025-09-18.at.8.21.46.PM.mov.mp4