這個非同步函式會回傳 Promise


let gettingItem =<storageType>.get(
  keys    // null, string, object or array of strings

<storageType> 會是以下可覆寫的儲存類型之一:storage.sync (en-US)storage.local



用來識別要檢查單元的 key(單個為字串;多個為陣列、或指定預設值的物件)。如果把這裡留空(空字串、空陣列、空物件都可以),就會取得空物件。如果是 null 或 undefined,則會取得所有儲存的內容。


Promise that will be fulfilled with a results object containing every object in keys that was found in the storage area. If the operation failed, the promise will be rejected with an error message.

警告: When used within a content script in Firefox versions prior to 52, the Promise returned by is fulfilled with an Array containing one Object. The Object in the Array contains the keys found in the storage area, as described above. The Promise is correctly fulfilled with an Object when used in the background context (background scripts, popups, options pages, etc.). When this API is used as, it correctly passes an Object to the callback function.


BCD tables only load in the browser



// 兩個單元:「kitten」與「monster」{
  kitten:  {name:"Mog", eats:"mice"},
  monster: {name:"Kraken", eats:"people"}

Define success and failure handlers for the promise:

function onGot(item) {

function onError(error) {
  console.log(`Error: ${error}`);

With no keys argument, retrieve everything:

let gettingItem =;
gettingItem.then(onGot, onError);

// -> Object { kitten: Object, monster: Object }

With an empty keys argument, return nothing:

// with an empty array, retrieve nothing
let gettingItem =[]);
gettingItem.then(onGot, onError);

// -> Object { }

With the name of an object, retrieve the match:

let gettingItem ="kitten");
gettingItem.then(onGot, onError);

// -> Object { kitten: Object }

With an array of object names, retrieve all matches:

let gettingItem =["kitten", "monster", "grapefruit"]);
gettingItem.then(onGot, onError);

// -> Object { kitten: Object, monster: Object }

With an object with object names as keys and the default value as value:

let gettingItem ={
  kitten: "no kitten",
  monster: "no monster",
  grapefruit: {
    name: "Grape Fruit",
    eats: "Water"

// -> Object { kitten: Object, monster: Object, grapefruit: Object }

Chrome 示例"kitten", function(items){
  console.log(items.kitten);  // -> {name:"Mog", eats:"mice"}

Or with an arrow function"kitten", items=>{
  console.log(items.kitten); // -> {name:"Mog", eats:"mice"}

備註: This API is based on Chromium's API. This documentation is derived from storage.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.