/在文檔上下文裏執行腳本,並返回結果
阿新 • • 發佈:2018-10-06
cal lua puppet launch window row out val console
/在文檔上下文裏執行腳本,並返回結果
(async () => {
const browser = await puppeteer.launch({
args: [‘--no-sandbox‘],
timeout: 10000,
});
const page = await browser.newPage();
await page.goto(‘http://www.163.com‘);
// Get the "viewport" of the page, as reported by the page.
const dimensions = await page.evaluate(() => {
return {
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
deviceScaleFactor: window.devicePixelRatio
};
});
console.log(‘Dimensions:‘, dimensions);
await browser.close();
})();
/在文檔上下文裏執行腳本,並返回結果