當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript chrome-remote-interface.default方法代碼示例

本文整理匯總了TypeScript中chrome-remote-interface.default方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript chrome-remote-interface.default方法的具體用法?TypeScript chrome-remote-interface.default怎麽用?TypeScript chrome-remote-interface.default使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chrome-remote-interface的用法示例。


在下文中一共展示了chrome-remote-interface.default方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: connectToChrome

 private async connectToChrome(): Promise<Client> {
   const target = await CDP.New({
     port: this.options.cdp.port,
     host: this.options.cdp.host,
   })
   return await CDP({ target })
 }
開發者ID:nylen,項目名稱:chromeless,代碼行數:7,代碼來源:local.ts

示例2: startChrome

  private async startChrome(): Promise<Client> {
    const { port } = this.options.cdp
    this.chromeInstance = await launch({
      logLevel: this.options.debug ? 'info' : 'silent',
      chromeFlags: [
        // Do not render scroll bars
        '--hide-scrollbars',

        // The following options copied verbatim from https://github.com/GoogleChrome/chrome-launcher/blob/master/src/flags.ts

        // Disable built-in Google Translate service
        '--disable-translate',
        // Disable all chrome extensions entirely
        '--disable-extensions',
        // Disable various background network services, including extension updating,
        //   safe browsing service, upgrade detector, translate, UMA
        '--disable-background-networking',
        // Disable fetching safebrowsing lists, likely redundant due to disable-background-networking
        '--safebrowsing-disable-auto-update',
        // Disable syncing to a Google account
        '--disable-sync',
        // Disable reporting to UMA, but allows for collection
        '--metrics-recording-only',
        // Mute any audio
        '--mute-audio',
        // Skip first run wizards
        '--no-first-run',
      ],
      port,
    })
    const target = await CDP.New({
      port,
    })
    return await CDP({ target, port })
  }
開發者ID:13768324554,項目名稱:chromeless,代碼行數:35,代碼來源:local.ts

示例3: initRuntimeClient

  private async initRuntimeClient(): Promise<RuntimeClient> {
    const target = await CDP.New()
    const client = await CDP({ target })

    await this.setViewport(client)

    const runtime = new LocalRuntime(client, this.options)

    return { client, runtime }
  }
開發者ID:KhaledNobani,項目名稱:chromeless,代碼行數:10,代碼來源:local.ts

示例4: startChrome

 private async startChrome(): Promise<Client> {
   this.chromeInstance = await launch({
     logLevel: this.options.debug ? 'info' : 'silent',
     port: this.options.cdp.port,
   })
   const target = await CDP.New({
     port: this.chromeInstance.port,
   })
   return await CDP({ target })
 }
開發者ID:nylen,項目名稱:chromeless,代碼行數:10,代碼來源:local.ts

示例5: generate

/**
 * Connects to Chrome and generates a PDF from HTML or a URL.
 *
 * @param {string} html the HTML string or URL.
 * @param {CreateOptions} options the generation options.
 * @param {any} tab the tab to use.
 * @returns {Promise<CreateResult>} the generated PDF data.
 */
async function generate(html: string, options: CreateOptions, tab: any): Promise<CreateResult>  {
  await throwIfCanceled(options);
  const client = await CDP({ ...options, target: tab });
  try {
    const {Network, Page, Runtime} = client;
    await throwIfCanceled(options);
    if (options.clearCache) {
      await Network.clearBrowserCache();
    }
    await Promise.all([
      Page.enable(), // Enable Page events
      Runtime.enable(), // Enable Runtime events
    ]);
    if (options.runtimeConsoleHandler) {
      await throwIfCanceled(options);
      Runtime.consoleAPICalled(options.runtimeConsoleHandler);
    }
    if (options.runtimeExceptionHandler) {
      await throwIfCanceled(options);
      Runtime.exceptionThrown(options.runtimeExceptionHandler);
    }
    const url = /^(https?|file|data):/i.test(html) ? html : `data:text/html,${html}`;
    if (options.cookies) {
      await throwIfCanceled(options);
      await Network.setCookies({cookies: options.cookies});
    }
    await throwIfCanceled(options);
    await Promise.all([
      Page.navigate({url}),
      Page.loadEventFired(),
    ]); // Resolve order varies
    if (options.completionTrigger) {
      await throwIfCanceled(options);
      const waitResult = await options.completionTrigger.wait(client);
      if (waitResult && waitResult.exceptionDetails) {
        await throwIfCanceled(options);
        throw new Error(waitResult.result.value);
      }
    }
    await throwIfCanceled(options);
    // https://chromedevtools.github.io/debugger-protocol-viewer/tot/Page/#method-printToPDF
    const pdf = await Page.printToPDF(options.printOptions);
    await throwIfCanceled(options);
    return new CreateResult(pdf.data);
  } finally {
    client.close();
  }
}
開發者ID:timonweb-forks,項目名稱:html-pdf-chrome,代碼行數:56,代碼來源:index.ts


注:本文中的chrome-remote-interface.default方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。