IndexedDB onversionchange event not fired in Chrome - html

I'm playing with the IndexedDB API from html5 spec in both Firefox and Chrome.
There something that's not working as expected I and want to share it here because I don't know if it's my fault or a browser bug.
According to the API, there's an event called onversionchange that's fired when you open a connection to a local database and the version number used is greater than the databases one.
My problem is that this event is being fired in Firefox but not in Chrome.
Some sample code trying several modes:
var db;
var DB_VERSION = 5;
var openRequest = indexedDB.open("test_db", DB_VERSION);
openRequest.onsuccess = function(event) {
db = openRequest.result;
};
openRequest.onversionchange = function(event) {
console.log("This is the place where I can change db structure");
};
openRequest.onupgradeneeded = function(event) {
console.log("This is the place where I can change db structure");
};
onversionchage event is not being fired even when I change the version number.
UPDATE
As ebidel has answered, Chrome implementation does not follow the currently specification so, in order to have a cross browser client code, we need to handle two situations: onversionchange event and database.version manual comparison.
Here are a couple on links with code example:
Chromium google group and
HTML5 Rocks!

Chrome's IndexedDB implementation is based off an older version of the spec which uses the older setVersion call rather than onversionchange/onupgradeneeded. Please star this issue: http://crbug.com/108223

Related

welcome page loads when Allow in incognito is checked/unchecked in Chrome

I am new to chrome extensions.I used chrome.runtime.onInstalled to load a html page whenever the extension is installed or updated.But when i am testing it in chrome, whenever i check/uncheck Allow in incognito the same html page loads each time.How to avoid this behaviour? I used "incognito":"split" in manifest.
I wish you'd posted the code so I could try to replicate the problem and give a specific solution but the easy solution is to use chrome storage API to save the extension's version when welcome.html is opened and compare it to the current version next time onInstalled is fired.
If the stored version is the same don't open it. If it's undefined or older, open it.
Get your extension's version by extracting it from chrome.extension.getURL("manifest.json")
Edit:
After a bit of googling it seems you can access the manifest more directly. Get the version number using the code below.
var version = chrome.runtime.getManifest().version;
Edit:
It seems the previous version is supplied in the callback when you update so you don't need to store anything. The object provided can be compared to the current version using chrome.runtime.getManifest().version
Something like this:
chrome.runtime.onInstalled.addListener(function (details) {
if(details.reason === "install"){
chrome.tabs.create({url: "welcome.html"});
}
else if(details.reason === "update"){
var currentVersion = chrome.runtime.getManifest().version;
var previousVersion = details.previousVersion;
if(previousVersion !== currentVersion){
chrome.tabs.create({url: "welcome.html"});
}
}
});
I don't think you can. I assume that when you uncheck "Allow in incognito", Chrome nukes the local state of the (split) incognito instance.

Chromecast event for device disconnect (sender)

Is there event that will notify a sender app when the use selects "stop cast" from within the chrome extension?
I've a chrome sender app get's in a limbo state if the user chooses to stop the cast from the extension instead of the app cast button.
EDIT:
This is some relevant code:
CastPlayer.prototype.onMediaDiscovered = function (how, mediaSession) {
this.currentMediaSession = mediaSession;
// ...
this.currentMediaSession.addUpdateListener(this.onMediaStatusUpdate.bind(this));
// ...
};
CastPlayer.prototype.onMediaStatusUpdate = function (e) {
console.log(e);
};
Have you tried Session.addUpdateListener(listener) ? I think the listener will be notified when the session is no longer alive.
It seems Google developers are pretty aware of that! :D
They've just update their senders sample code with a commit that is exactly what seems you're looking for: Added session update listener to handle disconnect by clicking cast extension
There's also another commit with the same text in another sample but with less code, here you have: https://github.com/googlecast/CastHelloVideo-chrome/commit/776559c9aaf16d7d82c62ee4dea611b6177ac217

How to get appWindow from Chrome.app.window.create

I am trying to write a chrome.app that is able to open and close chrome.app windows on both displays of a system that is configured with two monitors. When launched, the chrome application establishes a socket connection with a native application running on the same computer, I also open a hidden window via chrome.app.window.create to keep the chrome application up and running. The native application then reads a configuration file and then sends a series of ‘openBrowser’ commands to the chrome application via the socket.
When the chrome application receives an ‘openBrowser’ command, the chrome application makes a call to the chrome API method chrome.app.window.create, passing the create parameters AND a callback function. A code snippet is below:
NPMBrowserManager.prototype.openBrowser = function (browserId,htmlFile,browserBounds,hidden,grabFocus)
{
var browserManager = this;
var createParameters = {};
createParameters.bounds = browserBounds;
createParameters.hidden = hidden;
chrome.app.window.create(htmlFile,createParameters,function(appWindow)
{
// Check to see if I got a non-undefined appWindow.
if(appWindow !== null)
{
browserManager.browsers.push({"browserId":browserId,"window":appWindow});
console.info("NPMBrowserManager.openBrowser: Added browser, id =" + browserId + ", count =" + browserManager.browsers.length);
}
});
}
Unfortunately, the ‘appWindow’, parameter passed in the create callback is always undefined. I suspect it has something to do with the fact that the method openBrowser is itself being called by another method that processes commands received from the native application. However, the window opens exactly here and when I want to to, I just can’t seem to cache away any information about the new window that can be used later to close or move the window.
I want to be able to cache away the appWindow so that I can close or modify the created window later on in the workflow.
As a side note, I’ve noticed that appWindow is NOT undefined if I call the openBrowser method from within the callback that is associated with the chrome.app.runtime.onLaunched event. I suspect it has something to do with the current script context. I was not able to find any chrome.app documentation that goes into any detail about the chrome app architecture.
I would GREATLY appreciate it if anyone out there can explain to me how I can get the appWindow of the window that is created in the chrome.app.window.create method. By the way, I have also tried calling chrome.app.window.current to no avail… Very frustrating!!!
I’d also be interested in any documentation that might exist. I am aware of developer.chrome.com, but could not find much documentation other than reference documentation.
Thanks for the help!
Jim

chrome.app.getDetails() returns null

I was trying to get the version of my extension at run-time using chrome.app.getDetails().version and noticed that chrome.app.getDetails() returns null. Surprisingly, there is no talk about this in the online community and the function isn't even documented by the Google folks. Is there a permission I am missing? I do have tabs enabled.
Very old... I know
But in case if someone is looking for this, you can have your extension version reading the manifest file with chrome.runtime API and the getManifest Method.
Ex. in your background script:
var manifest = chrome.runtime.getManifest();
var current_version = manifest.version;
console.info('Current Version: ', current_version);
The object returned is a serialization of the full manifest file, so you can get all the info in the manifest file
So.. if you want for example all and only the matches of your content_scripts... for say something...
for(var i in manifest.content_scripts) {
console.log(manifest.content_scripts[i]['matches']));
}
Note: Stable since Chrome 22
It's undocumented because they might be moving getDetails to a different part of the API -- see this bug. It's currently working on my copy of Chrome (beta channel), but I wouldn't be surprised if they've disabled it in a newer release. In the meantime you can just do an AJAX query to get the manifest.json of your extension -- you can get its URI using chrome.extension.getURL("manifest.json").
Here is what I'm using to pull the current version.
var manifest = new XMLHttpRequest();
manifest.open("get", "/manifest.json", true);
manifest.onreadystatechange = function (e) { if (manifest.readyState == 4) {console.log(JSON.parse(manifest.responseText).version)} };
manifest.send({});

window.applicationCache

Using HTML5 manifest file and cache is working fine.
I use window.applicationCache.update() to download the updated version. works fine.
How can I check to see if the manifest file has been updated so an update is available but not start downloading. Reason for this I want the user to allow the update or not as they may be in a bad network connection area.
Try this:
// Check if a new cache is available on page load.
window.addEventListener('load', function(e) {
window.applicationCache.addEventListener('ondownloading', function(e) {
window.applicationCache.abort();
}, false);
}, false);
Just abort the download when you catch the ondownloading event.
You can see all the available events here
There is not an event like that.
Browser checks the update of the manifest file and download the new added files automatically. You can check current state of the cache using its status property. It may have six different values. You can see the available status properties here. Then you can use applicationCache.swapCache() for swapping according to Your/User need.