Use chrome.storage.session
, which is created for this exact purpose: to store variables in memory without persisting to the disk.
The API is the same as any other chrome.storage API, so the data must be JSON-compatible: string, number, boolean, null, array/object of these types.
The maximum capacity of the storage is currently 1MB.
async function foo() {
// reading
const foo = await chrome.storage.session.get('foo');
// writing
await chrome.storage.session.set({foo: 'bar'});
}
manifest.json:
"permissions": ["storage"]