As long as server can serve any JS to any client, you can’t protect the data from the server.
https://en.m.wikipedia.org/wiki/Same-origin_policy
Browser extensions can bypass that though, which can expose you to malicious third parties.
tl;dr: In most cases browser JS crypto offers no advantages if you're trying to protect yourself from a rogue/compromised backend (eg. do e2e crypto on keys stored within localstorage before passing that over to the backend). That is because if the backend is compromised it can likely serve backdoored JS code that will leak secrets.
This is not always true (eg. if you have multiple tiers of server backends within separate security domains), but almost always true for typical web monoliths.