Skip to content

Error accessing page and error closing browser if extension is loaded: "AttributeError: 'NoneType' object has no attribute '_pages'" #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ivarsj10s opened this issue May 11, 2021 · 3 comments · Fixed by #685
Assignees
Labels

Comments

@ivarsj10s
Copy link

ivarsj10s commented May 11, 2021

Hi!

Both for sync api and async api I have the same error, happens about 80% of the time. browser.close() will produce AttributeError: 'NoneType' object has no attribute '_pages' where stack trace comes outside of my script and I cannot catch it with try: except AttributeError within my code.

On top of this, playwright-python opens a new blank page + metamask page (not-expected); JS Playwright only opens + metamask page.

Extensions I used are 1) Metamask;

I cannot access the page, PlayWright shows 3 pages visually but lists only 2, only the blank ones; MetaMask page is both non-accessible and also 80% of the time raises outside-script stack trace from browser closed "AttributeError: 'NoneType' object has no attribute '_pages'"

from playwright.sync_api import sync_playwright

# these need to be replaced to your ones; Metamask unpacked can be downloaded here
# https://github.com/MetaMask/metamask-extension/releases/tag/v9.5.0
EXT_1_DIR = "C:/Users/<individual_path>/metamask_unpck"
USER_DIR = "C:/Users/<individual_path>/User Data/Profile 2"

ARGS = [
    "--disable-extensions-except={}".format(EXT_1_DIR),
    "--load-extension={}".format(EXT_1_DIR)
]

with sync_playwright() as p:
    browser = p.chromium.launch_persistent_context(USER_DIR, headless=False, args=ARGS)
    page = browser.new_page()
    _ = input("Wait till Metamask loads? ")
    print("len_pages()", len(browser.pages))
    for pg in browser.pages:
    	pg.close()

    _ = input("Close browser? ")
    browser.close()

This issue is playwright-python specific and there's no issue on playwright-for-javascript pls help. The issue is the same for both sync_api and async_api but I used sync_api in this example as it's a tad simpler and a tad less code.

Here's illustrated powershell output screenshot;
https://imgur.com/a/iMDSPcS

OS: Windows 10, playwright-python 1.11.0; Python 3.9

PROBLEM TL;DR: prevents me from using MetaMask extension and raises error on browser.close() on top - an issue I don't have in PlayWright for JS. Prob. same issue on other than MetaMask extensions as well, but I didn't have time to bulk up the sample.

@mxschmitt
Copy link
Member

@ivarsj10s it should be fixed when you install it via GitHub: pip install git+https://github.com/microsoft/playwright-python.git

@ivarsj10s
Copy link
Author

@ivarsj10s it should be fixed when you install it via GitHub: pip install git+https://github.com/microsoft/playwright-python.git

I can't install via the method you provided, neither on Windows 10 (tried 2 computers) nor on Linux, these are illustrated stack traces. https://imgur.com/a/HOHAieV Let me know if you need full stack traces

I still 'installed' your fix via manually modifying playwright-python inside Python Lib, line by line as commit lists the changes vs the prev. version. Your fix fixes the issue in the title of not raising error on closing the browser. However, playwright python opening more tabs and MetaMask tab being unreachable is still an issue and I opened a new issue to target just that #681

Questions:

  1. what OS / setup do I need to actually be able to run your pip install git+https://github.com/microsoft/playwright-python.git command successfully?
  2. approx when will your commit get merged into main branch so I can normal pip install such as pip install playwright-python?

@lafftar
Copy link

lafftar commented May 24, 2021

@ivarsj10s it should be fixed when you install it via GitHub: pip install git+https://github.com/microsoft/playwright-python.git

I can't install via the method you provided, neither on Windows 10 (tried 2 computers) nor on Linux, these are illustrated stack traces. https://imgur.com/a/HOHAieV Let me know if you need full stack traces

I still 'installed' your fix via manually modifying playwright-python inside Python Lib, line by line as commit lists the changes vs the prev. version. Your fix fixes the issue in the title of not raising error on closing the browser. However, playwright python opening more tabs and MetaMask tab being unreachable is still an issue and I opened a new issue to target just that #681

Questions:

  1. what OS / setup do I need to actually be able to run your pip install git+https://github.com/microsoft/playwright-python.git command successfully?
  2. approx when will your commit get merged into main branch so I can normal pip install such as pip install playwright-python?

I have the same exact problem, I would also like to know when this change will be pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants