Closed billy4479 closed 1 year ago
I was going to report this issue with Snapchat web version. We have to change the user agent but it fails with this addon unlike another addon that I have been using: https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher-revived.
I even created a polyfill with Greasemonkey using this JavaScript code to try if it works:
window.eval("window.navigator.userAgentData = new function (){this.platform = 'Linux';};");
However the addon otherwrites navigator.userAgentData
unlike the other addon.
In fact I noticed that by default navigator.userAgentData
is undefined when using the other addon but it still works.
However I had to update the version of the user agent on the other addon, I used this value from Linux Chromium:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
I did some further investigation and Snapchat web does provide some kind of polyfill for userAgentData
but only if it's undefined
before. If it is not undefined it assumes it is compliant to the specification, which, in this case, it is not, causing the website to crash. The issue with Snapchat is kind of unrelated to this extension: the website relies on NavigatorUAData
which is an experimental API that Firefox does not support (yet).
The options here would be to write some kind of polyfill for the full interface or just ignore it and let the website provide its own, the current solution is something in between that breaks websites that assume that it's present.
Another example of this is Whatsapp web, that, at the time of writing, if loaded from Firefox with the UA set to Chrome, throws an error complaining that getHighEntropyValues
does not exist.
This problem is also related to the "polyfill" provided by this extension being incomplete, because Whatsapp web works natively fine on Firefox too.
@billy4479 Why not leave navigator.userAgentData
undefined like the other working addon I mentioned is doing? It works on Snapchat Web. Anyway navigator.userAgentData
is experimental technology and cannot be trusted in production like mentioned on https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgentData.
In fact the addon breaks production websites like Snapchat because it uses this experimental technology (even if it can also be seen as an issue with the website).
Update: do you have popular websites examples that break if navigator.userAgentData
is undefined? I never had this issue.
Adding an option to keep navigator.userAgentData
undefined could be useful in case there are other problems like this in the future.
Thanks for the fix :)
navigator.userAgentData
's interface defines also two member functions, namely NavigatorUAData.toJSON()
and NavigatorUAData.getHighEntropyValues()
. It would be desirable, if possible, to have those functions too as some websites (web.whatsapp.com for example) rely on those
Adding an option to keep navigator.userAgentData undefined could be useful
Done.
navigator.userAgentData's interface defines also two member functions...
The new implementation contains these two methods. Give it a try, and let me know how it works.
Thank you for the quick fix, it works like a charm! Thank you so much
The
navigator.userAgentData
object lacks theplatform
key. According to MDN and the spec, it should be a string containing the underlying operating system, for example "Windows", "Linux" or "Android".This "confuses" many websites that think can rely on
userAgentData
, because it's notundefined
, but because it's incomplete it causes problems when the website tries to accessuserAgentData.platform
. A website that shows this behavior (at the time writing) is web.snapchat.com.