chrome.storage.sync doesn't sync between machines - javascript

I have a simple extensions that saves some data to chrome storage
var dt = new Date();
var item = {};
item[$('#qteSymb').text() + "-" + guid()] = $('#newnote').val() + "-:-" + $.datepicker.formatDate('mm/dd/yy', dt) + " " + dt.getHours() + ":" + (dt.getMinutes() < 10 ? "0" + dt.getMinutes() : dt.getMinutes());
chrome.storage.sync.set(item, function(){
renderNotes();
});
This works fine locally - my extension is working as intended - but it doesn't sync back to another computer. I am assuming the sync is ON on both computers because the bookmarks, extensions, etc. sync just fine.
Thank you!

So I finally figured this out.
When not using Chrome Web Store your manifest file should include a key (https://developer.chrome.com/extensions/manifest.html#key)
...
"key":"myawesomeextension"
...
Without this every time you install the extension on a different device (through chrome://extensions/ --> Load unpacked extension) it gets a new id and therefore the data being synced doesn't get matched to the correct extension - same extension with different ids = two different extensions in the eyes of Chrome.
There is no need for a key once the extension is in Chrome Web Store. Hope this helps somebody keep some hair at some point.

Related

How can I stop IE 11/Win7 from removing ".exe" from downloade files?

I have an application which I have created an installer for. I have signed the application with a certificate. With every browser/windows combination I have tried downloading the installer works fine, except Windows 7 IE 11.
This combination strips the .exe off of the file. If I add the .exe back, the installer works fine. The file resides on the web server and I cause the download using the following JS;
function processDownload(inInstalLink, ApplicationName)
{
if (confirm("Download "+ ApplicationName + " application?"))
{
var intRandom = Math.floor((Math.random() * 10000) + 1);
window.location = inInstalLink + "?tempID=" + intRandom; //Launch alternative, typically app download.
}
}
I call the javascript above as follows;
processDownload("MyInstaller.exe", "My Fun Application")
I have read about content disposition tags, but am at a loss on how to implement them here, and not sure if they would solve the problem. Any guidance is appreciated.
This seems to be a common problem in Windows 7 IE 11 with exe downloads without a content disposition.
One solution that others have tried and had success with is appending ‘.exe’ to the url.
window.location = inInstalLink + "?tempID=" + intRandom + ".exe"
With dealing with IE compatibility, sometimes solutions aren’t as intuitive or logical as we would like them to be.

Javascript/Rails Cookie not saving on safari but works on chrome

I am developing a rails app (I am a student) and I am trying to make a cookie that stores the users location which is found through the javascript geo location api. However, the cookie works perfectly in chrome but not safari or Firefox. I looked in the inspector and the cookie was there for chrome but not the other two. The code for the cookie is below. The rest of the code is written in ruby. The point of the cookie is so that I can get the users recent location in the controller.
<%if #lat_lng.nil? %>
<script>
getGeoLocation();
function getGeoLocation() {
navigator.geolocation.getCurrentPosition(setGeoCookie);
}
function setGeoCookie(position) {
var expiration = new Date();
expiration.setDate(expiration.getDate()+1);
var cookie_val = position.coords.latitude + "|" + position.coords.longitude;
document.cookie = "lat_lng=" + escape(cookie_val); expires= 'expiration.toGMTString()';
}
</script>
<% end %>
The cookie is defined in my applications controller:
#lat_lng = cookies[:lat_lng]
I really appreciate any help that is possible!
When you are setting the cookie, it should be in the following format:
document.cookie = "some=value; expires=Mon, 1 Jan 2000 12:59:59 GMT";
In your case, you are simply defining a variable in javascript. Try changing it to:
document.cookie = "lat_lng=" + escape(cookie_val) + "; expires=" + expiration.toGMTString();
PS. However, the expires part is optional and should work without it just fine. Maybe, Safari and FF require it for security reasons? Try googling that.

StaticMaps working when using wifi, but not working when using cellular data

I build website to get location(geolocation).
It works fine when I'm using wifi data, but its not working properly when Im using cellular data. It gives me blank image.
Any suggestion?
Here is my code:
function jsfGetLocation()
{
if ( navigator.geolocation ) { navigator.geolocation.getCurrentPosition(jsfShowPosition,jsfShowError); }
else { document.getElementById("DivMap").innerHTML = "Geolocation is not supported by this browser."; };
};
function jsfShowPosition(position)
{
var MapWidth = document.getElementById("Div").offsetWidth - 2;
var LttLng = position.coords.latitude + "," + position.coords.longitude;
var StrImgURL = "https://maps.googleapis.com/maps/api/staticmap?key=[MyKey]&center=" + LttLng + "&zoom=14&size=" + MapWidth + "x300&sensor=true&markers=color:red%7C" + LttLng;
document.getElementById("Div").innerHTML = "<img src='" + StrImgURL + "'>";
document.getElementById("ToolBarLt").textContent = position.coords.latitude;
document.getElementById("ToolBarLn").textContent = position.coords.longitude;
};
But I don't think that its about script error. I think its because of privilege data use on chrome or the iPhone.
You can check on this forum. This might be also because of issues with the services. This happens usually on older iPhones who have upgraded from iOS 8 to iOS 9. You can also read this thread with some troubleshooting tips about this issue. You can update iOS to the newest version and/or resetting the device network settings and then reboot the device. Hope this helps!
maybe u should change another device, try. So that we can find out what is the problem

How can I store persistent data with JS/JQuery using the file:/// protocol and IE/Edge browser?

I'm currently writing a small web page application where users can dynamically drag and drop links to files and pages on a customisable homepage.
It is written in Html5 and Javascript/Jquery mobile. The page will be stored on the local machine and accessed with the 'file:///' protocol, using the Internet Explorer / Microsoft Edge webbrowser.
I'm trying to find a way to store the data that resembles the customized page and links, so that when the user opens the page again the links will still be there and can be edited and customized further.
So far I've been looking into HTML localStorage, but this doesn't work with IE/Edge through the 'file:///' protocol, the page will not be hosted.
I was thinking of just creating a file with all the data in there, but I don't believe that is possible either due to security reasons.
I have not alot of experience with javascript, so any help is appreciated!
If you only want it to work on Internet Explorer/Microsoft Edge, a simple way to persist data would be using cookies. They will work even using the file:// protocol, and the only thing would be setting a far away expiration date (in the example below: 2/2/2222).
Try this sample code (part of it comes from this site) that will count the number of times a page has been loaded. Notice how the counter is kept even after closing the browser and reopening it:
<!doctype html>
<html>
<head>
<title>Persistent Data With Cookies In IE</title>
</head>
<body>
Number of reloads: <span id="num">-</span>
<script>
function setCookie(name, value)
{
var expiry = new Date(2222,2,2);
document.cookie = name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}
function getCookie(name)
{
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}
var cookieVal = getCookie("num");
var num = cookieVal != null ? cookieVal : 0;
document.getElementById("num").innerHTML = num;
setCookie("num", parseInt(num) + 1)
</script>
</body>
</html>
Pros of this solution:
Simple and easy to implement.
Works with the file:// protocol in IE and Edge (as specified in question) and also in Firefox.
Cons of this solution:
Limited storage space.
Doesn't work with the file:// protocol in Chrome (not required in question).

chrome.management.getAll does not return Chrome Store's app data

I am now writing a new tab page replacement for Chrome 33.
While I am using chrome.management.getAll() to get app list, I found a strange thing.
Here is my code:
document.addEventListener('DOMContentLoaded', function () {
...
chrome.management.getAll(getAllApps);
...});
function getAllApps(data) {
...
console.log("Installed App Count:" + data.length);
for (var i = data.length - 1; i >= 0; i--) {
console.log("Found App: " + data[i].name + " type:" + data[i].type);
if (data[i].type == 'theme' ||
data[i].type == 'extension' ) {
continue;
};
...
}
}
The output never lists Chrome Store.
But if I use chrome.management.get(), I could get the record of Chrome Store by its id.
Is there anything wrong in my code? Or is the Store is intended to be hidden?
Thank you. It is my first question here, so if there is any inappropriate words in my question, please forgive me.
The Store app is a component extension. Those extensions are built in to Chrome, not installed. As you can see from the documentation, getAll() returns only the user's installed extensions.
Your best bet is to hardcode the list of extensions that appear in a brand-new profile, which will consist only of component items (unless you're on a machine you don't control). Over time that list will diverge from the canonical list in the source code.
Both chrome.management.get() and chrome.management.getAll() show information about apps/extensions/themes installed on local computer, not information from Chrome Web Store.

Categories

Resources