New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interception does not work with page.setContent() and relative URLs #4526
Comments
@FranckFreiburger This happens because the default page is opened on 'about:blank' url. This is a special URL - relative paths are not getting resolved against it, so the first image is not even attempted to be loaded. If, before doing Hope this helps. |
@FranckFreiburger Right now I'm polyfilling const browser = await puppeteer.launch(LAUNCH_OPTIONS);
const page = await browser.newPage();
// Polyfill fetch so it handles relative URLs in `about:blank`
await page.evaluate(() => {
const originalFetch = window.fetch;
window.fetch = (inputResource, init) => {
let resource = inputResource;
// https://regexper.com/#%5E%5C%2F%28%3F!%5C%2F%29.*
if (
typeof resource === 'string' &&
(resource.match(/^\/(?!\/).*/) || resource === '')
) {
resource = `https://self.local${resource}`;
}
return originalFetch(resource, init);
};
}); @aslushnikov Is there a better way if I don't want to |
Maybe you can use |
@aslushnikov I realized that I avoid a lot of headaches by just doing a page.goto('file://path/to/empty.html') and using that as a starting point. There is a lot of functionality that's limited in that |
page.goto works, page.setContent led to empty links in eval puppeteer/puppeteer#4526
Steps to reproduce
Tell us about your environment:
What steps will reproduce the problem?
What is the expected result?
The output should show that
./foo.png
andhttp://localhost/foo.png
are interceptedWhat happens instead?
Only
http://localhost/foo.png
request is interceptedThe text was updated successfully, but these errors were encountered: