1. 程式人生 > >/在文檔上下文裏執行腳本,並返回結果

/在文檔上下文裏執行腳本,並返回結果

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

/在文檔上下文裏執行腳本,並返回結果