Cap*_*eow 7 google-chrome google-chrome-devtools puppeteer
我正在尝试收集 Chrome 浏览器日志:浏览器发出的警告,例如弃用和干预。例如,对于网站https://uriyaa.wixsite.com/corvid-cli2:
A cookie associated with a cross-site resource at http://wix.com/ was set without the `SameSite` attribute.
A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`.
You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
Run Code Online (Sandbox Code Playgroud)
我认为下面的代码可以解决问题,但它只捕获页面代码生成的日志。
(async ()=> {
const browser = await puppeteer.launch({dumpio: true});
const page = await browser.newPage();
page.on('console', msg => {
for (let i = 0; i < msg._args.length; ++i)
console.log(`${i}: ${msg._args[i]}`);
});
await page.goto('https://uriyaa.wixsite.com/corvid-cli2', {waitUntil: 'networkidle2', timeout: 20000});
await page.screenshot({path: 'screenshot.png'});
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)
波纹管不相关,因为我认为 reportingobserver 在没有 SameSite 的情况下无法捕获 cookie 上的 chrome 信息:阅读该主题使我访问https://developers.google.com/web/updates/2018/07/reportingobserver但我不确定如何使用它,使用浏览器控制台中的示例不起作用。
我不确定应该在哪种情况下使用观察者代码,或者浏览器是否需要一个标志来激活报告 API。或者如果这是解决问题的方法。
欢迎帮助。
据推测,该'console'事件仅捕获console.log()来自页面的类似调用。但似乎您可以通过 Log Domain 捕获来自浏览器CDPSession的警告。不幸的是,它只适用于我的头脑浏览器:
'use strict';
const puppeteer = require('puppeteer');
(async function main() {
try {
const browser = await puppeteer.launch({ headless: false });
const [page] = await browser.pages();
const cdp = await page.target().createCDPSession();
await cdp.send('Log.enable');
cdp.on('Log.entryAdded', async ({ entry }) => {
console.log(entry);
});
await page.goto('https://uriyaa.wixsite.com/corvid-cli2');
} catch (err) {
console.error(err);
}
})();
Run Code Online (Sandbox Code Playgroud)
其中一项:
{
source: 'other',
level: 'warning',
text: 'A cookie associated with a cross-site resource at http://www.wix.com/ was set without the `SameSite` attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.',
timestamp: 1589058118372.802,
url: 'https://uriyaa.wixsite.com/corvid-cli2'
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6172 次 |
| 最近记录: |