WebExtensions: is it possible to intercept/register a handler with the "file open" dialogs? - firefox-addon-webextensions

I have a Web Extension that occasionally deals in files -- usually by sending off a URL to the file to a remote server or by downloading the file at the user's request and shipping off the bytes to the same server.
This works fine for most use-cases, but sometimes you'll come across a site that automatically triggers a download of a file and pops open the file-open dialog for the user to handle. I wasn't able to find any documentation or filed bugs to this effect, but is there a way to register an extension to appear as a handler in that dialog?

Its currently not possible to add an icon to the file chooser dialog with WebExtensions. Feel free to open a feature request here: http://bugzilla.mozilla.org/
If you want to handle an action whenever a download occurs, you can use
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/downloads/onCreated

Related

How to best handle file upload failures in selenium webdriver

I am looking for any ideas on how best to handle file upload failures in selenium webdriver.
Recently I have been seeing a higher number of failures in my webdriver test suite, the error I am trying to fix is a failure in the Internet Explorer tests caused by a file upload failing.
In webdriver the only way I know to upload a file to an input element is to use the SendKeys() method and pass the file path to SendKeys() this works like a charm in chrome and firefox but periodically have had issues with it in Internet Explorer. What appears to happen is the file upload window gets opened but the path is not typed nor is the file uploaded. This leaves the node with a file upload window open, being this is a native window's window and not a webpage selenium cannot interact with the pop up.
The result is the HttpWebRequest does not get a response back triggering a WebdriverTimoutException. This results in the session getting cleaned up. This causes a cascade of failures for all other tests in the suite as the session has been terminated.
Environment Info:
Selenium.Webdriver & Seleneium.Support version 3.7.0
IEDriver 3.7.0
Testing in IE 11
I may be late to answer this question, but someone will benefit.
The file(s) in question should be available on the machine (be it local or remote server) that your program is running on, for example, in your /resources directory
On your local machine, this should work.
chooseFileElement.waitForVisible().type("/file/path/filename.jpg");
clickButton("Attach File");
On Remote Server however, you need to associate a new instance of LocalFileDetector to the <input type=file> element.
LocalFileDetector detector = new LocalFileDetector();
File localFile = detector.getLocalFile("/file/path/filename.jpg");
RemoteWebElement input = (RemoteWebElement) myDriver().findElement(By.id("fileUpload"));
input.setFileDetector(detector);
input.sendKeys(localFile.getAbsolutePath());
clickButton("Attach File");
It really depends on how you've written your code. What I would do is when you get down to the end and detect that you've gotten into a bad state, e.g. the File | Open dialog has been left open, close the dialog and start that part of the script over. I'm not sure what start over in your case would mean... maybe it means reload the page and start from there... maybe it means just .sendKeys() to the INPUT again.
You should be able to dismiss the dialog by sending an ESC to the page. You should be able to use .sendKeys() on the BODY tag or whatever.
You should be able to detect the bad state by catching certain exceptions.

IE file download box get location

i am currently working on a issue where i need to get location of the file downloaded.First let me explain the scenario.
I placed a link in my page and when user clicks the link it shows file download dialog with open/save/cancel options in IE.Now when the user clicks on the save button and choose a location to save the file i need to get that file saved location using whatever options possible.
Thanks!
I do not think you can... at least not easy. This runs on the client, and for security reasons you can not acces the client's filesystem with javascript.
Maybe it is however possible using a flash or silverlight plugin, as the user can allow access from within these applications to the local filesystem. It might be very difficult tho...
The browser will not allow you to access information about the clients filesystem.

Silverlight and XtraReports - opening generated PDF report in new tab in browser

I'm trying to send a PDF file from a WCF to silverlight client. PDF is generated by DevExpress XtraReports (in method XtraReport CreateReport(string reportTypeName, RootGenericReportParameterContainer reportInformation)).
Acually PDF is saved somewhere on clients computer after choosing save path in file save dialog - DevExpress takes care of everything - but I don't have a clue how to open the PDF in new tab in browser.
And here is another problem. Silverlight 4 has no access to local file system right? So information about local PDF location is useless. Maybe it would be better to save the PDF in WCF and send a link to it to the client - but how?
I would first question why you need to send the file to the Silverlight client. Get rid of that requirement and the solution becomes much simpler. Silverlight can provide a link that opens a new browser tab. That link would be handled by the web domain, processing it as an HttpHandler, generating the PDF file for the browser. Your PDF url doesn't have to reference a physical file, you can still generate it on request, handle querystring values, etc... Lots of different ways to do this.
Seems that the question isn't really about DevExpress or Silverlight - you're just looking to open a [document of some kind] in a new tab. Each browser natively handles things differently, and users can change tab handling to whatever they want. And (as you mentioned) once the user has downloaded the file, you no longer control it.
Your best bet (and the way I do it) is probably to have a link pointing to a handler/file using "target='_blank' " in the anchor tag on the webpage. From the server side, you would want to set the "Content-Disposition" header to "Inline" to indicate to the browser that the document should be displayed in place instead of downloaded ("Attachment").

Web, Silverlight. Always show save file dialog when user try to download file

I have link to file (Inside sharepoint list) I need always to show Save file dialog.
But some browsers starts to download file without promt.
What should be done to avoid automatic download?

File content in Javascript in a Browser

The only way I know to take the contents of a local file and push those bytes to a server is to set up a form post with an <input> of appropriate type to prompt the user to select a file.
I would like to do the same thing only pushing the data through XMLHttpRequest (no cross-scripting tricks).
Currently, we do this with an iframe to get the post behavior.
My sense is the iframe is the only solution, but I post here in case I've missed something.
You could use the JavaScript File API (available in Firefox 3.6 or later and latest versions of Chrome and Safari). Basically, you can add an event listener to the <input> tag that will fire when a user selects a file. Then, you can upload it using an XMLHttpRequest. Also, the File API can allow you to do other fancy stuff, such as drag-and-drop uploads, getting information about a file before it is sent to the server, and providing a progress bar as a file is uploading.More info: https://developer.mozilla.org/en/using_files_from_web_applications
This is not a good cross-browser solution because it doesn't have good support in all the popular browsers (Internet Explorer), but you could use feature detection in JavaScript to detect if the File API is available and revert back to your iframe method if it is not.

Resources