How to use the webextension-polyfill.storage function in webextension-polyfill

To help you get started, we’ve selected a few webextension-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitcrowd / tickety-tick / src / web-extension / store.js View on Github external
import browser from 'webextension-polyfill';

// Store preferences in synced storage if available, use local as a fallback:
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/sync
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
export default browser.storage.sync || browser.storage.local;
github cliqz-oss / re-consent / src / background.js View on Github external
const url = new URL(message.url);
    const siteName = url.hostname.replace('www.', '');
    const { onboardingShown } = await browser.storage.local.get('onboardingShown');
    dispatch({ type: 'init', siteName, showOnboarding: !onboardingShown });
  } else if (message.type === 'detectFeatures') {
    detectFeatures(message.url, dispatch);
  } else if (message.type === 'detectConsent') {
    detectConsent(message.consent, tab, localStorage, dispatch);
  } else if (message.type === 'changeConsent') {
    changeConsent(message.consent, tab, localStorage, dispatch);
  } else if (message.type === 'setBrowserExtensionIcon') {
    setBrowserExtensionIcon(message.applicationState, tab.id);
  } else if (message.type === 'telemetry') {
    telemetry(message.actionKey, message.actionData);
  } else if (message.type === 'hideOnboarding') {
    browser.storage.local.set({
      onboardingShown: +new Date(),
    });
    dispatch({ type: 'hideOnboarding' });
  } else if (message.type === 'showPageAction') {
    browser.pageAction.show(tab.id);

    telemetry(TELEMETRY_ACTION.PAGE_ACTION_DISPLAYED, {
      site: new URL(tab.url).hostname,
      type: getConsentType(message.state),
    });
  }
});
github dessant / web-archives / src / storage / versions / local / SkhmnNhMG.js View on Github external
import browser from 'webextension-polyfill';

const message = 'Add installTime, searchCount and contribPageLastOpen';

const revision = 'SkhmnNhMG';
const downRevision = 'SJltHx2rW';

const storage = browser.storage.local;

async function upgrade() {
  const changes = {};
  changes.installTime = new Date().getTime();
  changes.searchCount = 0;
  changes.contribPageLastOpen = 0;

  changes.storageVersion = revision;
  return storage.set(changes);
}

async function downgrade() {
  const changes = {};
  await storage.remove(['installTime', 'searchCount', 'contribPageLastOpen']);

  changes.storageVersion = downRevision;
github cnwangjie / better-onetab / src / background / init.js View on Github external
const fixDirtyData = async () => {
  const unlock = await listManager.RWLock.lock()
  const {lists} = await browser.storage.local.get('lists')
  if (lists) {
    const cleanLists = lists.filter(_.isPlainObject).map(normalizeList)
    await browser.storage.local.set({lists: cleanLists})
  }
  await unlock()
}
github dessant / search-by-image / src / storage / versions / local / r1H3rgx1X.js View on Github external
import browser from 'webextension-polyfill';

const message = 'Add stock photo engines';

const revision = 'r1H3rgx1X';
const downRevision = 'r1Pvd36nz';

const storage = browser.storage.local;

async function upgrade() {
  const changes = {};

  const {engines, disabledEngines} = await storage.get([
    'engines',
    'disabledEngines'
  ]);
  const newEngines = [
    'getty',
    'istock',
    'shutterstock',
    'adobestock',
    'depositphotos'
  ];
github cliffordfajardo / cato / app / util.js View on Github external
utils.resetLocalStorageTheme = async () => {
  await browser.storage.sync.set({themeConfig: utils.defaultThemeConfig})
}
github solobat / Steward / extension / js / plugins / steward / newtab.js View on Github external
}).then(newList => {
        return browser.storage.local.set({
            [NOTES_KEY]: newList
        });
    });
}
github lusakasa / saka / src / saka / Main / index.jsx View on Github external
fetchSakaSettings = async function fetchSakaSettings() {
    const { sakaSettings } = await browser.storage.sync.get(['sakaSettings']);
    let { searchHistory } = await browser.storage.sync.get(['searchHistory']);
    searchHistory =
      searchHistory !== undefined && searchHistory.length > 0
        ? new Set(searchHistory)
        : new Set(['']);

    if (sakaSettings !== undefined) {
      const { mode, showEmptySearchSuggestions } = sakaSettings;
      return {
        isLoading: false,
        mode,
        showEmptySearchSuggestions,
        searchHistory
      };
    }
github mar-kolya / secure-password-generator / src / background.js View on Github external
case constants.INSERT_PASSWORD_MESSAGE:
	performAction(constants.INSERT_PREVIOUS_PASSWORD_MENU);
	break;
    case constants.GET_STATE_MESSAGE:
	response = Promise.resolve({
	    password: password,
	    settings: settings
	});
	break;
    case constants.SET_STATE_MESSAGE:
	settings = message.settings;
	password = message.password;
	break;
    case constants.SAVE_SETTINGS_MESSAGE:
	settings = message.settings;
	response = browser.storage.local.set({ [constants.SETTINGS_KEY]: settings });
	break;
    }
    return response;
});
github kumabook / stickynotes / src / utils / api.js View on Github external
function setUser(user) {
  return browser.storage.local.set({ user }).then(() => user);
}