简体   繁体   English

阻止执行单个内联脚本

[英]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 . 我正在为特定站点编写自己的.js脚本,但是有一个可怕的内联脚本不允许我使用localStoragesessionStorage It's located in top of <body> and here it is: 它位于<body>顶部,在这里:

<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? 有什么办法可以使用自己的内容脚本或chrome扩展名摆脱此脚本?

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'. 我尝试使用带有"run_at": "document_start"内容脚本作为自己的chrome扩展名,但是由于无法读取'null的'removeChild'属性而失败。 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() {};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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