The best isolation is inside a Service Worker, where the script is served with Content-Security-Policy: sandbox header.[1]
[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/...
[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/...