storage.local.get returns array instead of object in Firefox <=51

RESOLVED WONTFIX

Status

Developer Documentation
Add-ons
P2
normal
RESOLVED WONTFIX
8 months ago
20 days ago

People

(Reporter: Geoffrey De Belie (Smile4ever), Unassigned)

Tracking

Details

Attachments

(1 attachment)

(Reporter)

Description

8 months ago
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0
Build ID: 20161213204721

Steps to reproduce:

https://github.com/Smile4ever/firefoxaddons/blob/f1ce137a8d7a3ceaf1a242e0c58abb1dd76b88de/Scrollkey-webext/scrollkey.js

Important parts from the code:

var getScrollValue = function(id) -> storage.local.get is called
var value = function(result) -> the result is processed. Note the if(isLowFirefoxVersion()) as a workaround for this (suspected) bug.



Actual results:

storage.local.get returns an array in Firefox <=51

[{
  "key": "value"
}]

In Firefox >=52 this works correctly and an object is returned (see below).


Expected results:

storage.local.get should return an object:

{
  "key": "value"
}
I just did a quick test on Firefox 50.1 and I do get an object back from storage.local.get. Can you create a reduced test case that reproduces this behaviour on Firefox < 52?
Flags: needinfo?(computergeoffrey)
(Reporter)

Comment 2

8 months ago
Created attachment 8823774 [details]
TestLocalStorage-source.zip

Test case. Output with Firefox 50.1.0:

Getting result..  testlocalstorage.js:16:2
An array  testlocalstorage.js:18:3
[{"scrollvalue":600}]  testlocalstorage.js:22:2

Source (zip also contains manifest):
var onSuccess = function(result){
	console.log("Getting result..");
	if(Array.isArray(result)){
		console.log("An array");
	}else{
		console.log("Not an array");
	}
	console.log(JSON.stringify(result));
}

var onError = function(result){
	
}

browser.storage.local.set({
	scrollvalue: 600
});
var getting1 = browser.storage.local.get("scrollvalue");
getting1.then(onSuccess, onError);
Flags: needinfo?(computergeoffrey)
It is reproducible when run from a content script, but not when run from a background script, and I can see that on Firefox 50.1 an array is returned while on 53 an object is returned, so this does look like a bug. I'll leave it to be triaged in case anyone else has any quick ideas about what the cause may be, and whether a fix needs to be uplifted. Thanks Geoffrey.
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 4

7 months ago
believe regression introduced and then fixed in 52.  Timing wise we won't be able to uplift into Beta before 51 goes to release.  Add to release notes.  Matt Wein will document
Status: NEW → RESOLVED
Last Resolved: 7 months ago
Flags: needinfo?(mwein)
Keywords: dev-doc-needed
Priority: -- → P2
Resolution: --- → WONTFIX

Comment 5

7 months ago
matt will write up docs to let folks know issue in 51.
Component: WebExtensions: Untriaged → Add-ons
Product: Toolkit → Developer Documentation

Comment 6

7 months ago
This is already documented in the warning box at https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/StorageArea/get.
Flags: needinfo?(mwein)

Comment 7

7 months ago
Thanks to Makyen for adding in the documentation
Keywords: dev-doc-needed
You need to log in before you can comment on or make changes to this bug.