Seems to me like trying to rewrite websites like this is really brittle and high friction. The "final form" of something like this is just an agent that extracts content/functionality from a site and surfaces it in a user's custom interface, might be worth just jumping in a little closer to that.