I need to filter out certain characters when a user pastes from the clipboard. (I don't actually want to modify what's in the clipboard.) I already have this working in IE. Sigh...
tl;dr: capability.policy
items in user.js make it into prefs.js but aren't taking effect.
FYI, I can reasonably have all users install user.js. But none of us have admin access to our machines, so that's about all I can do regarding configuration.
Thanks for any help!
Note:
- For the purposes of this question, I do not want to "get around" accessing the clipboard --
E.g., I do not want to operate on the value of the DOM element after a paste occurs - I do not want a solution that requires a framework/library (like jQuery, Dojo, Prototype, YUI, ...)
Steps followed
- Determined location of my profile folder by going to URL about:support => Profile Directory => Open Containing Folder
- Tried to enable clipboard in Firefox by creating user.js with the following lines:
user_pref("just.mike", "test to see if user.js works."); user_pref("capability.policy.policynames", "allowclipboard"); user_pref("capability.policy.allowclipboard.sites", "https://my-site.com"); user_pref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess"); user_pref("capability.policy.allowclipboard.Clipboard.paste", "allAccess");
Note: https://my-site.com isn't the real site.
- As it turns out, the
capability.policy
items are not visible using about:config -- due to Bugzilla Bug 284673 - about:config hides "capability.policy" preferences. However, I do think these user.js items "worked" and that the file is in the correct folder, because afterwards:- about:config showed the
just.mike
entry - prefs.js contained all the new lines but in a different order -- alphabetized:
user_pref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess"); user_pref("capability.policy.allowclipboard.Clipboard.paste", "allAccess"); user_pref("capability.policy.allowclipboard.sites", "https://my-site.com"); user_pref("capability.policy.policynames", "allowclipboard"); ... user_pref("just.mike", "test to see if user.js works.");
Zallowclipboard
everywhere so that thepolicynames
line came first due to alphabetization, but that didn't work either.)
- about:config showed the
- Attempted to read the clipboard in Firefox after an
onpaste
event with the following:var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard); if (!clipboard) { throw new Error('internal error -- could not create clipboard object'); } var transferable = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable); if (!transferable) { throw new Error('internal error -- could not create transferable object'); } transferable.addDataFlavor("text/unicode"); clipboard.getData(transferable, clipboard.kGlobalClipboard); var clipboard_data = new Object(); var clipboard_length = new Object(); transferable.getTransferData("text/unicode", clipboard_data, clipboard_length); var clipboard_text = ''; if (!!clipboard_data) { var clipboard_nsISupportsString = clipboard_data.value.QueryInterface(Components.interfaces.nsISupportsString); clipboard_text = clipboard_nsISupportsString.data.substring(0, clipboard_length.value / 2); } return(clipboard_text);
- The code fails on the first line, returning this error in the Firebug console:
Permission denied for <https://my-site.com> to get property XPCComponents.classes
Note: I am actually running it on the real URL, which does get shown in the error message -- I've just changed it to a dummy name here.
- I also saw some other examples where
createInstance
was used on the first line instead ofgetService
, but the first line still generates the same error text:var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].createInstance(Components.interfaces.nsIClipboard); // ...
Environment (This is out of my control)
- No admin access to computer
- Windows Vista
- Mozilla Firefox 10
References
- Enable clipboard in Firefox
- Bugzilla Bug 284673 - about:config hides "capability.policy" preferences
- Access the clipboard in Firefox
- Access the clipboard in Firefox in a slightly different way
- google: "Permission denied for" "to get property XPCComponents.classes"