files/en-us/web/api/contentindex/getall/index.md
{{APIRef("Content Index API")}}{{SeeCompatTable}}{{AvailableInWorkers}}
The getAll() method of the
{{domxref("ContentIndex")}} interface returns a {{jsxref('Promise')}} that resolves with
an iterable list of content index entries.
getAll()
None.
Returns a {{jsxref("Promise")}} that resolves with an {{jsxref('Array')}} of
contentDescription items.
contentDescription
id
title
description
url
category {{Optional_Inline}}
'' An empty {{jsxref('String')}}, this is the default.homepagearticlevideoaudioicons {{Optional_Inline}}
src
sizes {{Optional_Inline}}
type {{Optional_Inline}}
label {{Optional_Inline}}
No exceptions are thrown. If there are no items in the Content Index, an empty {{jsxref('Array')}} is returned.
The below example shows an asynchronous function that retrieves items within the content index and iterates over each entry, building a list for the interface.
async function createReadingList() {
// access our service worker registration
const registration = await navigator.serviceWorker.ready;
// get our index entries
const entries = await registration.index.getAll();
// create a containing element
const readingListElem = document.createElement("div");
// test for entries
if (entries.length === 0) {
// if there are no entries, display a message
const message = document.createElement("p");
message.innerText =
"You currently have no articles saved for offline reading.";
readingListElem.append(message);
} else {
// if entries are present, display in a list of links to the content
const listElem = document.createElement("ul");
for (const entry of entries) {
const listItem = document.createElement("li");
const anchorElem = document.createElement("a");
anchorElem.innerText = entry.title;
anchorElem.setAttribute("href", entry.url);
listElem.append(listItem);
}
readingListElem.append(listElem);
}
}
{{Specifications}}
{{Compat}}