chrome extension remove script tags

前端 未结 2 1550
长情又很酷
长情又很酷 2021-02-10 10:29

i looked everywhere trying to find an answer to this question. i want my extension to either disable all javascript on the page BUT to allow the insertion of a cotent script th

2条回答
  •  遇见更好的自我
    2021-02-10 11:29

    Well, the only way to truly prevent scripts is with contentSettings. So you need to put your code somewhere else, in another domain, since contentSettings rules can be applied for specific URL's.

    Put you content script to run at document start.

    contentScript.js:

    window.stop();
    document.all[0].innerHTML = "\
    \
        \
            \
        \
    ";
    

    inject.html:

    
    
    
    
    
        
    
    
    

    Now your code is in a parent frame and in another domain, but it may cause some CORS issues which you can try found some workarounds later. Give a try, then tell me if there's something to fix.

提交回复
热议问题