26
7
Today I have noticed that I am unable to run bookmarklets on https://github.com/ due to Content Security Policy (CSP) restrictions. Is there a way to disable CSP in Firefox for just bookmarklets, and not everything else?
I noticed the security.csp.enable
option in about:config
, but this would disable CSP
completely. The following message is logged to console when activating a bookmarklet:
Timestamp: 04/22/2013 02:39:05 PM
Warning: CSP WARN: Directive inline script base restriction violated
Source File: https://github.com/
Line: 0
Source Code:
javascript:...
I don't understand... creating a button on the page to load the code when clicked doesn't work, it still throws a CSP exception – Michael – 2015-03-21T17:59:05.553
1The on-demand feature is very important. I have bookmarklets that insert a quick eval-textarea with some features that does not fill the a large part of the page, one for creating a QR code for the current page and some other smaller parts. Those are not GH-specific. The power of bookmarklets is that they can be created and removed very easily. GreaseMonkey was already installed, but that is not going to solve the CSP issue. Thanks for the suggestions, perhaps a solution for Firebug will also be of benefit for bookmarklets. – Lekensteyn – 2013-04-26T09:37:51.263
4
Unfortunately the Firebug fix will only fix Firebug itself. From Github blog entry on CSP: As made clear by the CSP spec, browser bookmarklets shouldn't be affected by CSP. (..) But, none of the browsers get this correct. All cause CSP violations and prevent the bookmarklet from functioning. Perhaps you should investigate the case more thoroughly and report an issue on Bugzilla.
– jakub.g – 2013-04-26T12:27:04.5732
BTW you can use GM_registerMenuCommand to make a function invocation on-demand. Don't forget
– jakub.g – 2013-04-30T13:07:21.503@grant GM_registerMenuCommand
. It adds entry to Greasemonkey menu, accesible under(GM logo) > User Script Command...
. That way you can easily convert your bookmarklets into userscripts.