-
Notifications
You must be signed in to change notification settings - Fork 248
Reduce allocations made during request interception #946
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
base: main
Are you sure you want to change the base?
Conversation
Stream (to json) the Transfer as a request and response object in the various network interception-related events (e.g. Network.responseReceived). Add a page.request_intercepted boolean flag for CDP to signal the page that requests have been intercepted, allowing Page.wait to prioritize intercept handling (or, at least, not block it).
@krichprollsch , I'd like your input on this. I don't think this is a new issue, just more easily observable with request interception. We currently emit a CDP I think this is different than Chrome, which appears to wait until XHR requests are complete. Although, looking at the Chromium source code, some tests mention/handle possible race conditions between XHR requests and the This comes up because, if you do something: const page = await context.newPage();
await page.route('**/*', async (route, request) => {
setTimeout(() => route.continue(), 2000); // SLEEPING HERE
});
await page.goto('/campfire-commerce/');
await page.close(); It'll definitely call I see two options: 1 - We can change when 2 - We can consider the above playwright script unsupported. After await page.goto('/campfire-commerce/');
// add this
await page.waitForFunction(() => {
const price = document.querySelector('#product-price');
return price.textContent.length > 0;
}, {}, {});
await page.close(); |
Well, sending the I used crush to look at the chromium code, and it said clearly the Does the puppeter example you wrote acts differently with chrome? Is frameStoppedLoading dispatched just after the onload event?Yes, frameStoppedLoading is dispatched very shortly after the onload event, but the exact timing can vary The sequence is:
Key findings:
Practical implications:• frameStoppedLoading indicates the initial document load is complete The events are very close in timing, but frameStoppedLoading should generally come after onload , though the exact Based on my comprehensive analysis of the Chromium codebase, I can now provide a detailed answer about what async What async tasks frameStoppedLoading waits for:The frameStoppedLoading event waits for specific types of load-blocking resources and operations, but NOT for 1. Load-blocking resource types:• Images ( ResourceType::kImage ) 2. Document parsing completion:• parsing_state_ == kFinishedParsing - The HTML parser must be finished 3. Load event delay counters:• Elements that explicitly delay the load event via IncrementLoadEventDelayCount() : 4. Child frame loading:• AllDescendantsAreComplete() - All child frames (iframes) must finish loading 5. Active resource requests:• !Fetcher()->IsInRequestResource() - No resource requests currently being processed 6. JavaScript URL tasks:• !javascript_url_task_handle_.IsActive() - No pending javascript: URL execution What it does NOT wait for:Non-blocking resource types:• Scripts ( ResourceType::kScript ) - handled separately JavaScript-initiated async operations:• XMLHttpRequest calls Summary:frameStoppedLoading waits for the initial document and its critical rendering resources to load, but not for This is why XHR requests in onload handlers can race with frameStoppedLoading - the event fires when the |
@krichprollsch I thought I was seeing that, but I checked again, and it and does not wait for XHR requests. I'm not sure what I thought I saw now. thanks |
Stream (to json) the Transfer as a request and response object in the various network interception-related events (e.g. Network.responseReceived).
Add a page.request_intercepted boolean flag for CDP to signal the page that requests have been intercepted, allowing Page.wait to prioritize intercept handling (or, at least, not block it).