SafariExtensions
SafariExtensions copied to clipboard
FB11426949 - Web Extension storage callbacks in the wrong order
In a Safari web extension on both macOS 12 and iOS 15 (I filed this bug under Mac because there was no cross-platform category), if you call storage.local.set and then storage.local.get, the callbacks are called in the opposite order, and indeed the opposite order from Chrome and Firefox extensions. Attached is a sample Xcode project demonstrating the bug. Just build and run the extension in Safari, and open the web inspector console.
Expected results:
[Log] first (content.js, line 6)
[Log] second – "bar" (content.js, line 9)
Actual results:
[Log] second – undefined (content.js, line 9)
[Log] first (content.js, line 6)
As you can see, the wrong callback order results in undefined rather than the expected result, which is bad. You can use the same sample web extension in Safari, Chrome, and Firefox to compare results. If you look at the online documentation for the extension storage API from Mozilla and Google, you can see that their examples depend on the callbacks occurring in the right order. StorageArea.set()
browser.storage.local.set({kitten, monster}) .then(setItem, onError);
browser.storage.local.get("kitten") .then(gotKitten, onError);
browser.storage.local.get("monster") .then(gotMonster, onError);
chrome.storage.local.set({key: value}, function() { console.log('Value is set to ' + value); });
chrome.storage.local.get(['key'], function(result) { console.log('Value currently is ' + result.key); });
Apple's response:
Resolution:Investigation complete - Works as currently designed