question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CDP.Close() not working with Chrome 59 on macOS

See original GitHub issue

Hi, I’m trying to do the following actions:

  1. open a new (headless) Chrome tab
  2. navigate to an URL
  3. take e screenshot
  4. close Tab

And closing tab doesn’t work. In fact, if I do a http://localhost:9222/json/list all the tabs opened at specified pages are listed.

Basically, the code is the following:

...
const target = await CDP.New({ port: this.options.port || 9222 });
const tab = await CDP({ target });     
const tabId = tab.target.id;      
const { Page, Emulation } = tab;
      
await Promise.all([
  Page.enable(),
  Emulation.setDeviceMetricsOverride(options.metrics),
  Emulation.setVisibleSize({ width: options.metrics.width, height: options.metrics.height }),
  Emulation.forceViewport({ x: 0, y: 0, scale: 1 }),
]);
await Page.navigate({ url: url });
await Page.loadEventFired();      
let { data } = await Page.captureScreenshot({ format: 'png', fromSurface: true });

// do something with data... 
// close tab   

await CDP.Close( {id: tabId});

I’ve also tried using Runtime:

await tab.Runtime.evaluate({expression: 'window.close();'})

but again, tabs stay open. Many thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
benjaminwoodcommented, Jul 19, 2017

Yeah, that makes sense. I’ve opened a PR that adds a general note. Feel free to tweak it or let me know how you’d like it to change and I can adjust the PR.

1reaction
benjaminwoodcommented, Jul 18, 2017

FYI for anybody else that lands here, the bug has been fixed in Chrome Canary: https://www.google.com/intl/en/chrome/browser/canary.html

@cyrus-and perhaps we should comment about this in the readme where appropriate? If you agree I’ll open a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Chrome won't shut down on Mac? Try these fixes
We've got all the troubleshooting answers for what to do when Chrome won't shut down on your Mac. From Terminal commands to Chrome...
Read more >
Getting Started with Headless Chrome - Chrome Developers
It's a way to run the Chrome browser in a headless environment. Essentially, running Chrome without chrome! It brings all modern web platform ......
Read more >
How to install and use Headless Chrome on OSX
This walkthrough shows you how to get headless Chrome up and running on OSX and explains in detail how to use the code...
Read more >
chrome-remote-interface - npm
The solution is to provide an up-to-date one, or if you are using the protocol embedded in chrome-remote-interface, make sure to be running...
Read more >
Fix Chrome update problems & failed updates - Google Support
If you're having problems updating Chrome on your computer, you might see: Update failed: Updates are disabled by administrator Update failed (Error: 3...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found