Question

I've managed to get the element of a button inside a a webpage . I know its ID , its class , etc ; I even managed to trigger the click event from within a content script from a Google Chrome extension . The button is inside a Google webpage.

There's a Browse button though that opens up a openDialog window and prompts the user to chose a certain file for uploading. How can I go on automating this upload without prompting the user for the file? I just want to feed it the string from the content script and the webpage takes it from there.

Is there a solution for this in Google Chrome, Firefox?

Thank you!

Was it helpful?

Solution

if you are uploading from the clients computer, you can't. Its a security feature of file.upload. If you examine the path to the uploaded file, you'll notice c://fakepath/xxxxx this is to prevent applications finding out file structure on the clients computer.

https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications

OTHER TIPS

In Firefox add-ons (well, in the privileged parts, i.e. not SDK page-mods and so on), you can construct a file object you could use with the regular HTML5 stuff (XMLHttpRequest, FormData ;)) directly via the File "constructor":

var file = File("path/to/some/file");

When it comes to Chrome you're out of luck as @David already correctly pointed out in the other answer.

Edit 1: Actually, when it comes to chrome it might be possible to request a file://* permission, have the user opt-in explicitly, and then use xhr etc. to first retrieve the file as a blob and then upload the blob with another xhr. Haven't tested this, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top