Is the Chrome extension possible to write to a file in the Chrome system directory?

In fact, I never wrote a real extension. I made one that was just a drop down list of links, but actually it is not. In any case, instead of diving primarily into the massive collection of guides for writing Chrome extensions, I decided that I would first make sure that my idea would be possible.

My plan is this: I want to take the currently playing track in the Pandora player and send the track information to a source outside the browser (in my case, a Python script).

Getting the information itself should not be difficult; their new HTML5 interface makes this part super easy. The problem is to report this information as soon as I receive it. I would like you not to upload data to the web server, and Python pulled it from there.

Obviously, Chrome won't make it easier for extensions to send DBus messages or anything else, but is it possible to write the file to the Chrome system directory somewhere and get Python? Am I completely ridiculous even asking such a question?

EDIT: I thought I would report on what I actually did for everyone who happens in the future in this matter. Since I only needed this extension to work on one computer (mine), I just installed mod_python for Apache, and my extension sent its data directly to my Python script, waiting on localhost. This has the advantage that you do not need to try out the URL or the Python file, as I assumed I needed. It also avoids the potential security risks associated with NPAPI.

+6
source share
2 answers

The only way I can think of this is the NPAPI extension. NPAPI allows you to include a native binary file with your extension, with which your plugin will be able to communicate. You can do almost anything you like in this binary.

However, heed the warning on page I related to the above:

NPAPI is a really big hammer that should be used only when no other approach will work.

The code running in the NPAPI plugin has full permissions of the current user and is not isolated or protected from malicious input by Google Chrome. You should be especially careful when handling input from untrusted sources, such as when working with content scripts or XMLHttpRequest.

Because of the additional security risks, NPAPI presents to users, extensions that use it will require a manual review before it can be accepted into the Chrome Web Store.

+3
source

This is an old question, but there is another option:

If you write to localStorage from your extension, you can access the Chrome local storage directory, where each site and extension is usually provided with its own file. On Linux, the directory is located in ~/.config/google-chrome/Default/Local Storage , and on Windows it is located in %LocalAppData%\Google\Chrome\User Data\Default\Local Storage . I do not have a Mac to test, but it is not difficult to find.

The data is stored as what looks like JSON inside SQLite. I personally did not try to turn it into something useful, but there is information there. I just did a quick test and the file seems to be updated as soon as you write to localStorage so that you can put a file system watcher on it and get notified at any time.

0
source

Source: https://habr.com/ru/post/902985/


All Articles