Currently the reader mode assets (aboutReader.html and aboutReader.css) are included inline in ReaderMode.js as a base64 encoded string. This works fine and fast but it is not ideal because it is hard to work with those files. This was done because there is no easy way to load an application resource from the WKWebView: because of the content process separation and sandboxing that happens it is not possible use file: URLs. As an alternative I am going to suggest that the Swift side loads the template instead, does the substitutions in it and then loads it in the WKWebView. This means that the template setup code in ReaderMode.js will move to the ReaderMode.swift so that the native code will then prepare the content and passes it to the WKWebView via loadHTMLString(). The original CSS in aboutReader.css has all the content set to invisible. This was probably done to minimize flickering when the readerized content is loaded in it and the user defined settings (font face/size/theme) are applied. We can keep this but it means that the ReaderMode.swift needs a page loaded callback so that we can apply the user style and make the document visible. Need to experiment because ideally we go from original page to readerized page really quickly without seeing any noticable delay or flickering or changes in content.
The last bit of comment #1 should be in a separate bug. It can be done as a followup bug to this one.
Created attachment 8553203 [details] [review] Pull Request