How to access a file on the computer from the extension??

6,786 views
Skip to first unread message

Yael Bessen

unread,
Nov 9, 2013, 9:22:22 AM11/9/13
to chromium-...@chromium.org
Hi!
I need to copy a text from a text file on my computer,
Can someone help me with the code??
I don't know how to that,really need your help! :)

Adrian Aichner

unread,
Nov 9, 2013, 10:20:42 AM11/9/13
to Yael Bessen, Chromium-extensions
Yael, what have you got so far?

We might be able to point out problems with your code, but it's not likely that someone will write it for you.

Adrian


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/60ee0fc1-7b1d-4fa3-b206-68d89dc0cfaf%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/groups/opt_out.

Yael Bessen

unread,
Nov 9, 2013, 12:06:33 PM11/9/13
to chromium-...@chromium.org, Yael Bessen
Hi,
I don't mean  someone will write me  the code, I just need some direction....
I went through all the chrome extension guide and I haven't found any explanation about accessing files.
Should I just write a regular HTML page with JavaScript function that access file on the computer?
 or are there any special JavaScript functions for working with the extension?
or any API that I should work with?  
any explanation/links about that will be great :)

On Saturday, November 9, 2013 5:20:42 PM UTC+2, Adrian Aichner wrote:
Yael, what have you got so far?

We might be able to point out problems with your code, but it's not likely that someone will write it for you.

Adrian
On Sat, Nov 9, 2013 at 3:22 PM, Yael Bessen <yaelb...@gmail.com> wrote:
Hi!
I need to copy a text from a text file on my computer,
Can someone help me with the code??
I don't know how to that,really need your help! :)

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

Adrian Aichner

unread,
Nov 9, 2013, 1:50:16 PM11/9/13
to Yael Bessen, Chromium-extensions
Have you decided whether an extension or a Chrome app is what you want?



The chrome fileSystem API provide access to a sandboxed section of the user's filesystem


If you want to potentially import files from anywhere on your system, then HTML input type=file should fit your needs.

This is what I use in the example I provided.


(I have meanwhile released r13 but that code is unchanged, just wanted to send a link to a non-moving target in the source tree.)

Just look the the import element and see what functions and listeners it needs. It's all open source. You could even clone the whole thing at

If your file is just plain text you could always just drag the file onto chrome from a native file manager and drop it between two tabs i chrome.

In the text in this new tab you select the phrase of interest and the context menu allows you to Search Google for 'Selection Text'


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Yael Bessen

unread,
Nov 9, 2013, 5:23:59 PM11/9/13
to chromium-...@chromium.org, Yael Bessen
Thanks Adrian for all the great links!

Can I use  chrome fileSystem API in extensions or only in Chrome apps?
basically I don't mind if it will be an extension or a Chrome app ,
 at the end I just need a browser action button that with one click will copy a text from a specific file on my computer
and will paste the text on Google and run the search of the text.
I need it to be fluent.
that is the whole project,nothing else...
what is the best way to implement this? by an app or extension?
or if you have any other ideas...



To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsubscribe...@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Adrian Aichner

unread,
Nov 9, 2013, 5:42:45 PM11/9/13
to Yael Bessen, Chromium-extensions
Sure, make it a browser action extension.
You can use an options page in case your file path needs to be configurable.
I would still recommend to use a input type=file button.
You can preload it programmatically instead of choosing a file manually and also call its click event listener programmatically.

Good Luck!
Adrian


To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Yael Bessen

unread,
Nov 10, 2013, 7:58:30 PM11/10/13
to chromium-...@chromium.org, Yael Bessen
Hi Adrian,
I went through your code of the autosave extension and I'm trying to understand something-
where did you wrote the path to the file?

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Adrian Aichner

unread,
Nov 11, 2013, 9:53:38 AM11/11/13
to Yael Bessen, Chromium-extensions
On Mon, Nov 11, 2013 at 1:58 AM, Yael Bessen <yaelb...@gmail.com> wrote:
Hi Adrian,
I went through your code of the autosave extension and I'm trying to understand something-
where did you wrote the path to the file?

I don't.
 
 

On Sunday, November 10, 2013 12:42:45 AM UTC+2, Adrian Aichner wrote:
Sure, make it a browser action extension.
You can use an options page in case your file path needs to be configurable.
I would still recommend to use a input type=file button.
You can preload it programmatically instead of choosing a file manually and also call its click event listener programmatically.

Contrary do what I suggested here you obviously can't do that.

The user has to be in control and confirm handing off local file data to any random trustworthy code running in a browser.

That ends my contributions to this subject.

Adrian

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Yael Bessen

unread,
Nov 11, 2013, 11:07:29 AM11/11/13
to chromium-...@chromium.org, Yael Bessen
so how can I use your code if I want to get to a specific file on the computer?

Good Luck!
Adrian


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Paulie

unread,
Nov 11, 2013, 12:42:53 PM11/11/13
to chromium-...@chromium.org, Yael Bessen
Hi Yael,

I can see you are struggling here. Out of curiosity I just tried to do what I think you want to do. I am not a great coder but I assure you this took me 15 minutes to test and get working so I if you are ok with javascript you should be ok.

What I did was the following:

- Set a full path to a text file in the permissions section of the manifest.
- Created a browser action which open a popup.html file
- In my popup html file I link to a file called popup.js and jquery which loads the file
- Use jquerys load function to load the file into a temporary container.
- This loads the file and I can log out the content of the file via console.log


Permissions and Browser action in Manifest looks like this:

"permissions" : ["file:///C:/Users/[USER]/Desktop/file.txt"],

"browser_action": {
   "default_icon": "icon.png",
    "default_popup": "popup.html"
  }


I won't give you the exact code....that would be too easy :)

One other tip....to get access to the popups console you should right click the popup then click "inpect element". This will open the developer tools for the popup.

Or you can open the background page for your extension and use the console.log of the background page but you can't do that within the popup code so you would need to add something like this to your popup.js code to get the bg page:

var bgp = chrome.extension.getBackgroundPage();
bgp.console.log("calling bg page console log from popup.js");

Let me know how you get on.

Paulie

unread,
Nov 11, 2013, 12:55:27 PM11/11/13
to chromium-...@chromium.org, Yael Bessen
One change I think:

For some reason my permission file path gave me permission access to any file. So I don't think specifying a full path works. I think you can just put file:///* as the permission instead.

Also - when you load the extension which has file permissions an additional check box appears under your chrome extension at chrome://extensions/  Make sure that is checked. For me it was checked by default. I imagine this is auto checked when in developer mode but if you put it on the chrome web store users would have to tick that manually. (Thats if extensions with file access are allowed on the chrome webstore. Not sure)

Ben Wells

unread,
Nov 11, 2013, 4:11:19 PM11/11/13
to Paulie, Yael Bessen, Chromium-extensions

This approach is only allowed on unpacked extensions/apps. If you try to upload to the Webstore you will get errors.

In general there is no way to access any file by path. The user has to grant access to files for security reasons.

Yael, what about your use case means can't you let the use choose the file?

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Paulie

unread,
Nov 11, 2013, 4:33:27 PM11/11/13
to chromium-...@chromium.org, Paulie, Yael Bessen
Yael said in an earlier post that this was for her own private use only so I think leaving it unpacked is ok.

I just tested a packed version however and it still works but as I suspected anyone who installs it would have to manually go and check the "Allow access to file URLs" under chrome://extensions/

So it might work if uploaded to the CWS but perhaps Chrome may well check for this kind of access and just not approve it. Or maybe it would have to be manually checked and maybe approved depending on what the code does. 

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
Reply all
Reply to author
Forward
0 new messages