This button gets generated when the ‘Onion-Location’ HTTP header is found. However, it seems that the ‘document’ file with the header needs to finish loading fully before this information is available. You can also see this in the ‘Network’ tab of the DevTools menu: click on the request with the ‘document’ initiator while a website is loading, and you’ll see that the ‘Headers’ tab is only filled in once it fully finished loading.
This leads to unfortunate behavior, especially when you’ve set Tor Browser to always prioritize .onion sites: it will wait for the initial request to finish loading completely, which could take, like, 20 seconds on a bad connection, and once the site has finally loaded, it’ll visit the onion service, which will again take about 20 seconds.
I’m not sure how HTTP requests work exactly, but I was wondering if it would be possible to redirect or show the button as soon as it receives the Onion-Location header in the stream of data. If the header is the first part of the data that arrives, then this could lead to significant speedups.