Hello,
I don’t understand why i have a number of request different between Playwright with Chromium and my browser.
When I open the Web developer console, in the Network tab I can see 92 requests 1.2 MB transfered.
By with Playwright with Chromium, I only count 30 requests.
Below is my code and I attache a picture of the Web developer console.
I tried to calculate the size of the home page with 2 different methods intercept_response() intercept_requestfinished() I don’t have the same result with theses methods as I have in a real brower. I’m doing it in the wrong way ?
Thanks
######################################## from playwright.sync_api import sync_playwright import time
full_size = 0 requests_nb = 0
def intercept_response(response): global full_size, requests_nb size = len(response.body()) print(response.headers_array()) print(response) full_size += size requests_nb += 1
def intercept_requestfinished(request): global full_size, requests_nb sizes = request.sizes() print(request.url + " " + str(sizes)) full_size += sizes['responseBodySize'] + sizes['requestHeadersSize'] requests_nb += 1
with sync_playwright() as p: browser = p.chromium.launch_persistent_context( "", headless=False, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.21 Safari/537.36" ) browser = p.chromium.launch() page = browser.new_page() page.set_viewport_size({"width": 1920, "height": 1080}) # Maximum time in milliseconds page.set_default_timeout(10000)
# page.on("response", intercept_response)
page.on("requestfinished", intercept_requestfinished)
page.goto('https://www.bureau-traduction.eu')
time.sleep(1)
page.screenshot(path="gtp.png")
page.remove_listener("requestfinished", intercept_requestfinished)
browser.close()
print("Full size : " + str(full_size)) print("Requests : " + str(requests_nb))
This thread is trying to answer question "Why is there a difference in the number of requests and page size between Playwright with Chromium and a regular browser?"
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].