schickling/chromeless

Error: No inspectable targets

Open

#181 opened on Aug 6, 2017

View on GitHub
 (16 comments) (0 reactions) (0 assignees)TypeScript (13,240 stars) (606 forks)batch import
APIbughelp wanted

Description

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()

Contributor guide