在node js中,我使用playwright打开一个浏览器页面,用一些html设置内容,然后截取它的屏幕截图.该html包含图像标签,并且IMG的src是本地文件.在截图中,我没有看到当地的图片.是否禁用本地文件访问?如果是,如何启用它?我使用了文件名的相对路径和绝对路径.如果我使用网址,则会显示图像. 我使用的是Mac OS.
async function screenShot() {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.setViewportSize({ width:200, height:200 });
await page.setContent(`
<html><body>
<div id="container">
<h1>HELLO</h1>
<img src="file:///resources/image.png" />
</div></body>
</html>
`)
await page.locator("#container").screenshot({ path: 'screenshot.png' });
// Teardown
await context.close();
await browser.close();
}
输出图像-