How to set current url so relative links resolve correctly when injecting custom html in puppeteer?

Viewed 198

I am trying to create a new page and manually set its content. Because the url of a blank page with injected code is still about:blank, all of the relative links on the page are broken. Is there a way to set the url of the page without actually navigating to that url via goto?

1 Answers

I can think of two options:

  1. Create a function to turn a relative path into a file:// URL.
  2. Run a simple server. I wrote a post about that on my blog
Related