Write image to clipboard in Firefox - firefox

I'm currently trying to write an image blob data to the clipboard in Firefox (104.0 Linux).
I seeked information about Permissions, and Clipboard.
As for the permissions, I found contradictory things, some that say you should request for some clipboard write permission (https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API or https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard), some that say that the permission is temporary granted on user interaction. The later seems to work because I'm able to use navigator.clipboard.writeText("blah") to write successfuly to the clipboard.
Problem is when trying to write data. Mozilla documentation states about 2 versions :
Clipboard.write() (https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write)
Seems obsolete or something, because the method simply doesn't exist, I only have writeText()
setImageData() (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/clipboard/setImageData). This one makes absolutely no sense as browser doesn't exist, as well as setImageData() in the navigator.clipboard instance
Any help would be grealty appreciated here !
EDIT : in fact to actually gt a definition for write() method, user has to manually define a bool true value for flag dom.events.asyncClipboard.clipboardItem in about:config
So, pretty much unusable in production environment, if you don't expect power users only...
So now, I have a new issue, even with that bool set to true, firefox goes "lack of user activation" half of the time, even though the tab is focused. It seems I have to actually do something on the page in order to get it to work ; IE. move the mouse, click here and there...
I even tried to add a prompt, as my clipboard.write() occurs deep in await/async stuff under the button click handle (I'm actually in a NodeJS/Nuxt environment), and writing to the clipboard from the prompt, and even there, I get that error...

Related

Cannot complete download from popup when prompting location with saveAs

I've been working on a browser extension allowing users to generate epub files from any webpage.
To use the extension, a user has to click on a toolbar button which opens a popup. On the latter, after specifying a config, the user clicks on "Generate". Here is my issue though:
When I use the download API directly, and specify saveAs to false (i.e the user is NOT prompted where to save the file), then the download is completed as expected and the file saved in some location.
However, when I do set saveAs to true --- which is what I want in the final version --- then once the user has selected the location under which to save the file, the download fails. My intuition is that as soon as the file location window pops up, the popup looses focus and dies, which makes the download impossible to resume.
Is that the explanation? And is there a way to prevent such a problem? I do not find my use case to be much of a stretch, and do not get why popups associated with browser actions are not allowed to loose focus for file selection.
Another weird thing is that I'm pretty confident this problem only appeared recently in firefox, since when I started developing the extension, I had no issue.
My intuition is that as soon as the file location window pops up, the
popup looses focus and dies, which makes the download impossible to
resume.
That's right...
Browser Action Popup is page and once page is closed, async operations will lose their reference. It is best to pass async operations to the background script.
You can use
runtime.sendMessage()
to pass a message to the background script to run the download.
You can also use the async
runtime.getBackgroundPage() to run a function in the background script but the first option works
easier as you dont need to wait for the async response as in runtime.getBackgroundPage()

Writing a c# or c++ application which can detect if browser is going to download a file

I am going to write an application which runs in the background on windows platform. If user is working on any browser (IE, Firefox, Chrome, etc) and any of the user action results in downloading activity, the background program should take control. The background program pop-ups a window asking user, if they want to download. If user proceeds with OK, then background program sends signal to browser to stop its download process and the background program will do download. If user rejects download by the background program, then default download of browser can go on.
For this please suggest if any working model is there in c#/VB.NET/C++ or how to achieve this activity.
Will very much appreciate your kind help.
Thanking you very much in advance.
I don't think you understand the whole notion of downloading. Any resource you get from the Internet is downloaded. Hence, anything would trigger your application. You can, however, try to "parse" URL to see the extension but this does not have to mean nothing, since you can give any file an arbitrary extension (well not exactly arbitrary, but you know.. ). Another option is detecting FTP downloads ( i assume this might be of more interest ). This way you'd "only" have to check for a specific protocol. The reason i quoted only in the last sentence is that none of these tasks is a simple one.
You basically want to write a Proxy, or use an existing one.
You might wanna take a look at WinPcap
Finally, none of this options really give you the infromation whether user is going to download a file. But if you write a proxy, you could stop the endpoint application of obtaining that file once you download it.

Can the last opened file location be directly altered?

As I understand it, when a file open dialog box (such as GetOpenFileName) is used, Windows will automatically remember where the last file was that was opened by the program, and Windows remembers these locations separately for each program. Is there a way to directly alter this, in order to cause the file picking dialog for program X to start in C:\Example\Directory?
I'm attempting to automate a program which has been programmed to work only through a GUI, and I don't have any access to the internals of this program (such as being able to alter how it calls the file picker). Instead, I'm using a mouse macro (via AutoHotkey). If I can be completely sure that the file picker will start in a particular place, I should be able to automate the rest with mouse clicks.
If you had access to the source code, I'd suggest you just change the lpstrInitialDir property of the OPENFILENAME passed to GetOpenFileName().
Outside of that, you'll want to change the registry keys for the MRUs:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32
What might make more sense, and might fix the issue you're having, is also changing the Working Directory so that the default location isn't "My Documents", if you're experiencing that.
Depending on the operating system, the results vary:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx

What's the proper way to call VBScript from Firefox?

I'd like to be able to call a vbscript from Firefox that resides on network share. Thus it is visible to all my team members at work. Using:
<a href='file://///server/path/to/file.vbs'>run me</a>
What this script does is it grabs server side information through Samba from the client-side, and uses that information to bring up a MS Outlook new e-mail window with the HTML formatted server side (a Linux system) information filled in. I do not send the e-mail yet because I want to allow the teammate to make sure what they are about to send is correct. And we have to use Outlook. Unfortunately mailto: does not appear to allow any kind of HTML formatting, which is why I've turned to VBScript.
Seems to work in IE, although you get prompted before it allows you to run it. I guess that's OK for now. It's a little annoying having to make sure you're in IE to run it, especially for those of us who prefer not to use IE.
Right now all Firefox does is display the code contents in the browser.
I'm not even sure if I'm going about all this the right way, but from where I stand, I guess I'd like to be able to run it from Firefox. If not, I'll survive. Thanks
I don't think this is possible. Even if it is, it's probably a security risk.
To launch the script, you'll have to run "wscript.exe file.vbs", but that's not allowed otherwise Viruses can exploit this easily.
Therefore, unless you want to use some browser exploit, this will not be possible.

Can an app use the clipboard for its own purposes? (read: who owns the clipboard?)

In PowerBuilder's IDE, the code autocomplete feature uses the clipboard to communicate the completed text to the code window. By doing so, it overrides whatever was stored on the clipboard before. So, if you had the winning numbers of the next lottary stored on your clipboard, and you used the autocomplete to turn m_goodfor into m_goodfornothing, you've just lost your only chance of ever getting rich, and you're left with nothing on your clipboard.
Features like that are the reason I hate software. It looks like it was implemented by some intern that noone was looking after. However, there's also a chance I got all worked up for nothing, and making such use of the clipboard is absolutely legit. So, can an app use the clipboard for its own purposes? Who is considered the owner of the clipboard?
(Bonus votes to whoever puts himself in place of the feature's programmer, and provides some reasoning for this being done on purpose, assuming the users would actually benefite from it)
You are probably right on the intern reasoning. There is absolutely no reason why an application would use the clipboard to communicate information other than pure laziness. Even between processes, there are other, better ways of communicating information.
Other then letting the user paste information in another application, there is no reason to use the clipboard.
The programmer did it because it was easy, and put his needs above those of the end user. There are many programs that do this, particularly add-ins to outlook, VB, etc., which copy/paste their buttons onto the toolbar. Any user that runs a clipboard extender (like my own ClipMate) will absolutely hate this behavior (and you'll be "busted" right away).
Here is my favorite quote on the subject:
“Programs should not transfer data into our out of the clipboard without an explicit instruction from the user.”
— Charles Petzold, Programming Windows 3.1, Microsoft Press, 1992
An app should never change anything on the clipboard without the user initiating that action. My .02 anyway.
Bonus votes to whoever puts himself in place of the feature's programmer, and provides some reasoning for this being done on purpose
Using clipboard for application communication
They are always a better way to do it. The programmer might have done it this way because it was faster to implement OR because he really wanted to have this value in the clipboard after the action. At least, if he didn't wanted to have it in the clipboard he could have get the value from the clipboard, store its value then replace the old content of the clipboard inside the clipboard and everything would have be more "transparent" ans less frustrating for the end-user.
I have built a piece of functionality into an App that uses the clipboard. Business was requesting a way for users to seamlessly capture a screen shot and upload it.
I worked with the business to develop it and what we came up with was a user simply hit the print screen key and clicked "upload" in my app.
The Java Applet running in the background pulled the image off the clipboard and displayed a formatted preview to the user, The user then added in a file name and description and clicked save.
Using the clipboard this way saved the user the time of having to capture the screen shot save it somewhere then find it through an upload interface. Even if we did go that route by the user hitting print screen to capture the image in the first place they are already overwriting whatever was on the clipboard in the first place.
Using the clipboard isn't all bad but I certainly agree using it in an IDE is a def no no.

Resources