puppeteer - 如何设置当前 url,以便在 puppeteer 中注入(inject)自定义 html 时正确解析相对链接?

标签 puppeteer puppeteer-sharp

我正在尝试创建一个新页面并手动设置其内容。由于注入(inject)代码的空白页面的 url 仍然是 about:blank,因此该页面上的所有相关链接都已损坏。有没有办法设置页面的 url,而不需要通过 goto 实际导航到该 url?

最佳答案

我可以想到两个选择:

  1. 创建一个函数,将相对路径转换为 ​​file:// URL。
  2. 运行一个简单的服务器。我写了一篇关于这个的文章on my blog

关于puppeteer - 如何设置当前 url,以便在 puppeteer 中注入(inject)自定义 html 时正确解析相对链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69201513/

相关文章:

node.js - 是否有一种通用方法可以使用 Puppeteer 消除所有模式和 cookie 警告?

node.js - 使用 puppeteer + ffmpeg 从网站录制视频

javascript - puppeteer:在继续下一行之前等待 N 秒

c# - 无法单击具有特定属性的按钮

c# - 有没有办法将 chrome-extension 添加到 PuppeteerSharp Web 驱动程序?

node.js - 如何让 Puppeteer waitForNavigation 在点击后工作

javascript - 使用 Puppeteer 获取所有纯文本

c# - 使用 PuppeteerSharp 访问 windows.localStorage

azure - 已发布的 .net Core Azure 应用服务 (Linux) 没有权限

c# - 使用异步 linq 过滤 Puppeter Sharp 的 ElementHandle[]