Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Take screenshot of an element #41

Closed
buremba opened this issue Jul 27, 2017 · 14 comments
Closed

Take screenshot of an element #41

buremba opened this issue Jul 27, 2017 · 14 comments

Comments

@buremba
Copy link

buremba commented Jul 27, 2017

The screenshot() method returns the full-page screenshot, is there any way to get the screenshot of a DIV or any other element?

@ernsheong
Copy link

Is it really "full-page", or just viewport screenshot?

@buremba
Copy link
Author

buremba commented Jul 27, 2017

Oh, sorry, it's the viewport. It's possible to calculate the viewport of the DIV, create a screenshot with that viewport so that the result covers the DIV and then crop the screenshot but most of the screenshot tools support this feature and it would be great if this library can also support it.

@ernsheong
Copy link

This is basically a proxy to Chrome itself, so if Chrome doesn't have it, you're out of luck

@buremba
Copy link
Author

buremba commented Jul 27, 2017

It's possible to accomplish this with a bit of post-processing. If the aim of this library is to provide a proxy to Chrome headless, then you're right but if the aim is to provide a high-level library (it looks to be like that) on top of Chrome, this would be a good feature.

@stevenvachon
Copy link

Nightmare has a clip argument. This library is still very immature.

@hbakhtiyor
Copy link

Page.captureScreenshot protocol method has clip parameter which you can use it.

I did it in my API, here's the example of the capturing only DOM node.
https://api.letsvalidate.com/v1/thumbs?url=stackoverflow.com&selector=%23question-mini-list

Here's how I did it.

// ...

const {root: {nodeId: documentNodeId}} = await DOM.getDocument();
let nodeId;

try {
  const node = await DOM.querySelector({
    selector: options.selector,
    nodeId: documentNodeId,
  });

  nodeId = node.nodeId;
} catch(err) {
  console.error('Error while DOM querying', {err});
}

if (nodeId) {
  const {model} = await DOM.getBoxModel({nodeId});

  clip = {
    x: model.content[0],
    y: model.content[1],
    width: model.width,
    height: model.height,
    scale: 1
  };
}

// ...

const {data} = await Page.captureScreenshot({clip});

@stevenvachon
Copy link

Verbose. I'll stick with Nightmare.

@buremba
Copy link
Author

buremba commented Jul 27, 2017

@hbakhtiyor it's a hosted service, we would like to host the API in our own servers / AWS account because of security considerations. We attach the private cookie information to the session in order to get screenshots of user dashboards. That's why I'm interested in this library.

@joelgriffith
Copy link
Contributor

Navalia has had this for a while as well: https://joelgriffith.github.io/navalia/Chrome/screenshot/

@schickling
Copy link
Owner

That's a great idea @buremba! We should definitely make this easier in the future! Thanks for bringing this up.

How would you like the API to look like?

@stevenvachon: Please note that unlike NightmareJS which has been around for many years and therefore seen a lot of API iterations and improvements, Chromeless is still pretty new. So if you're missing a feature, please open an issue (or even better: create a PR). I think this would be more productive instead of these kinds of comments. 🙏

@adieuadieu adieuadieu added the API label Jul 28, 2017
@adieuadieu adieuadieu added this to 1.3 in Roadmap Jul 29, 2017
@adieuadieu adieuadieu moved this from 1.3 to 1.4 in Roadmap Jul 29, 2017
@elisherer
Copy link
Contributor

Implemented in #137

@buremba
Copy link
Author

buremba commented Aug 2, 2017

Thanks!

@buremba buremba closed this as completed Aug 2, 2017
@buremba
Copy link
Author

buremba commented Aug 2, 2017

I'm opening the issue since the PR is not merged yet. You can close it once it's merged.

@buremba buremba reopened this Aug 2, 2017
@achyutjhunjhunwala
Copy link

@adieuadieu Hi, Any chances, the unreleased functionalities like this and custom path for saving screenshot getting released soon

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

9 participants