How to use the webextension-polyfill.permissions 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 toggl / toggl-button / src / scripts / settings.js View on Github external
dom.innerHTML = `<strong>${k}</strong> - ${TogglOrigins[customs[k]].name}`;
          li.appendChild(dom);

          dom = document.createElement('a');
          dom.className = 'remove-custom';
          dom.textContent = 'delete';
          li.appendChild(dom);

          customHtml.appendChild(li);
        }
      }

      replaceContent('#custom-perm-container', customHtml);

      // Load permissions list
      browser.permissions.getAll().then(function (results) {
        let key;

        try {
          Settings.origins = [];
          origins = results.origins;
          for (i = 0; i &lt; origins.length; i++) {
            name = url = origins[i]
              .replace('*://*.', '')
              .replace('*://', '')
              .replace('/*', '');
            if (url.split('.').length &gt; 2) {
              name = url.substr(url.indexOf('.') + 1);
            }
            Settings.origins[name] = {
              id: i,
              origin: origins[i],
github toggl / toggl-button / src / scripts / settings.js View on Github external
toggleOrigin: function (e) {
    let target = e.target;

    if (e.target.tagName !== 'INPUT') {
      target = e.target.querySelector('input');
      if (!target) target = e.target.parentElement.querySelector('input');
      target.checked = !target.checked;
    }

    const permission = { origins: target.getAttribute('data-host').split(',') };

    if (target.checked) {
      browser.permissions.request(permission).then(function (result) {
        if (result) {
          target.parentNode.classList.remove('disabled');
        } else {
          target.checked = false;
        }
      });
    } else {
      browser.permissions.contains(permission).then(function (allowed) {
        if (allowed) {
          browser.permissions.remove(permission).then(function (result) {
            if (result) {
              target.parentNode.classList.add('disabled');
            } else {
              target.checked = true;
            }
          });
github Orogenesis / FireX-Proxy / vue / components / AddProxyComponent.vue View on Github external
requestPermissions() {
        if (navigator.userAgent.indexOf('Chrome') > -1) {
          browser.permissions.request(permissions).then(granted => {
            if (!granted) {
              return;
            }

            this.create();
          })
        } else {
          const width = 440;
          const height = 220;

          const left = Math.floor(screen.width / 2 - width / 2);
          const top = Math.floor(screen.height / 2 - height / 2);

          browser.windows.create({
            url: browser.extension.getURL("prompt.html"),
            type: 'popup',
github cnwangjie / better-onetab / src / common / utils.js View on Github external
export const checkPermission = async permission => {
  if (await browser.permissions.contains({permissions: [permission]})) return true
  return browser.permissions.request({permissions: [permission]})
}
export const readFile = file => new Promise((resolve, reject) => {
github cnwangjie / better-onetab / src / common / utils.js View on Github external
export const checkPermission = async permission => {
  if (await browser.permissions.contains({permissions: [permission]})) return true
  return browser.permissions.request({permissions: [permission]})
}
export const readFile = file => new Promise((resolve, reject) => {
github toggl / toggl-button / src / scripts / settings.js View on Github external
browser.permissions.contains(permission).then(function (allowed) {
        if (allowed) {
          browser.permissions.remove(permission).then(function (result) {
            if (result) {
              removed = true;
              db.removeOrigin(custom);
              parent.remove();
            } else {
              alert('Fail');
            }
          });
        } else {
          alert('No "' + custom + '" host permission found.');
        }
      });
github Orogenesis / FireX-Proxy / vue / components / AddProxyComponent.vue View on Github external
add() {
        if (!this.$refs.form.validate()) {
          return;
        }

        browser.permissions.contains(permissions).then(yes => {
          if (yes) {
            return this.create();
          }

          this.requestPermissions();
        })
      },
      async create() {
github toggl / toggl-button / src / scripts / settings.js View on Github external
removeCustomOrigin: function (e) {
    let custom;
    let domain;
    let permission;
    let parent;
    let removed = false;

    if (e.target.className === 'remove-custom') {
      parent = e.target.parentNode;
      custom = parent.querySelector('strong').textContent;
      domain = '*://' + custom + '/';
      permission = { origins: [domain] };

      browser.permissions.contains(permission).then(function (allowed) {
        if (allowed) {
          browser.permissions.remove(permission).then(function (result) {
            if (result) {
              removed = true;
              db.removeOrigin(custom);
              parent.remove();
            } else {
              alert('Fail');
            }
          });
        } else {
          alert('No "' + custom + '" host permission found.');
        }
      });

      if (!removed) {