Closed Bug 1645598 Opened 4 years ago Closed 4 years ago

storage.sync.get does not return default values any more when the new storage.sync implementation is enabled

Categories

(WebExtensions :: Storage, defect)

defect

Tracking

(firefox-esr68 unaffected, firefox-esr78 fixed, firefox77 unaffected, firefox78 fixed, firefox79 fixed)

RESOLVED FIXED
mozilla79
Tracking Status
firefox-esr68 --- unaffected
firefox-esr78 --- fixed
firefox77 --- unaffected
firefox78 --- fixed
firefox79 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Regression, )

Details

(Keywords: regression)

Attachments

(2 files, 2 obsolete files)

The storage.{sync,local,managed}.get APIs are supposed to retrieve a value from storage, and default to the input parameters if the value is not found. This has always worked, but when the new sync storage backend was enabled (bug 1634615), this started to break. Now undefined is returned instead of the actual storage.

STR:

  1. Run the following from the console of any extension that uses the storage API:
(await browser.storage.sync.get({ abcdef: 123456 }) ).abcdef

Expected:

  • 123456, because the storage does not contain the key and should default to the input value for the given key.

Actual:

  • undefined, meaning that the storage.sync.get API ignored the input.

I discovered this bug because a user reported broken functionality in one of my add-ons at https://github.com/Rob--W/crxviewer/issues/93

The behavior of storage.get with an object parameter was documented in the Parameters section of the extension API documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get#Syntax

A key (string) or keys (an array of strings, or an object specifying default values) to identify the item(s) to be retrieved from storage.

But it is easy to overlook those three words, so I expanded the article on MDN: https://wiki.developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/StorageArea/get$compare?locale=en-US&to=1628409&from=1603555

Assignee: nobody → rob
Status: NEW → ASSIGNED

The crate seems to be born at https://github.com/mozilla/application-services/tree/54875c00ce464748c7747683d7dc5ba1d1c8bb92/components/webext-storage,
and vendored in the tree at https://searchfox.org/mozilla-central/rev/0e09b9191c02097034e46b193930f91c45b7885d/third_party/rust/webext-storage/Cargo.toml

It is not obvious which repository is canonical, but since I'm not seeing the crate on crates.io and this bug is an actual regression that impacts users, I'm going to submit the patch against m-c.

Ouch, thank you for catching that!

The canonical repo is https://github.com/mozilla/application-services/tree/master/components/webext-storage. Would you mind making your PR on GitHub, against the vendor-mc/78 branch? (We're using that branch to minimize churn, and to make uplifts easier).

We can merge your PR ASAP, and then use this bug to bump the rev and re-vendor.

Thank you!

Flags: needinfo?(rob)

Here is the PR: https://github.com/mozilla/application-services/pull/3235

I will attach a regression test and the vendor version bump to this bug.

To test the changes, I modified m-c's top-level Cargo.toml and referred to the location of my cloned/forked application-services repository, as follows:

[patch.'https://github.com/mozilla/application-services']
fxa-client = { path = "../../repositories/application-services/components/fxa-client" }
viaduct = { path = "../../repositories/application-services/components/viaduct" }
sync15-traits = { path = "../../repositories/application-services/components/support/sync15-traits" }
interrupt-support = { path = "../../repositories/application-services/components/support/interrupt" }
sql-support = { path = "../../repositories/application-services/components/support/sql" }
webext-storage = { path = "../../repositories/application-services/components/webext-storage" }

The lookup and listing of unrelated crates is not ideal, but without it the code wouldn't compile or symbols could not be linked.

To get this fix: https://github.com/mozilla/application-services/pull/3235

Updated as follows:

sed -i 's/e8d7530319fa6c20d9de78d031c9398630eca3cd/61dcc364ac0d6d0816ab88a494bbf20d824b009b/g' services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml services/sync/golden_gate/Cargo.toml toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml toolkit/components/glean/Cargo.toml toolkit/library/rust/shared/Cargo.toml
./mach vendor rust

Verified by running the new regression test that I added in the bug:

 ./mach test toolkit/components/extensions/test/mochitest/test_ext_storage_smoke_test.html --tag=remote-webextensions

Wow, thanks for being all over this!

Pushed by rob@robwu.nl:
https://hg.mozilla.org/integration/autoland/rev/424c361f3d54
Add unit test for storageArea.get with defaults r=rpl
https://hg.mozilla.org/integration/autoland/rev/88e7bf87b79d
Vendor application-services for fix in webext-storage r=lina
Pushed by malexandru@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0613bb2a6a94
Fix lint error on head_storage.js a=lint-fix
Attachment #9156705 - Attachment is obsolete: true

Comment on attachment 9156607 [details]
Bug 1645598 - Vendor application-services for fix in webext-storage

Beta/Release Uplift Approval Request

  • User impact if declined: See comment 0. Extensions that rely on storage.sync.get to return default values if no data is stored locally—if the extension has just been installed, for example, or cleared its data—will break if the new Rust backend is enabled. Rob's extension is an example.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Includes test coverage upstream and an xpcshell test for Firefox. The new Rust backend is also disabled by default, but we'd like to keep our options open to enable it via a pref later.
  • String changes made/needed: None
Attachment #9156607 - Flags: approval-mozilla-beta?
Attachment #9156579 - Flags: approval-mozilla-beta?

Thanks Lina for writing the uplift request.

This follow-up linting fix should also be uplifted: https://hg.mozilla.org/mozilla-central/rev/0613bb2a6a94 (from comment 10).

Comment on attachment 9156607 [details]
Bug 1645598 - Vendor application-services for fix in webext-storage

approved for 78.0b8

Attachment #9156607 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9156579 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Comment on attachment 9157058 [details] [diff] [review]
vendor-beta.patch

Talked to :jcristau and we'll just uplift bug 1629127 directly.
Attachment #9157058 - Attachment is obsolete: true
Attachment #9157058 - Flags: approval-mozilla-beta?
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: