Selecting folders, not files, in Google Chrome - java

I'm creating an extension for Google Chrome, so any code has to be compatible with Chrome and Chrome only. In this extension, I need the user to select a folder from his local machine. This simple task is becoming quite a problem. The chrome extensions options page will not run applets, so I couldn't really do Java. It's Google Chrome only so an ActiveX object is out of the question as well. I just need a simple way of selecting a folder(not a file) and passing its path to Javascript. Might this be possible in Flash Actionscript? It seems FileReference and FileReferenceList classes in AS only allow you to choose a file, and not a folder. Is there another possibility besides Flash? All the options page files DO rest on the local users machine, so it's not server side.
Thank you for your time.

You can use the webkit-directory attribute on your element to select directories and get the same sort of result as from the "multiple" attribute.
A demo of this: http://www.thecssninja.com/demo/webkitdirectory/
The chromium bug: http://crbug.com/58977

Related

What are possible ways to modify or customize an installer after it was built and signed?

We would like to brand a piece of software based on which customer's website it is downloaded from. E.g. by showing the customer's logo etc. All we need is an ID, the software can handle the rest of the customization at runtime based on that.
The number of customizations is potentially large, and we would like to avoid prebuilding and storing these installers.
I'm open to consider all options, especially some out-of-the-box ideas.
I think it is impossible to change a signed installer (exe/dmg) without breaking the signature.
Some ideas I'm toying with (and their trade-offs):
Store the ID in the installer download filename (Con: Brittle, browsers might change the name or append a suffix to avoid duplicate names)
Ask the user to enter a code shown on the download page (Con: some inconvenience for the user)
Provide a zip with installer and config-file next to it (Con: some users will not manage to unzip, or only unzip the installer without the config file)
On Linux the installer shell script can be modified at download time, as the script cannot be signed.
Set up a server that builds and signs installers on the fly at the time of the download request. To speed this up, it could be yet another installer wrapping the main installer, and it's only task would be to extract and run the main installer with the ID parameter. (Con: complex infrastructure, code signing certificates on the public facing server, very slow for MacOS notarization)
Chromium-based browsers like Google Chrome, Chromium, Opera, Microsoft Edge, etc. save the URL of origin and the referrer URL for all downloaded files on Windows 10 (only on NTFS file systems) and Linux (only on Ext4).
For details see for example here. On Windows the metadata is also accessible from command line or direcly from Java.
There seems to be a similar feature on Mac. See for example this question on superuser.
Accessing this metadata from within your installer could help to customize the behavior of your installer. While the data will not be available in all setups (e.g. Internet Explorer stores only a zone ID and no URL) and may get lost (e.g. a user deletes the data or copies the file to a file system that does not support metadata) it could propably cover the majority of your users. Asking users to enter a code when the metadata is not found could still be used as a fallback.
Main concern I would have with this approach is that the Chromium developers may decide to remove this feature in near future or make it optional, like the developers of wget (see for example here)
On latest Windows 10 I still get the following metadata for a downloaded file with both, latest Google Chrome and Microsoft Edge Browser:
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://httpd.apache.org/
HostUrl=https://mirror.klaus-uwe.me/apache//httpd/httpd-2.4.46.tar.bz2

Downloading Files with ChromeDriver

I have a project where I need to download an audio file in ChromeDriver. The behavior here is different from in regular Chrome, where if I visit the URL, it'll automatically start downloading a file. If I do the same thing manually in ChromeDriver, it will not download the file.
I've tried different configurations of the chrome options/preferences. I've also found options that worked with old versions of chrome, that no longer work anymore.
Here is one of the better resources I found, but it still didn't work, even with their updated blog post
https://dkage.wordpress.com/2012/03/10/mid-air-trick-make-selenium-download-files/
When I attempt to use his solution, my chromedriver abruptly crashes itself in a non chrome-esque way. It just disappears. Not "Something went wrong" page like you'd normally expect. I end up with Java not being able to find my Session, cause it stopped existing.
Has anyone been successful at downloading files through Selenium webdriver in Chrome? If I need to use another browser, I can.
I'm currently using Chrome Canary.
I have the same problem. One solution that might work is to use another library, that is able to operate outside of the browser. I found these stackoverflow post discussiong this issue:
https://sqa.stackexchange.com/questions/2197/how-to-download-a-file-using-seleniums-webdriver
it contains this blogpost wich gives you some sugestions.
https://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/
Window automation
The first approach smells like “brute force”: when searching the net for a solution to the problem, you easily end up with suggestions, to control the native window with some window automation software like AutoIt. Means you have to prepare AutoIt such, that it waits for any browser download dialog, the point at which Selenium is giving up, takes control of the window, saves the file, and closes the window. After that Selenium can continue as usual.
This might eventually work, but I found it to be techical overkill. And as it turned out, there was a much simpler solution to the problem.
Change the browsers default behaviour
The second possibility is to change the default behaviour of the browser. When clicking on a PDF for example, the browser should not open a dialog and ask the user what to do with the file, but rather save it without comments and questions in a predefined directory. To accomplish that, a file download has to be initiated manually, saved to disk and marked as the default behaviour for these file types from now on.
Well, that could work. You “only” have to assure that all developers, hudson instances, etc. share the same browser profile. And depending on the amount of different file types, that could be some manual work.
Direct download
Taking a step back, why do we want to download the file with Selenium in the first place? Wouldn’t it be much cooler, to download the file without Selenium, but rather with wget? You would have solved the second problem as you go. Seems a good idea, since wget is not only available for Linux but also for Windows.
Problem solved? Not quite: what about files, that are not freely accessible? What, when I first need to create some state with Selenium in order to access a generated file? The solution seems ok for public files, but is not applicable for all situations.

develop a user defined plugin for web browser

How to develop a user defined plugin for a web browser.
It should features:
It should be installed in any browsers.
It should be executed whenever the browser starts.
It should monitor the web page and access the web page that the browser displays.
It should monitor and access the web page (for example, getting a value from a text box) irrespective of the web page the browser displays. (The web page can be of any URL either google or any domain)
How to start with it? It would be helpful if there is some sample. Thanks in advance
For Firefox < 4 write an Addon, for 4 and above Jetpack will be the way to go. For Chrome write a Extension. Opera, well wait till 11.5 ships. Safari 5. IE.
Read the documentation for each browser.
Hm...
I hope you tell the user about that.
Right now it reads like you want to deploy something to a PC and monitor all browsers, well if you want to do that you'll have to put some effort into it.
I don't think 1. is possible, you will have to create multiple versions of your plugin in order to work with each browser.
There is not a single example, because as I mentioned, you are going to have to do something different. You will need to determine and target specific browsers. I would suggest starting with one and once you have it have it working move to the next browser.
Do you mean a Plugin (like Flash, PDF Reader) or and Extension?
Plugins are native programs and extensions are normally coded in JavaScript & HTML.
Depending on what you want to do, an extension is enough powerful and the better choice.
There is no browser independent way to implement plugins. For each browsers you must read the interface reference. For example the reference for chrome: http://code.google.com/chrome/extensions/getstarted.html

Getting the Folder Path via the Browser using Internet Explorer

I would like to create a folder selector for my application which will only run on Internet Explorer Browsers (IE6+).
I would like to get the full folder path a user wishes to use via a HTML browse button or similar and then pass this to my server side application which is written in PHP! This can not be done via JavaScript for security reasons so I am looking for any other alternative that will work.
I had implemented a solution using a Java Applet but this did not work out as it didn't work on IE6, plus the browser security is locked down where I am deploying this app, meaning I am unlikely to get away with an applet.
The current solution is getting the user to paste in the folder location into a textfiel, this isn't acceptable any more.
Any implementation advice welcome!
Thanks all
If your app is IE only you can create a simple ActiveX Control with only one method:
HRESULT BrowseForFolder([out] BSTR folderName);
ATL Wizard will give you major portion of code.
But I would consider using flash for this:
It is more widely used then Java (I
think so).
ActiveX is strongly depends on
browser's security options and more annoying to install.
Your task is rather small, so it can
be implemented without deep skills, if you not familiar with flash

Does this applet work for you?

I have found a solution to get the full file path of a file that is about to be uploaded using a Java Applet. I need this for an internal system not anything else "dodgy"!
Can anyone confirm if this works in an IE6 browser: http://www.maschek.hu/preview/ffx3_file/filepath.html
I have an IETester application that has IE6/7/8 in one place and all IE6 does is just load/wait for the page and it has been 10 minutes. I am trying to determine if this applet will work in IE6?
Its using PARAM tags so is that a no? This has worked on my IE8.
To get this to work, do I need to do more than change the PARAM tags to Object tags?
Thanks all
Check out this website -->
http://www.spoon.net/browsers/
Its a browser Sandbox. You can run any browser from the web. Very useful stuff.
If you want to test your application in IE6 you could use the Internet Explorer Application Compatibility Virtual PC Images supplied free by Microsoft. This will probably be more reliable than asking other people to do it for you.

Categories