It depends very much on the client side code as to whether this is possible. For a single page app, where only standard framework code is loaded from the server directly, then client side calls are used to pull any other required data, it's trivial - just hook into the client side calls, and ensure they're parsed correctly before being used on the page.
However, in a lot of older applications, the server provides the data directly, even if it is then shifted into place with client side code. In this case, any client side encoding would only trigger after the content has been put on the page, and, probably, executed.
Example of SPA (pseudocode):
clientContent = server.load(serverContent);
document.body = clientContent; // raw content only included after encoding
Example of server rendered:
serverContent // raw content executes here
In terms of methods of encoding, it depends on the context of the vulnerable data - for HTML contexts, look at things like https://stackoverflow.com/a/7124052/6039613 but note that you will need different characters escaping if the XSS vulnerabilities are within script blocks, for example.