How to use the chrome-remote-interface.List function in chrome-remote-interface

To help you get started, we’ve selected a few chrome-remote-interface 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 webhintio / hint / packages / utils-debugging-protocol-common / src / debugging-protocol-connector.ts View on Github external
await this.lockFile();

        const launcher: BrowserInfo = await this._launcher.launch('about:blank');
        let client;

        this._pid = launcher.pid;

        /*
         * We want a new tab for this session. If it is a new browser, a new tab
         * will be created automatically. If it was already there, then we need
         * to create it ourselves.
         */
        if (launcher.isNew) {
            // Chrome Launcher could return extensions tabs if installed them but we don't need them.
            const tabs = filter(await cdp.List({ port: launcher.port }), (tab: any) => { // eslint-disable-line new-cap
                return !tab.url.startsWith('chrome-extension');
            });

            // Can assume not-null as `this._launcher.launch` always will return a port.
            client = await this.getClient(launcher.port!, tabs[0]);
            this._tabs = tabs;
        } else {
            const tab = await cdp.New({ port: launcher.port, url: null }); // eslint-disable-line new-cap

            if (!tab) {
                throw new Error('Error trying to open a new tab');
            }

            this._tabs.push(tab);

            client = await cdp({
github gwuhaolin / chrome-render / lib / poll.js View on Github external
static async new(maxTab = Infinity) {
    const port = await sysFreePort();
    const chromeTabsPoll = new ChromeTabsPoll();
    chromeTabsPoll.port = port;
    chromeTabsPoll.chromeLauncher = await launchChrome(port);
    chromeTabsPoll.tabs = {};
    chromeTabsPoll.maxTab = maxTab;
    chromeTabsPoll.requireResolveTasks = [];

    // Request the list of the available open targets/tabs of the remote instance.
    // @see https://github.com/cyrus-and/chrome-remote-interface/#cdplistoptions-callback
    const tabs = await chrome.List({ port });

    for (let i = 0; i < tabs.length; i++) {
      const tab = tabs[i];
      const { id, type } = tab;
      // ignore background_page
      if (type === 'page') {
        chromeTabsPoll.tabs[id] = {
          free: true,
          client: await chromeTabsPoll.connectTab(id),
        };
      }
    }
    return chromeTabsPoll;
  }
github adieuadieu / serverless-chrome / examples / serverless-framework / aws / src / captureScreenshot.js View on Github external
export async function captureScreenshotOfUrl (url) {
  const LOAD_TIMEOUT = (config && config.chrome.pageLoadTimeout) || 1000 * 60

  let result
  let loaded = false

  const loading = async (startTime = Date.now()) => {
    if (!loaded && Date.now() - startTime < LOAD_TIMEOUT) {
      await sleep(100)
      await loading(startTime)
    }
  }

  const [tab] = await Cdp.List()
  const client = await Cdp({ host: '127.0.0.1', target: tab })

  const { Network, Page } = client

  Network.requestWillBeSent((params) => {
    log('Chrome is sending request for:', params.request.url)
  })

  Page.loadEventFired(() => {
    loaded = true
  })

  if (config.logging) {
    Cdp.Version((err, info) => {
      console.log('CDP version info', err, info)
    })
github adieuadieu / serverless-chrome / examples / serverless-framework / aws / src / chrome / screenshot.js View on Github external
export default async function captureScreenshotOfUrl (url, mobile = false) {
  const LOAD_TIMEOUT = process.env.PAGE_LOAD_TIMEOUT || 1000 * 60

  let result
  let loaded = false

  const loading = async (startTime = Date.now()) => {
    if (!loaded && Date.now() - startTime < LOAD_TIMEOUT) {
      await sleep(100)
      await loading(startTime)
    }
  }

  const [tab] = await Cdp.List()
  const client = await Cdp({ host: '127.0.0.1', target: tab })

  const {
    Network, Page, Runtime, Emulation,
  } = client

  Network.requestWillBeSent((params) => {
    log('Chrome is sending request for:', params.request.url)
  })

  Page.loadEventFired(() => {
    loaded = true
  })

  try {
    await Promise.all([Network.enable(), Page.enable()])
github firefox-devtools / debugger / packages / devtools-client-adapters / src / chrome.js View on Github external
function connectClient() {
  if (!getValue("chrome.debug")) {
    return Promise.resolve(createTabs([]));
  }

  return CDP.List({
    port: getValue("chrome.port"),
    host: getValue("chrome.host")
  })
    .then(tabs => createTabs(tabs, {
      clientType: "chrome", type: "page"
    }));
}
github N0taN3rd / Squidwarc / lib / launcher / puppeteer.js View on Github external
async function findPageToConnectTo (options) {
  const targets = await CRI.List(options)
  let backup
  let i = 0
  for (; i < targets.length; i++) {
    const target = targets[i]
    if (target.webSocketDebuggerUrl) {
      if (target.type === 'page') {
        return target.webSocketDebuggerUrl
      } else {
        backup = target
      }
    }
  }
  if (backup) return backup.webSocketDebuggerUrl
  throw new Error('Squidwarc could not find a browser page to connect to')
}
github firefox-devtools / devtools-core / packages / devtools-launchpad / src / client / chrome.js View on Github external
async function connectClient() {
  if (!getValue("chrome.debug")) {
    return createTabs([]);
  }

  try {
    const tabs = await CDP.List({
      port: getValue("chrome.port"),
      host: getValue("chrome.host")
    });

    return createTabs(tabs, {
      clientType: "chrome",
      type: "page"
    });
  } catch (e) {
    return [];
  }
}
github firefox-devtools / debugger / packages / devtools-client-adapters / src / chrome.js View on Github external
function connectNodeClient() {
  if (!getValue("node.debug")) {
    return Promise.resolve(createTabs([]));
  }

  return CDP.List({
    port: getValue("node.port"),
    host: getValue("node.host")
  })
    .then(tabs => createTabs(tabs, {
      clientType: "node", type: "node"
    }));
}
github N0taN3rd / Squidwarc / lib / crawler / index.js View on Github external
static List (...args) {
    return CDP.List(...args)
  }
github carlosrocha / vim-chrome-devtools / src / ChromeDevToolsPlugin.js View on Github external
list = async () => {
    let targets;
    try {
      targets = await CDP.List(await this._getDefaultOptions());
    } catch (e) {
      echoerr(this._nvim, e.message);
    }

    if (!targets) {
      return;
    }

    const labels = targets.map(
      ({ id, title, url }) => `${id}: ${title} - ${url}`,
    );

    if (labels.length == 0) {
      echomsg(this._nvim, 'No targets available.');
    } else {
      await this._nvim.call('fzf#run', {