Concept is, that service worker will verify any fetched file with signing key and prevent malicious updates (from hacked server, etc.). This is working great till it comes to actual service worker file.
Bad actor can just change SW file, which is executed at browser's level and you cannot intercept it in any way (or I could not find it). Although not everything is accessible from SW context (like window), this is pretty big hole in my attempt.
Only close option I found is using server to serve service worker files on temporary dynamic paths, which are initiated from client and are only for single use.
Path would be forgotten after initial download, so anytime client app tries to fetch new service worker, it would result in error. This is obviously problematic, because it might not work for every browser and you can't control how such errors would be handled in the future and SW might be just invalidated.
Some secure cached wrapper (disconnected via domain config after it is loaded) around iframe could work better, but SW does not intercept fetch requests, so nothing here.
Is it worth investing time into to provide at least some level of awareness (like alerts for users)? I have feeling that investing time in such hacky solutions is not time well spent.