简体   繁体   中英

Prevent single inline script from executing

I am writing own .js script for specific site but there is one terrible inline script that doesn't allow me to use localStorage and sessionStorage . It's located in top of <body> and here it is:

<script type="text/javascript">
window.localStorage.clear();
window.sessionStorage.clear();
</script>

As you can see, this awful script clears both storages every time page is reloaded. Is there any way to get rid of this script using own content script or chrome extension?

I have tried to use content script with "run_at": "document_start" as own chrome extension but it fails with `Cannot read property 'removeChild' of null'. Here is my script's code:

var script = document.getElementsByTagName('script')[0];
script.removeChild(script);

If you can get a script tag to run BEFORE that script then simply redefine those functions to do nothing.

window.localStorage.clear = function() {};
window.sessionStorage.clear = function() {};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM