"Mark as read" and "Mark all as read" fail if popup is closed (Firefox)
- Open popup with some unread items
- Click "Mark as read" or "Mark all as read" - popup will show the progress indicator
- Quickly close the popup by clicking outside of it
- Icon will show the old number; popup will show the same list of unread items
Firefox 54.0, Ubuntu Zesty
Hi @AlexNk
It seems like FF disposes feedIds and the function fails with can’t access dead object
https://github.com/olsh/Feedly-Notifier/blob/master/src/scripts/core.js#L787
The disposing of objects is a feature https://blog.mozilla.org/addons/2012/09/12/what-does-cant-access-dead-object-mean/
Simple array copying doesn't solve the problem.
Hi Oleg
I'm not familiar with WebExtensions API but is that possible to perform such operations not in context of popup?
Well, this is not webextension specific bug. The aggressive GC behaves the same for all types of FF add-ons. For now, I don't have a solution for the issue.
Sorry if my question is stupid but F.N. icon somehow performs requests to show the number of new feeds. Therefore there's an instance which isn't affected by this GC behavior and can safely perform "mark as read" requests.
Yes, of course, the addon works even if the popup is closed.
The problem is that the feedIds is created in the popup.js and passed to the core.js (background page).
Yes, you are right, now I understand the issue.
I tried to debug it on Firefox and found that copying the contents of the array helps in this case )I don't know if there's any API for cloning objects in JS, but this approach works for me):
function markAsRead(feedIds, callback) {
- let ids = []; for (let i = 0; i < feedIds.length; i++) ids.push(feedIds[i]);*
apiRequestWrapper("markers", {
body: {
action: "markAsRead",
type: "entries",
entryIds: ids
},
method: "POST"
}).then(function () {
-
}, function () { if (typeof callback === "function") { callback(false); } }); }for (let i = 0; i < ids.length; i++) {* removeFeedFromCache(ids[i]); } chrome.browserAction.getBadgeText({}, function (feedsCount) { feedsCount = +feedsCount; if (feedsCount > 0) { *feedsCount -= ids.length;* setBadgeCounter(feedsCount); } }); if (typeof callback === "function") { callback(true); }
With this change after execution of the call, "ids" with its content is still alive even when "callback" is dead.
Hi @AlexNk ,
Thanks for the investigation 👍
I used splice function for the array copying, and this didn't work. Will try your code.