Prevent all or some DOM content to be parsed, per website domain
To abort loading of a website, you can simply use the window.stop()
method.
When called, when the current script finish running, the parsing of the website stops completely.
For example:
<p>Before scripts</p>
<script>
document.write('<p>Before stop</p>')
console.log('Before stop')
window.stop()
document.write('<p>After stop</p>')
console.log('After stop')
</script>
<p>Between scripts</p>
<script>
console.log('Second script')
document.write('<p>Second script</p>')
</script>
<p>After scripts</p>
The above HTML displays:
Before scripts
Before stop
while you can see the following in the console:
Before stop
After stop
That shows that the <script>
calling .stop()
is fully evaluated, but changes made to DOM after .stop()
aren't displayed.
Alternatively, to erase the full DOM content, it might be better to redirect the browser, that solution works even after page load:
window.open('about:blank','_self')