
Show HN: Disabling View Source in Firefox and Edge - JeremyBanks
https://no-source.github.io/
======
core-questions
For the lazy, here's the magic:

    
    
      <script>
        document.currentScript.remove();
        setTimeout(function() {
          // no rights reserved (BSD0) by Jeremy Banks <_@jeremy.ca>
    
          const html = document.documentElement.outerHTML;
    
          document.open('text/plain');
          document.write('view source disabled');
          document.close();
    
          document.documentElement.innerHTML = html;
        });
      </script>

------
clouddrover
When I view source in Firefox I get the URL "view-
source:wyciwyg://0/[https://no-source.github.io/"](https://no-
source.github.io/") which gives me the "view source disabled" message.

But if I then manually edit that in the location bar to "view-
source:[https://no-source.github.io/"](https://no-source.github.io/") I can
view the source as expected.

------
inceptionnames
Neat. How do people even discover a hack like this?

~~~
JeremyBanks
In this case, I was trying to use `document.open()` to replace the document
with some text for debugging, and I noticed some strange side effects. :) The
starting point was here: [https://stackoverflow.com/questions/39233344/does-
javascript...](https://stackoverflow.com/questions/39233344/does-javascripts-
document-open-support-the-mime-type-parameter)

------
clouddrover
Also doesn't work in Safari 11.0.3.

