-1

I have a interface which has a button that closes the playwright context and browser, but when i close it, a lot of exceptions (because the playwright browser and context were closed during some actions) are raised and i couldn't ignore them with try/except. This is a problem because the exceptions always shutdown the interface window. Here is a sample of code:

def close_playwright():
    context.close()
    browser.close()

playwright = sync_playwright().start() 
browser = playwright.webkit.launch()
context = self.browser.new_context(java_script_enabled=False)
page = context.new_page()
page.goto("https://example.com")
# do something 
# sometime close_playwright() is called and the exceptions are raised

1 Answers1

0

I found out that the problem was i was trying to close the context before closing the page first, and that was the thing which raises unhandleable exceptions. The solution is replacing the close_playwright() function with this:

def close_playwright():

    page.close()
    context.close()
    browser.close()
    playwright.dispose()