得到终端的console.log输出在这里,我下面这个问题后:如何通过无头的Chrome Runtime.evaluate
https://github.com/cyrus-and/chrome-remote-interface/issues/105
但我似乎无法得到console.log
输出在Mac的终端。它可能在我看不到的Chrome Devtools窗口中。
所以我怎么通过Runtime.evaluate表达的Mac终端的console.log输出?
我下面的代码:
const chromeLauncher = require('chrome-launcher');
const CDP = require('chrome-remote-interface');
const file = require('fs');
(async function() {
async function launchChrome() {
return await chromeLauncher.launch({
chromeFlags: [
'--headless',
'--disable-gpu'
]
});
}
const chrome = await launchChrome();
const protocol = await CDP({
port: chrome.port
});
const {
DOM,
Network,
Page,
Emulation,
Runtime
} = protocol;
await Promise.all([Network.enable(), Page.enable(), Runtime.enable(), DOM.enable()]);
Page.navigate({url: 'https://www.chromestatus.com/'});
Page.loadEventFired(async() => {
const result = await Runtime.evaluate({expression: 'console.log(\'aaa\')'});
protocol.close();
chrome.kill();
});
})();
上帝的母亲。为什么它必须是复杂的。谢谢!! –
@惠普。大声笑,我确切地知道你的意思。当然,很高兴帮助!不要忘记奖励赏金。 :P – mscheker