class Scheduler: def __init__(self): self.execution_array: List[Callable[, None]] =  def add_execution(self, fn: List[Callable[, None]] = ): self.execution_array.append(fn) def run(self): while True: if self.execution_array is not None and len(self.execution_array): self.execution_array() self.execution_array.remove(self.execution_array)```
This thread is trying to answer question "Why does Playwright close before another function in a custom scheduler is executed, and how can a browser object be launched and stored for later use without this issue?"
def launch_browser(): # Start Playwright and connect to Chromium browser with playwright.sync_api.sync_playwright() as p: global browser, context, page browser = p.chromium.launch(headless=False) context = browser.new_context(user_agent=random.choice(user_agents)) page = context.new_page() scheduler.add_execution(launch_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 firstname.lastname@example.org.