I am working on a Chrome extension called Chrome Snippets that will allow you to inject snippets of JavaScript from files but I am having trouble accessing local directories on the user's computer. Anyone have an idea of how to accomplish this?
manifest.json:
{
"name": "Chrome Snippets",
"description": "Run JavaScript on the DOM of any web page from a library of recipes stored on your computer.",
"author": "Adam Fisher",
"version": "1.0",
"manifest_version": 2,
"default_locale": "en",
"permissions": [ "tabs", "webNavigation", "*://*/*", {"fileSystem": ["write", "retainEntries", "directory"]} ],
"app": {
"background": {
"scripts": ["js/background.js"],
"persistent": false
}
},
"icons": {
"16": "img/icon16.png",
"48": "img/icon48.png",
"128": "img/icon128.png"
},
"options_page": "html/options.html",
"homepage_url": "http://adamfisher.me"
}
background.js:
/*
** file: js/background.js
** description: Main functionality of the extension. Checks if a file exists
** for the given host name and loads it.
*/
chrome.webNavigation.onCompleted.addListener(function (details) {
var recipesDirectory = localStorage['Chrome_Snippets_Recipes_Directory'];
var host = "/^(?:ht|f)tps?:\/\/([^/]+)/".exec(details.url); // Get the host part of the URL.
chrome.tabs.executeScript(details.tabId, {
file: ''
});
});