How to use the chrome-remote-interface.New 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 adieuadieu / serverless-chrome / examples / serverless-framework / aws / src / handlers / screencast.js View on Github external
let framesCaptured = 0

  // @TODO: write a better queue, which waits a few seconds when reaching 0
  // before emitting "empty"
  const requestQueue = []

  const loading = async (startTime = Date.now()) => {
    log('Request queue size:', requestQueue.length, requestQueue)

    if ((!loaded || requestQueue.length > 0) && Date.now() - startTime < LOAD_TIMEOUT) {
      await sleep(100)
      await loading(startTime)
    }
  }

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

  const {
    Network, Page, Input, DOM,
  } = client

  Network.requestWillBeSent((data) => {
    // only add requestIds which aren't already in the queue
    // why? if a request to http gets redirected to https, requestId remains the same
    if (!requestQueue.find(item => item === data.requestId)) {
      requestQueue.push(data.requestId)
    }

    log('Chrome is sending request for:', data.requestId, data.request.url)
  })
github adieuadieu / serverless-chrome / examples / serverless-framework / src / printToPdf.js View on Github external
export async function printUrlToPdf (url, printOptions = {}) {
  const LOAD_TIMEOUT = (config && config.chrome.pageLoadTimeout) || 1000 * 20
  let result
  let loaded = false
  const requestQueue = [] // @TODO: write a better quite, which waits a few seconds when reaching 0 before emitting "empty"

  const loading = async (startTime = Date.now()) => {
    log('Request queue size:', requestQueue.length, requestQueue)

    if ((!loaded || requestQueue.length > 0) && Date.now() - startTime < LOAD_TIMEOUT) {
      await sleep(100)
      await loading(startTime)
    }
  }

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

  const { Network, Page } = client

  Network.requestWillBeSent((data) => {
    // only add requestIds which aren't already in the queue
    // why? if a request to http gets redirected to https, requestId remains the same
    if (!requestQueue.find(item => item === data.requestId)) {
      requestQueue.push(data.requestId)
    }

    log('Chrome is sending request for:', data.requestId, data.request.url)
  })

  Network.responseReceived(async (data) => {
    // @TODO: handle this better. sometimes images, fonts, etc aren't done loading before we think loading is finished
github gwuhaolin / chrome-render / lib / poll.js View on Github external
async createTab() {
    const tabCount = Object.keys(this.tabs).length;
    if (tabCount < this.maxTab) {

      // Create a new target/tab in the remote instance.
      // @see https://github.com/cyrus-and/chrome-remote-interface/#cdpnewoptions-callback
      const tab = await chrome.New({ port: this.port });

      const { id } = tab;
      this.tabs[id] = {
        free: true,
        client: await this.connectTab(id),
      };
      return id;
    }
  }
github JoshTheDerf / prerenderer / es5-autogenerated / renderers / chrome.js View on Github external
return _regenerator2.default.wrap(function _callee3$(_context3) {
                  while (1) {
                    switch (_context3.prev = _context3.next) {
                      case 0:
                        _context3.next = 2;
                        return CRI.New(localConnectionOptions);

                      case 2:
                        tab = _context3.sent;
                        _context3.next = 5;
                        return CRI(Object.assign({}, localConnectionOptions, { tab }));

                      case 5:
                        client = _context3.sent;
                        Page = client.Page;
                        _context3.next = 9;
                        return Page.enable();

                      case 9:
                        if (!options.inject) {
                          _context3.next = 19;
                          break;
github oblador / loki / src / targets / chrome / create-existing-docker-target.js View on Github external
async function createNewDebuggerInstance() {
    debug(
      `Launching new tab with debugger at port ${dockerHost}:${chromeDockerPort}`
    );
    const target = await CDP.New({ host: dockerHost, port: chromeDockerPort });
    debug(`Launched with target id ${target.id}`);
    const client = await CDP({
      host: dockerHost,
      port: chromeDockerPort,
      target,
    });

    client.close = () => {
      debug('New closing tab');
      return CDP.Close({
        host: dockerHost,
        port: chromeDockerPort,
        id: target.id,
      });
    };
github livewires / you-win / docs / pdfs.js View on Github external
async function newPage(chrome, url) {
    const target = await CDP.New({port: chrome.port})
    const client = await CDP({target})
    const {Page} = client
    await Page.enable()
    await Page.navigate({url, referrer: ''})
    await Page.loadEventFired()
    await sleep(200)
    return {chrome, Page, client}
}
github moos / chromate / src / chrome-tab.js View on Github external
function getClient(options) {
  if (!options || !options.port) {
    options = Object.assign(options || {}, {port: Tab.settings.port});
  }

  return CDP.New(options).then((tab) => {
    return CDP({target: tab});
  });
}
github oblador / loki / packages / target-chrome-docker / src / create-chrome-docker-target.js View on Github external
async function createNewDebuggerInstance() {
    debug(`Launching new tab with debugger at port ${host}:${port}`);
    const target = await CDP.New({ host, port });
    debug(`Launched with target id ${target.id}`);
    const client = await CDP({ host, port, target });

    client.close = () => {
      debug('New closing tab');
      return CDP.Close({ host, port, id: target.id });
    };

    return client;
  }
github prisma-archive / chromeless / src / chrome / local.ts View on Github external
private async connectToChrome(): Promise {
    const { host, port } = this.options.cdp
    const target = await CDP.New({
      port,
      host,
    })
    return await CDP({ target, host, port })
  }