2017-10-20 6 views
0

chromless apiを使用してフルページのスクリーンショットをキャプチャしたいと思います。 (フルページは、現在のビューポートだけでなく、折りたたみの下のすべてのものと同じように)クロムレスAPIを使用してdocument.body.scrollHeightにアクセスできますか?

ここで

私が現在持っているものですが、私は彼らのdemo siteにテストしてい:?

const chromeless = new Chromeless({ remote: true }) 

const screenshot = await chromeless 
    .goto('https://www.graph.cool') 
    .setViewport({width: 1024, height: 800, scale: 1}) 
    .evaluate(() => { 
    const height = document.body.scrollHeight; 
    return height 
    }) 
    .setViewport({width: 1024, height: height, scale: 1}) 
    .screenshot() 

console.log(screenshot) 

await chromeless.end() 

私は(希望は)私のjavascriptのは大丈夫です、そして多分これは、APIの制限だと思うからアクセスdocumentオブジェクトですヘッドレスウェブブラウザ?

012ここ

は、参考のために、評価のドキュメントです: https://github.com/graphcool/chromeless/blob/master/docs/api.md#api-evaluate

答えて

1

このような文書の高さ(demo)をつかんでページ全体をスクリーンショットすることが可能です:

const chromeless = new Chromeless({ remote: true }) 

const scrollHeight = await chromeless 
    .goto('https://www.graph.cool') 
    .evaluate(() => document.body.scrollHeight) 

console.log(`The document's height is ${scrollHeight}px`) 

const screenshot = await chromeless 
    .setViewport({width: 1024, height: scrollHeight, scale: 1}) 
    .screenshot() 

console.log(screenshot) 

await chromeless.end() 

注意すべき主なものは、我々でありますevaluate()呼び出しから高さを返し、それを変数scrollHeightに割り当ててから、ビューポートの高さを設定する必要があります。

関連する問題