schickling/chromeless

Error: No inspectable targets

Open

#181 创建于 2017年8月6日

在 GitHub 查看
 (16 评论) (0 反应) (0 负责人)TypeScript (606 fork)batch import
APIbughelp wanted

仓库指标

Star
 (13,240 star)
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()

贡献者指南