schickling/chromeless

Error: No inspectable targets

開放

#181 建立於 2017年8月6日

 (16 則留言) (0 個反應) (0 位負責人)TypeScript (606 個分叉)batch import
APIbughelp wanted

倉庫指標

星標
 (13,240 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

When trying to use it with chrome headless instance, I'm getting:

Error: No inspectable targets
    at defaultTarget (/Project/node_modules/chrome-remote-interface/lib/chrome.js:45:23)
    at /Project/node_modules/chrome-remote-interface/lib/chrome.js:228:32
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:208:7)

Failing near here:

class Chrome extends EventEmitter {
    constructor(options, notifier) {
        super();
        // options
        const defaultTarget = function (targets) {
            // prefer type = 'page' inspectabe targets as they represents
            // browser tabs (fall back to the first instectable target
            // otherwise)
            let backup;
            let target = targets.find((target) => {
                if (target.webSocketDebuggerUrl) {
                    backup = backup || target;
                    return target.type === 'page';
                } else {
                    return false;
                }
            });
            target = target || backup;
            if (target) {
                return target;
            } else {
                throw new Error('No inspectable targets');
            }
        };

Running example with:

  const chromeless = new Chromeless({
    viewport: {
      width: 1440,
      height: 900,
      scale: 1,
    }
  });

  const screenshot = await chromeless
    .goto('https://www.google.com')
    .type('chromeless', 'input[name="q"]')
    .press(13)
    .wait('#resultStats')
    .screenshot();

  console.log(screenshot) // prints local file path or S3 url

    await chromeless.end()

貢獻者指南