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
Request interception and caching compatibility #6996
Request interception and caching compatibility #6996
Conversation
This is not a perfect solution, as outlined in #2905 (comment). It should cover most people's use cases though, while we are waiting for Chromium changes to land. |
Jan, could you PTAL since you looked into the request interception recently? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
One thing though: Could you add a unit test to cover this use case? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah damn, I'm confused by this UI.
Could you add a test that covers this new behaviour?
When we call |
Can I suggest that the documentation update should give the merest clue as to why you might or might not want caching to be disabled? If I'm understanding it correctly, the only problem is that if caching is not disabled, then requests served from the cache will not be intercepted - which may well not be a problem at all in many applications. |
I'm under the impression that caching is purposely disabled when configuring request interception because otherwise unexpected issues would happen. This is also stated by the original author @aslushnikov of the relevant code in #1154 and #4260. It is relatively easy to just configure request interception and having caching enabled at the same time. I have tried that some time ago and have got the similar results (rendering some pages never finish due to lack of the Unfortunately, this PR does not seem to resolve the earlier issue as it merely provides the means for users to keep caching enabled while doing request interception. I have performed further tests, and it seems that Puppeteer at 8695759 (revision that has this PR merged) would fail to render many webpages, one example of which is https://github.com/, while having I'm afraid that this PR may need to be excluded from the next Puppeteer release unless properly fixed, as the current version merely reintroduced the issue that was previously got rid of in #1154 and #4260. |
@starrify I am fully aware that |
Right, I agree that people with specific use cases may be interested in this, though I much doubt the coverage as there are many real-world web pages that would break on this, according to my previous tests and what's mentioned here: #5176 (comment) @Androbin: Could you help quickly verify whether it is true that Puppeteer at revision 8695759 (with this PR merged) would fail to render https://github.com/ ? (click me for a sample test script)(async () => {
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
// Needed only when inside a Docker container
args: ['--no-sandbox'],
});
const page = await browser.newPage();
const enableCaching = process.env.TEST_ENABLE_CACHING == 'true';
await page.setRequestInterception(true, enableCaching);
page.on('request', (request) => {
request.continue();
});
const url = process.env.TEST_URL || 'https://github.com/';
try {
await page.goto(url);
} catch (err) {
console.error(err);
}
await browser.close();
})(); Sorry but I'm against the very idea of have it documented as experimental, as I would like to see from the documents clear warnings that this feature is known to break the rendering of many real world web pages (if my other issue report doesn't get proved wrong). |
const { page, server } = getTestState();
await page.setRequestInterception(true, false);
page.on('request', (request) => request.continue());
await page.goto('https://github.com/', { waitUntil: 'load' }); PASSED const { page, server } = getTestState();
await page.setRequestInterception(true, true);
page.on('request', (request) => request.continue());
await page.goto('https://github.com/', { waitUntil: 'domcontentloaded' }); PASSED const { page, server } = getTestState();
await page.setRequestInterception(true, true);
page.on('request', (request) => request.continue());
await page.goto('https://github.com/', { waitUntil: 'load' }); FAILED const { page, server } = getTestState();
await page.setRequestInterception(true, true);
page.on('request', (request) => {
// alternative: request.resourceType() == "font"
if (request.url().endsWith(".woff")) {
request.abort();
} else {
request.continue();
}
});
await page.goto('https://github.com/', { waitUntil: 'load' }); PASSED |
I would like to note that blocking requests for fonts and images is a common use case of the people who requested this flag. |
@starrify If you provide me with a list of sites that have this issue, I could compile a list of failing resources, we could identify what's common between them, and fix the issue. |
I have done some debugging and it looks like the events generated by Chromium are in a different order for fonts than for other resources like stylesheets. Stylesheet request:
Font request (cache disabled):
Font request (cache enabled):
Font request (cache enabled + fix):
|
Could you also check a scenario with redirects and how they change the order of events? |
See #6996 (comment) and #6996 (comment) for context. Issue: #7038
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [puppeteer](https://togithub.com/puppeteer/puppeteer) | [`^9.1.1` -> `^10.0.0`](https://renovatebot.com/diffs/npm/puppeteer/9.1.1/10.0.0) | [![age](https://badges.renovateapi.com/packages/npm/puppeteer/10.0.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/puppeteer/10.0.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/puppeteer/10.0.0/compatibility-slim/9.1.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/puppeteer/10.0.0/confidence-slim/9.1.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>puppeteer/puppeteer</summary> ### [`v10.0.0`](https://togithub.com/puppeteer/puppeteer/blob/master/CHANGELOG.md#​1000-httpsgithubcompuppeteerpuppeteercomparev911v1000-2021-05-31) [Compare Source](https://togithub.com/puppeteer/puppeteer/compare/v9.1.1...v10.0.0) ##### ⚠ BREAKING CHANGES - Node.js 10 is no longer supported. ##### Features - **chromium:** roll to Chromium 92.0.4512.0 (r884014) ([#​7288](https://togithub.com/puppeteer/puppeteer/issues/7288)) ([f863f4b](https://togithub.com/puppeteer/puppeteer/commit/f863f4bfe015e57ea1f9fbb322f1cedee468b857)) - **requestinterception:** remove cacheSafe flag ([#​7217](https://togithub.com/puppeteer/puppeteer/issues/7217)) ([d01aa6c](https://togithub.com/puppeteer/puppeteer/commit/d01aa6c84a1e41f15ffed3a8d36ad26a404a7187)) - expose other sessions from connection ([#​6863](https://togithub.com/puppeteer/puppeteer/issues/6863)) ([cb285a2](https://togithub.com/puppeteer/puppeteer/commit/cb285a237921259eac99ade1d8b5550e068a55eb)) - **launcher:** add new launcher option `waitForInitialPage` ([#​7105](https://togithub.com/puppeteer/puppeteer/issues/7105)) ([2605309](https://togithub.com/puppeteer/puppeteer/commit/2605309f74b43da160cda4d214016e4422bf7676)), closes [#​3630](https://togithub.com/puppeteer/puppeteer/issues/3630) ##### Bug Fixes - added comments for browsercontext, startCSSCoverage, and startJSCoverage. ([#​7264](https://togithub.com/puppeteer/puppeteer/issues/7264)) ([b750397](https://togithub.com/puppeteer/puppeteer/commit/b75039746ac6bddf1411538242b5e70b0f2e6e8a)) - modified comment for method product, platform and newPage ([#​7262](https://togithub.com/puppeteer/puppeteer/issues/7262)) ([159d283](https://togithub.com/puppeteer/puppeteer/commit/159d2835450697dabea6f9adf6e67d158b5b8ae3)) - **requestinterception:** fix font loading issue ([#​7060](https://togithub.com/puppeteer/puppeteer/issues/7060)) ([c9978d2](https://togithub.com/puppeteer/puppeteer/commit/c9978d20d5584c9fd2dc902e4b4ac86ed8ea5d6e)), closes [/github.com/puppeteer/puppeteer/pull/6996#issuecomment-811546501](https://togithub.com/puppeteer//github.com/puppeteer/puppeteer/pull/6996/issues/issuecomment-811546501) [/github.com/puppeteer/puppeteer/pull/6996#issuecomment-813797393](https://togithub.com/puppeteer//github.com/puppeteer/puppeteer/pull/6996/issues/issuecomment-813797393) [#​7038](https://togithub.com/puppeteer/puppeteer/issues/7038) - drop support for Node.js 10 ([#​7200](https://togithub.com/puppeteer/puppeteer/issues/7200)) ([97c9fe2](https://togithub.com/puppeteer/puppeteer/commit/97c9fe2520723d45a5a86da06b888ae888d400be)), closes [#​6753](https://togithub.com/puppeteer/puppeteer/issues/6753) ##### [9.1.1](https://togithub.com/puppeteer/puppeteer/compare/v9.1.0...v9.1.1) (2021-05-05) ##### Bug Fixes - make targetFilter synchronous ([#​7203](https://togithub.com/puppeteer/puppeteer/issues/7203)) ([bcc85a0](https://togithub.com/puppeteer/puppeteer/commit/bcc85a0969077d122e5d8d2fb5c1061999a8ae48)) </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Never, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-generator-typescript).
See #2905
This change is fully backwards compatible as it defaults to the current behavior.