How to inject script into a page using bookmarklet if the Content Security Policy is enabled on the server?

后端 未结 3 484
闹比i
闹比i 2021-01-06 19:25

I have a bookmarklet which uses jQuery and parses some elements on the page. To use jQuery, i am creating a script tag(with src as the jQuery URL) dynamically and appending

相关标签:
3条回答
  • 2021-01-06 19:58

    Take

    javascript:(function(){
    
    })();
    

    And fill the empty line with the jQuery source code, for example the contents of https://code.jquery.com/jquery-3.4.1.min.js . Afterward set it as URL of your bookmark(let).

    0 讨论(0)
  • 2021-01-06 20:00

    The spec says (at least I think it still does) that CSP should not prevent bookmarklets, but no browser has implemented this. Your only option is to disable CSP in the browser or use an extension.

    0 讨论(0)
  • 2021-01-06 20:12

    Self-contained bookmarklets are another possibility. Here's jQuery 3.3.1.

    0 讨论(0)
提交回复
热议问题