How to use the webextension-polyfill.runtime 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 glacambre / firenvim / src / NeovimFrame.ts View on Github external
const [major, minor, patch] = extInfo.version.split(".");
        nvim.set_client_info(extInfo.name,
            { major, minor, patch },
            "ui",
            {},
            {},
        );

        await confReady;
        nvim.ui_attach(cols, rows, {
            ext_linegrid: true,
            ext_messages: getConfForUrl(url).cmdline === "firenvim",
            rgb: true,
        });
        let resizeReqId = 0;
        browser.runtime.onMessage.addListener((request: any, sender: any, sendResponse: any) => {
            if (request.selector === selector
                && request.funcName[0] === "resize"
                && request.args[0] > resizeReqId) {
                const [id, width, height] = request.args;
                resizeReqId = id;
                // We need to put the keyHandler at the origin in order to avoid
                // issues when it slips out of the viewport
                keyHandler.style.left = `0px`;
                keyHandler.style.top = `0px`;
                // It's tempting to try to optimize this by only calling
                // ui_try_resize when nCols is different from cols and nRows is
                // different from rows but we can't because redraw notifications
                // might happen without us actually calling ui_try_resize and then
                // the sizes wouldn't be in sync anymore
                const [cellWidth, cellHeight] = getCharSize(host);
                const nCols = Math.floor(width / cellWidth);
github dessant / search-by-image / src / select / App.vue View on Github external
mounted: function() {
    this.snackbar = new MDCSnackbar(this.$refs.snackbar);
    this.snackbar.foundation_.autoDismissTimeoutMs_ = 31556952000; // 1 year
    this.snackbar.closeOnEscape = false;

    browser.runtime.onMessage.addListener(this.onMessage);
    browser.runtime.sendMessage({id: 'selectFrameId'});
  }
};
github rejerry / bookmark / src / common / onetab / tabs.js View on Github external
const openTabLists = async () => {
  const currentWindow = await browser.windows.getCurrent();
  const windowId = currentWindow.id;
  const tabs = await getAllInWindow(windowId);
  let tabsRes = tabs.filter(i =>
    browser.runtime.getURL('index.html#/app/') === i.url
    || browser.runtime.getURL('index.html#/app') === i.url
  );
  if (tabsRes.length === 0) {
    await browser.tabs.create({url: browser.runtime.getURL('index.html#/app/')})
  } else {
    let latestTab = tabsRes.splice(tabsRes.length - 1, 1);
    const tabIndex = tabs.findIndex(tab => tab.id === latestTab[0].id);
    browser.tabs.highlight({windowId, tabs: tabIndex});

    /*关闭其他tab*/
    if (tabsRes.length !== 0) {
      let ids = [];
      tabsRes.map(i => ids.push(i.id));
      browser.tabs.remove(ids);
    }
  }
};
github sienori / Tab-Session-Manager / src / background / save.js View on Github external
async function sendMessage(message, options = {}) {
  await browser.runtime
    .sendMessage({
      message: message,
      ...options
    })
    .catch(() => {});
}
github AztecProtocol / AZTEC / packages / extension / src / content / utils / subscribeToBackgroundScript.js View on Github external
const backgroundResponse = await fetchFromBackgroundScript({
        ...data,
        type: clientEvent,
        query: queryWithRequestId,
    }) || {};
    const {
        data: {
            validation,
        },
    } = backgroundResponse;

    if (!validation.success) {
        return null;
    }

    const port = browser.runtime.connect({ name: requestId });
    port.onMessage.addListener(response => postToClientScript(requestId, {
        response,
    }));

    port.postMessage({
        type: contentSubscribeEvent,
    });

    const unsubscribe = () => port.postMessage({
        type: contentUnsubscribeEvent,
    });

    return {
        unsubscribe,
    };
}
github SeleniumHQ / selenium-ide / packages / selenium-ide / src / plugin / communication.js View on Github external
export function sendMessage(id, payload) {
  return browser.runtime
    .sendMessage(id, JSON.parse(JSON.stringify(payload)))
    .then(response => {
      if (response === undefined || response === null) {
        return Promise.reject(
          new NoResponseError(
            `${Manager.getPlugin(id).name} plugin did not respond`
          )
        )
      } else if (response.error) {
        const error =
          response.status === 'fatal'
            ? new FatalError(response.error)
            : new Error(response.error)
        error.sender = id
        return Promise.reject(error)
      } else {
github aredotna / ervell / src / extension / src / injectIframe.js View on Github external
import browser from 'webextension-polyfill'
import ExtensionPane from 'extension/src/lib/ExtenionPane'

const pane = new ExtensionPane()

browser.runtime.onMessage.addListener(msg => {
  switch (msg.text) {
    case 'toggle':
      if (pane.isOpen) {
        return pane.close()
      }
      return pane.open(msg)
    case 'add':
      return pane.add(msg)
    case 'save-page':
      if (pane.isOpen) {
        return pane.saveCurrentPage()
      }
      return pane.open(msg)
    default:
      break
  }
github SeleniumHQ / selenium-ide / packages / selenium-ide-extension / src / content / commands-api.js View on Github external
editRegion(request.rect, target => {
        if (target) {
          browser.runtime.sendMessage({
            selectTarget: true,
            target: [[target]],
            selectNext: request.selectNext,
          })
        } else {
          browser.runtime.sendMessage({
            cancelSelectTarget: true,
            selectNext: request.selectNext,
          })
        }
      })
    } else {
github glacambre / firenvim / src / browserAction.ts View on Github external
document.getElementById("disableFirenvim").addEventListener("click", () => {
        browser.runtime.sendMessage( { funcName: ["toggleDisabled"] })
            .then(updateDisableButton);
    });
    displayErrorsAndWarnings();
github lusakasa / saka / src / saka / Main / Containers / StandardSearch / index.jsx View on Github external
handleKeyDown = e => {
    switch (e.key) {
      case 'Escape':
        browser.runtime.sendMessage({
          key: 'closeSaka',
          searchHistory: [...this.props.searchHistory]
        });
        break;
      case 'Backspace':
        if (ctrlKey(e)) {
          e.preventDefault();
          this.closeTab();
        } else if (!e.repeat && e.target.value === '') {
          browser.runtime.sendMessage({
            key: 'closeSaka',
            searchHistory: [...this.props.searchHistory]
          });
        }
        break;
      case 'ArrowLeft':
      case 'ArrowRight':
        break;
      case 'ArrowDown':
        e.preventDefault();
        this.props.updateSearchHistory(this.state.searchString);
        this.incrementSelectedIndex(1);
        break;
      case 'ArrowUp':
        e.preventDefault();
        this.props.updateSearchHistory(this.state.searchString);