How to sync chrome extension options - javascript

I've made a Chrome extension with an options page. The data is saved in localstorage and works just fine.
Chrome doesn't sync the localstorage to the cloud, just the extensions. This means that any user data will not sync to other computers of the same google account.
I can not find an API at http://developer.chrome.com/extensions/docs.html which allows me to sync the user-chosen preferences.
What methods do you suggest?

In the (hopefully near) future, you'll be You are now able to store stuff in chrome.storage.sync, and it will be synced automagically.
Unless you need something right now, do consider putting all your configurations in an single object, sometime later you'll be able to just sync it!
Edit: now this is available in stable Chrome!

Nathan Moos told you truth :) But you don't need to write it by oneself, you can use Ankit Ahuja solution from Sylebot extension. You will need file js/sync.js. Source code is great, and it works great!

You should be able to use HTML5 WebDatabases, but you cannot. See comments below.

You could serialize some of the options to a bookmark and tell the user to enable bookmark sync. Then, you could read from the bookmark or build a pseudo-"localStorage" object around the bookmark.

You could try to do it with Google Docs like Chrome does with bookmarks. I don't know how far the api reaches but this seems a rather basic operation.

Related

Open network location in Javascript

Is there any way to open a file or a folder located on the network? I understand reasons Browsers dont allow that. And I know that I need to add extensions to Chrome and FireFox to get a network folder shown. When I meet these requirements and I have an href that looks like:
file://network volume/directory
then by clicking on it I get a folder open. Now I need to open it by clicking on a button. Is that even possible?
Thanks
Assuming you jumped all the hoops and completely unsecured your browser (which I did not, which makes this answer a guess rather then a solid answer), I suppose that javascript actions on window.location might work. e.g.
window.location.href = 'file://foo/bar/';
or the window.open API http://www.w3schools.com/jsref/met_win_open.asp
A side note, do check the HTML5's file APIs. They explicitely require that user picks the files explicitely and do not seem to allow what you require, but they are the endorsed file approach and if, by any chance, your requirements can be met by using them you'll save yourself from a world of pain and going against the flow... See http://www.html5rocks.com/en/tutorials/file/dndfiles/ for a good starter.
If I understand you correctly. You want to access a file on the local server.The following would work for you.
window.open("http://www.example.com");//opens a url
window.open("file://server/serverfolder/index.asp");// server side

Detect installed extensions in browsers?

Is it possible to detect via JS what extensions / add ons a user has installed on his browser? The use case was the a particular chrome extension, Autofill was setting some text values into hidden zip fields causing some validations to fail and I want to show a message to the user that this extension might create problems.
For Firefox: First snippet of code on: AddonManager.jsm - MDN
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAllAddons(function(aAddons) {
// Here aAddons is an array of Addon objects
});
// This code will execute before the code inside the callback
Must run this code in privelaged javascript, as in not a tab. You can try for specialPowers though I don't know how that works.
To run privelaged script from your site you will have to create a firefox addon and addEventListener's to your site, like a button to list the addons, you would attach a privelaged function to that.
With the addon you enable/disable addons, but users find that annoying because addons do some obtrsuvie stuff on install sometimes.
For Chrome extensions specifically, only certain extensions are detectable so this is not a very good method, but as far as I know, there are no longer any reliable methods to detect browser extensions.
For the extension that you want to detect, you would need its Extension Id and its Web accessible resource.
Some extensions have web accessible resources and some do not. If there is no web accessible resource, you will not be able to detect that extension.
To find the web accessible resource, you will need to look at the extensions chrome.manifestfile. It will tell you if there is web accessible content. For example, the chrome.manifest file might say:
content web-developer content/web-developer/ contentaccessible=yes
Generally, its not very effective to look for browser extensions since you have to know which extensions you want to detect ahead of time and many times they are undetectable.
Also, here's a good link that I used when I was trying to do the same thing here
NavigatorPlugins.mimeTypes
Take a peek at the MDN page
https://developer.mozilla.org/en-US/docs/Web/API/NavigatorPlugins.mimeTypes?redirectlocale=en-US&redirectslug=Web%2FAPI%2FNavigator.mimeTypes
Hope it helps
In JavaScript check to see if the zip field has been changed while it is hidden and show a warning to the user that an extension might be causing issues.
For Firefox you can do it with Mochitest/SpecialPowersAPI
https://developer.mozilla.org/en-US/docs/SpecialPowers

localstorage or sessionstorage can't persist data on cross browser

I am working on a small application but I am stuck on a problem. I want stored form element values on a HTML page when filled in on one browser(Ex. Firefox) and auto fill data when same page is loaded in another browser(Ex. Chrome). If anybody has any ideas please help me.
Unless clients can login and you're willing to share this data via your server, you can not change behavior of a different browser from your current, so in your example Firefox can not change a cookie, localstorage or whatever of Chrome. Browsers tend to only share information like cookies when they are first ran; such as with you the import wizard from Firefox.
I can think of two alternatives to achieve this:
An authentication system where the data is stored server-side.
Through custom browser extensions. You could create a custom browser extension that directly writes the data of the other browsers. This does require the user to install that extension though.
This link explain how to achieve that http://www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/
It's not simple, but it's the way that I know it can be done at the moment without the use of cookies.

Reverse engineering form submit

I'm using a hosted cart system to manage a ecommerce platform. The system uses form submission to add items to the user's cart. I want to write a javascript library to allow me to add things to the cart with JS, but I will need to see what the platform is submitting so I can copy it appropriately.
Any advice how to best sniff out what the default form info is getting submitted to the form so I can copy it via jquery?
Thanks!
Open your browser's console; Chrome has it built-in, Firefox has Firebug.
The entire request will be viewable in the network tab.
Another, more-complicated option is to set up a trivial local proxy and dump the request.
You can use TamperData. It's a nice addon for Firefox that let's you view and edit this data.
Firebug and it's derivatives also has the functionality if you have that.
Firebug on firefox using the console and turn on 'persist' it will tell you whats going on after the page posts and stuff. :)

Google Chrome Extension Persistence

My question is quite simple, i need to develop a Google Chrome Extension and by the way create dynamically HTML/CSS files. Basically i was thinking to do this with javascript but it's not possible for security reason. So i'm thinking about using directly Chrome API.
Is there a persistance API with chrome ?
Chrome Extensions use localStorage for data persistence. Check out http://diveintohtml5.ep.io/storage.html for a tutorial.
Note that only strings can be saved to localStorage. You'll need a JSON parser/stringifier if you want to load/save objects.
It is possible to do this with javascript. Chrome is very strict when it comes to calling scripts outside its domain(your extension folder I mean).
1. Make sure you are making js calls from your background page and not your content scripts.
2. If you are making js/ajax calls, note that chrome always sends an OPTIONS request. even for GET requests. So your server have to be able to grant permisions.
I hope these 2 points help your js. However, as everyone is saying, LocalStorage does a really good job.
I'm not completely sure of what you are asking but take a look at Local Storage
Hope it helps!

Categories

Resources