How to use the webextension-polyfill.commands 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 samueljun / tomato-clock / src / background / timer.js View on Github external
case RUNTIME_ACTION.SET_TIMER:
          this.setTimer(request.data.type);
          break;
        case RUNTIME_ACTION.GET_TIMER_SCHEDULED_TIME:
          // Hack because of difference in chrome and firefox
          // Check if polyfill fixes the issue
          if (sendResponse) {
            sendResponse(this.getTimerScheduledTime());
          }
          return this.getTimerScheduledTime();
        default:
          break;
      }
    });

    browser.commands.onCommand.addListener(command => {
      switch (command) {
        case "start-tomato":
          this.setTimer(TIMER_TYPE.TOMATO);
          break;
        case "start-short-break":
          this.setTimer(TIMER_TYPE.SHORT_BREAK);
          break;
        case "start-long-break":
          this.setTimer(TIMER_TYPE.LONG_BREAK);
          break;
        case "reset-timer":
          this.resetTimer();
          break;
        default:
          break;
      }
github mar-kolya / secure-password-generator / src / background.js View on Github external
browser.tabs
	    .executeScript({
		code: "document.activeElement.value = " + JSON.stringify(password)
	    })
	    .catch((error) => {
		console.error("Failed to set password: ", error);
	    });
	break;
    }
}

browser.contextMenus.onClicked.addListener((info, tab) => {
    performAction(info.menuItemId);
});

browser.commands.onCommand.addListener(function(command) {
    performAction(command);
});

browser.runtime.onMessage.addListener((message, sender) => {
    let response = undefined;
    switch (message.message) {
    case constants.GENERATE_PASSWORD_MESSAGE:
	password = createPassword(settings);
	response = Promise.resolve({
	    password: password
	});
	break;
    case constants.INSERT_PASSWORD_MESSAGE:
	performAction(constants.INSERT_PREVIOUS_PASSWORD_MENU);
	break;
    case constants.GET_STATE_MESSAGE:
github sienori / Tab-Session-Manager / src / options / components / KeyboardShortcutsPage.js View on Github external
async initCommands() {
    const commands = await browser.commands.getAll();
    const rawDescription = /^__MSG_(.*)__$/;
    const convertedCommands = commands.map(command => {
      const isRawDescription = rawDescription.test(command.description);
      if (isRawDescription)
        command.description = browser.i18n.getMessage(command.description.match(rawDescription)[1]);
      return command;
    });

    this.setState({ commands: convertedCommands, isInit: true });
  }
github lusakasa / saka / src / background_page / index.js View on Github external
runAt: 'document_start',
        matchAboutBlank: true
      });
    }
  }
}

async function saveSettings(searchHistory) {
  await browser.storage.sync.set({ searchHistory: [...searchHistory] });
}

browser.browserAction.onClicked.addListener(() => {
  toggleSaka();
});

browser.commands.onCommand.addListener(command => {
  switch (command) {
    case 'toggleSaka':
    case 'toggleSaka2':
    case 'toggleSaka3':
    case 'toggleSaka4':
      toggleSaka();
      break;
    default:
      console.error(`Unknown command: '${command}'`);
  }
});

browser.runtime.onMessage.addListener(async (message, sender) => {
  switch (message.key) {
    case 'toggleSaka':
      toggleSaka();
github cnwangjie / better-onetab / src / background.js View on Github external
if (msg.storeInto) {
      tabs.storeSelectedTabs(msg.storeInto.index)
    }
    if (msg.login) {
      boss.login(msg.login.token)
    }
    if (msg.refresh) {
      boss.refresh()
    }
    if (msg.import) {
      const {lists} = msg.import
      lists.forEach(list => listManager.addList(list))
    }
  })
  browser.runtime.onMessageExternal.addListener(commandHandler)
  browser.commands.onCommand.addListener(commandHandler)
  browser.runtime.onUpdateAvailable.addListener(detail => {
    window.update = detail.version
  })
  browser.runtime.onInstalled.addListener(detail => {
    if (DEBUG) return
    if (detail.reason === chrome.runtime.OnInstalledReason.UPDATE) {
      const updatedNotificationId = 'updated'
      browser.notifications.onClicked.addListener(id => {
        if (id === updatedNotificationId) {
          browser.tabs.create({ url: 'https://github.com/cnwangjie/better-onetab/blob/master/CHANGELOG.md' })
        }
      })
      browser.notifications.create(updatedNotificationId, {
        type: 'basic',
        iconUrl: 'assets/icons/icon_128.png',
        title: __('ui_updated_to_ver') + ' v' + browser.runtime.getManifest().version,
github kumabook / bebop / src / background.js View on Github external
popupPorts         = {};

  await loadOptions();
  try {
    await idb.upgrade(config.dbName, config.dbVersion, db => createObjectStore(db));
    logger.info('create indexedDB');
  } catch (e) {
    logger.info(e);
  }

  browser.windows.onFocusChanged.addListener(onWindowFocusChanged);
  browser.runtime.onConnect.addListener(connectListener);
  browser.tabs.onActivated.addListener(activatedListener);
  browser.tabs.onRemoved.addListener(onTabRemoved);
  browser.runtime.onMessage.addListener(messageListener);
  browser.commands.onCommand.addListener(commandListener);
  browser.storage.onChanged.addListener(storageChangedListener);

  logger.info('bebop is initialized.');
}
github glacambre / firenvim / src / background.ts View on Github external
return fn(sender, request.args !== undefined ? request.args : []);
});

browser.tabs.onActivated.addListener(({ tabId }: { tabId: number }) => {
    updateIcon(tabId);
});
browser.windows.onFocusChanged.addListener(async (windowId: number) => {
    const tabs = await browser.tabs.query({ active: true, windowId });
    if (tabs.length >= 1) {
        updateIcon(tabs[0].id);
    }
});

updateIcon();

browser.commands.onCommand.addListener(async (command: string) => {
    switch (command) {
        case "nvimify":
            const id = (await browser.tabs.query({ active: true, currentWindow: true }))[0].id;
            browser.tabs.sendMessage(id, { args: [], funcName: ["forceNvimify"] });
            break;
        case "toggle_firenvim":
            await toggleDisabled();
            break;
    }
});
github sienori / Tab-Session-Manager / src / options / components / KeyboardShortcutForm.js View on Github external
async updateShortcut(shortcut) {
    try {
      await browser.commands.update({ name: this.props.id, shortcut: shortcut });
      this.setState({ shortcut: shortcut || "" });
    } catch (e) {
      this.setState({ error: browser.i18n.getMessage("invalidShortcutMessage") });
    }
  }
github sienori / Tab-Session-Manager / src / background / background.js View on Github external
case "removeTag":
      removeTag(request.id, request.tag);
      break;
    case "getInitState":
      return IsInit;
    case "getCurrentSession":
      const currentSession = await loadCurrentSession("", [], request.property).catch(() => {});
      return currentSession;
  }
};

browser.runtime.onStartup.addListener(onStartupListener);
browser.runtime.onInstalled.addListener(init);
browser.runtime.onInstalled.addListener(onInstalledListener);
browser.runtime.onMessage.addListener(onMessageListener);
browser.commands.onCommand.addListener(onCommandListener);