Version 15 no longer allows copy to clipboard
We have been setting signed.applets.codebase_principal_support in FireFox to allow copying to the clipboard in Window XP and Windows 7. It has worked fine until version 15, and it no longer works. If we cannot use this feature, we will have to convert all of our users to IE or some other browser that allows us to do the copy.
被選擇的解決方法
There is a code sample in the system details list.
It is usually best to sign your script in such cases.
- http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard
- http://www.mozilla.org/projects/security/components/signed-scripts.html
所有回覆 (8)
Are there any new errors or warnings in the error console (Ctrl+Shift+j)?
Do you have a sample page online that demonstrates the problem? If so, could you provide the URL?
選擇的解決方法
There is a code sample in the system details list.
It is usually best to sign your script in such cases.
When I entered the lines from http://kb.mozillazine.org/Granting_JavaScript_access_to_the_clipboard, even 14.0.1 would not allow access to the clipboard. FF no longer reported access was not allowed, nor did it give any other indication of a problem, it just ignored the request. I did use only the main website url (www.mybfl.com) for the allowed url. Do I need to specify the actual webpages that will be using the clipboard?
I had to remove the lines to get 14.0.1 to work again, and 15 did not work either way. It appears to be something in the update, however, since FF 15 does work on one of our computers.
It there something I can do to further isolate the problem? I could delete FF on one of the failing computers and download a new fresh copy of FF 15. However, we have a lot of stuff that FF knows about (bookmarks and passwords) that we do not want to lose. Is there a file I can save that has those settings in it before I delete FF?
Other than the bookmarks and passwords, our FF is vanilla. We do not modify any settings other than the febooti clipboard change.
Thanks
I have been told the problem was that Java 1.7 got hacked and FF 15 checks to see if Java 1.7 is running, and if so, disables the copy to the clipboard. If Java 1.6 or FF 14 is running, everything works correctly.
If that is true, that would be account for our problem.
I can't say that this question is satisfactorily answered.
I too have been wrestling with getting Firefox to let you manipulate the clipboard with JavaScript and I find it amazing that this is incredibly simple to do in IE, with merely using window.clipboardData, and suddenly impossible in Firefox.
As of version 15, firefox no longer lets you access any of the properties under netscape.security. Previously, you kick started getting access to such advanced privileges with a call to netscape.security.PrivilegeManager.enablePrivilege, but the Java console will show you that there are no properties under netscape.security, unless you fiddle with prefs.js.
Obviously, there's another way to do as I highly doubt that sites running in Firefox that can store things to the clipboard are messing with user preferences.
Granting JavaScript access to the clipboard and Signed Scripts in Mozilla are clearly outdated documents. The second site insists that I first visit Netscape Object Signing: Establishing Trust for Downloaded Software to get a better idea of Netscape object signing, but that page no longer exists, and I wouldn't be surprised if even if I did find that article, it would be nothing but completely antiquated info. Signed Scripts in Mozilla also says that you access signed resources with that jar: protocol, which sends us on quite the elaborate goose chase as I challenge anyone to show me a single website that has me go to some jar:http:... site that has a button that lets you copy text to the clipboard.
Does anyone have an actual solution for this? All we want is for a webpage in Firefox to examine and manipulate the clipboard. There are still several sites that can do this in Firefox. I'm drawing a blank at the moment as to which ones, but I'll be back...
I promise you good coders, I will not rest until I find a solution of which I can provide a specific example. Feel free to beat me to it...
I would be interested in seeing some examples that work now that enablePrivilege was disabled in Firefox 17. Maybe some new HTML5 sorcery, or a plugin (Flash? Java?) is used?
So… of what I can tell so far, it is quite true that Firefox no longer allows scripts to access the clipboard, with the exception of making add-ons in the XUL environment. When I first ran into this problem in version 15 on a page I was running locally, the error returned was
A script from "file://" was denied UniversalXPConnect privileges
in response to the statement netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect').
Nowadays, you’ll get
TypeError: netscape.security.PrivilegeManager is undefined
I first learned of this method of accessing the clipboard from one of the Mozilla Developer docs. The article begins: “Mozilla provides a number of interfaces for accessing the clipboard”. I’ve not yet found any information about the other interfaces.
Thanks to Google, I did find a live link for Netscape Object Signing: Establishing Trust for Downloaded Software, which Signed Scripts in Mozilla recommends reading before working with signed scripts. The Signed Scripts article says you should use Mozilla’s signtool, apparently from a suite of programs called NSS tools. It provides that link to the tools, but the only link for the signtool program is to the source code files that you must compile. The man page for the program is also at the Mozilla Developer Network. I’ll try to study this material soon and provide a more straightforward guide.
In the meantime, I found a forum that talks about another approach to accessing the clipboard by way of saying document.designMode = “on”. This makes every element editable, as though every element’s contentEditable property were assigned to true. In fact, both properties came from IE.
In the forum I linked to, there’s a JS example were designMode is turned on and a Range is used to select text. The command document.execCommand("copy", false, null) is intended to actually copy the text, but if you try this in Firefox, you’ll get
Error: Access to XPConnect service denied
I also tried toggling signed.applets.codebase_principal_support to true and restarting Firefox but, unfortunately, the JavaScript console still reports no PrivilegeManager property underneath netscape.security, and document.execCommand gives its same error in designMode.
One popular workaround for allowing Firefox to add text to the clipboard is ZeroClipboard, which uses an invisible flash movie. You can associate the movie with any element and it acts as a conduit for an element’s access to the event model. I’ve not used it yet, but the example works.
This works for me via CAPS prefs.
- user_pref("capability.policy.policynames", "allowclipboard");
- user_pref("capability.policy.allowclipboard.sites", "http://");
- user_pref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess");
You can test it this way for this forum:
Copy and paste this code in the command line in Browser Console and press Enter or paste the code in the Code field in the Error Console and click the Evaluate button.
- Firefox/Tools > Web Development > Browser Console (Error Console)
var {classes:Cc,interfaces:Ci} = Components; var cp = "capability.policy."; var PS = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService); var PB = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch(cp); function pp(pn){return("user_pref(\"" + cp+pn + "\", \"" + PB.getCharPref(pn) + "\");")} var obj = new Object, txt = "Granting Clipboard Access"; try {obj.value = PB.getCharPref("allowclipboard.sites");} catch(e){obj.value = "";} if (PS.prompt(null,txt,"Enter website(s) to allow access to the clipboard\nUse a Space character as separator",obj,null,{})){ PB.setCharPref("policynames", "allowclipboard"); PB.setCharPref("allowclipboard.Clipboard.cutcopy", "allAccess"); PB.setCharPref("allowclipboard.sites", obj.value); var ujs = []; ujs.push(pp("policynames")); ujs.push(pp("allowclipboard.Clipboard.cutcopy")); ujs.push(pp("allowclipboard.sites")); obj.value = ujs.join("\n"); txt = "Add lines to user.js"; PS.prompt(null,txt,obj.value,obj,null,{}) }
(CAPS prefs aren't stored in prefs.js, so this only works for the current session; use user.js)
Copy and paste these codes in the command line in the Web Console (Web Developer > Web Console; Ctrl+Shift+K) and press the Enter key.
Switch design mode on:
- document.designMode = 'on';
Select some text and evaluate this to copy selected text to the clipboard:
- document.execCommand("copy", false, null)
由 cor-el 於