Reputation: 4972
I have an extension that I recently pushed an update for with updated permissions. Some users are upgrading and reporting that the app doesn't work after the update, in order to make it work again they are having to completely uninstall the app and re-install and everything works as it should.
Has anyone ever had a similar issue? For me in testing everything updated properly, and not everyone is having this issue but it is becoming an issue.
Something to note - the popup tab does work it's just the context menu that has the issue.
EDIT - I am unable to replicate and have no clear way to test this beyond getting reports from users. I did notice a drop in reports after deploying another update where I adjusted the order of the permissions... I don't see how this is at all related but I am looking for any clarity as to why this is happening and if there is something that can be done to avoid it in the future.
Upvotes: 3
Views: 1863
Reputation: 349262
You're creating context menu items in a listener for the chrome.runtime.onInstalled
event. This is the documented and recommended way to create context menu items, but it is not always triggered due to bugs in Chrome (crbug.com/388231, crbug.com/389631, crbug.com/264963).
I guess that in your case the permission update caused the extension to be disabled, and then chrome.runtime.onInstalled
was not triggered any more after re-enabling it because of crbug.com/388231.
A work-around for this bug is to use a short timer and try to update the context menu item that should have been created. If the onInstalled event is not triggered, then the context menu is not created and trying to update it will fail. This condition can then be used to ensure that the context menu is created correctly.
var SOME_CONTEXTMENU_ID = "GifMeContextMenu";
function onInstalled() {
// ... do your thing, e.g. creating a context menu item:
chrome.contextMenus.create({
"title": "GifMe",
"contexts": ["image"],
"id": SOME_CONTEXTMENU_ID
});
}
// Should be triggered whenever the extension or browser is
// reloaded, installed or updated.
chrome.runtime.onInstalled.addListener(onInstalled);
setTimeout(function() {
// This .update() call does not change the context menu if it exists,
// but sets chrome.runtime.lastError if the menu does not exist.
chrome.contextMenus.update(SOME_CONTEXTMENU_ID, {}, function() {
if (chrome.runtime.lastError) {
// Assume that crbug.com/388231 occured, manually call the
// onInstalled handler.
onInstalled();
}
});
}, 222); // <-- Some short timeout.
Upvotes: 5