Why is the playwright chromium instance automatically closing when I iterate over a list of direct downloading links?

  Kiến thức lập trình

I am trying to download files in a loop using playwright. I have to login to salesforce for the first time but after that the links directly download the files.

But in my case the first file completes downloading and then when the browser navigates to the second url I get this pop up saying “Download is in progress. Quit Chromium anyway?”:
Download is in progress. Quit Chromium anyway?

Here’s my code:

from playwright.sync_api import sync_playwright  
import time

# List of URLs  
urls = ["https://test.file.force.com/servlet/servlet.FileDownload?file=some_id_1", "https://test.file.force.com/servlet/servlet.FileDownload?file=some_id_2", "https://test.file.force.com/servlet/servlet.FileDownload?file=some_id_3"]  
  
# Launch the browser  
with sync_playwright() as playwright:  
    browser = playwright.chromium.launch(headless=False)  
    page = browser.new_page()  
    flag = False
    # Iterate over URLs  
    for url in urls:  
        page.goto(url)
        if(not flag):
            page.get_by_placeholder("User Email Address").fill("[email protected]")
            page.get_by_role("button", name="Continue").click()
            page.get_by_placeholder("Password").fill("test#12345")
            page.get_by_role("button", name="SSO Login").click()
            flag = True 
        time.sleep(20)
  
    # Close the browser  
    browser.close()  

LEAVE A COMMENT