Playwright works locally, but fails once deployed on to Google Run

I developed and successfully tested a python script locally that uses Playwright for web scraping.

TLDR: Python script logs into a website, goes to a different page, clicks on a few links and then downloads a CSV
file, which will ultimately be pushed into a Google Big Query Table,
but for the moment, it will simply be returned to the browser for testing
purposes…

I created a dockerfile and pushed the container to the Google Artifact Registry. Finally I deployed the service to Google Run.

here is the main.py

from flask import Flask, request, abort, Response
from playwright.async_api import async_playwright
import asyncio
import pandas as pd
import io

app = Flask(__name__)

# Declare the username and password directly in the code
USERNAME = ""
PASSWORD = ""
DASHBOARD = ""

@app.route('/')
def home():
    return 'Flask is running! Visit /csvdata?url=<your-url> to capture and view the CSV data.'

@app.route('/csvdata')
def capture_and_display_csv():
    # Get the URL from the query string
    url = request.args.get('url')
    
    if not url:
        return abort(400, description="URL parameter is required")
    
    # Run the function to get the CSV data
    csv_data = asyncio.run(get_csv_data(url))
    
    # Convert DataFrame to HTML for display (or just return as plain text)
    csv_html = csv_data.to_html()  # Or use csv_data.to_string() for plain text
    
    return Response(csv_html, mimetype='text/html')

async def get_csv_data(url):
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        page.set_default_timeout(600000)
        
        await page.goto(url, timeout=600000)
        
        # Enter the username and password
        await page.fill('#username', USERNAME)
        await page.fill('#password input', PASSWORD)
        
        # Click the login button
        await page.click('button[type="button"]')        
        await page.wait_for_selector('div.randomDOM"]', timeout=600000)   
        await page.goto(DASHBOARD, timeout=600000)

        await page.click('a.step1')
        await page.click('a.step2')
        await page.click('a.step3')
        await page.click('a.download_link')
        
        # Wait for the download to complete
        download = await page.wait_for_event('download', timeout=600000)
        
        # Save the file content to a variable
        csv_content = await download.path()
        
        # Read the CSV content into a pandas DataFrame
        df = pd.read_csv(csv_content)
        await browser.close()
        return df

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8080)

here is the requirements.txt

Flask==2.3.2
playwright==1.39.0
pandas==2.0.3
numpy==1.25.2

As per the question, the problem is that once deployed on Google Run the script times out (in quite a strange fashion, it seems to timeout initially, and then makes a second attempt that also timesout). The logs dont reveal anything that actually fails, in fact as per the below, the logs suggest that the run completed successfully with a 200 document response:

I have cranked up the resources on the Google Run to 8GIG Memory, 8CPUS and 3600 Request Timeout (max), and also as per the code above, explicitly put timeout of page and all wait functions to 10 mins – non of these has yielded a result. Hoping someone knows how to make this work or has any ideas.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật