Adding extension causes extra unwanted blank page to open and extension's opened page becomes a 'ghost' page and is completely unreachable!
See original GitHub issueOn JavaScript adding an extension which opens ‘welcome’ page such as MetaMask => extension opens 1 new page and you can close this page and the default page.
On Playwright Python adding an extension which opens ‘welcome’ page such as MetaMask => extension opens 1 extra blank page (2 blank pages / total) and a new ‘extension’ ‘ghost’ page which is unnaccessible from Playwright Python and you cannot close it.
I briefly mentioned this issue on https://github.com/microsoft/playwright-python/issues/681 where the developer who got assigned fixed my main issue in the title but skimmed over this issue. The developer’s given fix only fixed browser.close()
raising errors => into => not raising errors, but not this issue. This issue is still ‘at large’ (i.e. especially of a criminal or dangerous animal) at liberty; escaped or not yet captured.)
PROBLEM: this bug causes an unaccessible ‘extension’ page to just hang there and I cannot close it using code. It’s not inside browser.pages
.
Illustrative image sets with descriptive captions:
-
Playwright JS https://imgur.com/a/X13eydu
-
Playwright Python https://imgur.com/a/mkINpWl
EDIT: adding source as by confusing from @pavelfeldman 's reply
import playwright
from playwright.sync_api import sync_playwright
EXT_1_DIR = "C:/Users/PC/Desktop/PW_PY/metamask_unpck"
USER_DIR = "C:/Users/PC/AppData/Local/Google/Chrome/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()
EDIT: update to @pavelfeldman 's input.
new source
import playwright
from playwright.sync_api import sync_playwright
EXT_1_DIR = "C:/Users/PC/Desktop/PW_PY/metamask_unpck"
USER_DIR = "C:/Users/PC/AppData/Local/Google/Chrome/User Data/Profile 2"
ARGS = [
"--disable-extensions-except={}".format(EXT_1_DIR),
"--load-extension={}".format(EXT_1_DIR)
]
with sync_playwright() as p:
# 1) launch MetaMask
browser = p.chromium.launch_persistent_context(USER_DIR, headless=False, args=ARGS)
_ = input("Wait till Metamask loads? ")
# 2) print len() pages and bg_pagesshould be 2, but is 1 (bug)
print("len_pages()", len(browser.pages))
print("len_background_pages()", len(browser.background_pages))
_ = input("Close pages? ")
# 2.1) pages don't get closed, only blank page is detected and closed, 2nd page does not get detected,
# or, closed
for pg in browser.pages:
pg.close()
# 3) close the browser, old bug error on closing was fixed by your dev - all good- thanks him
_ = input("Close browser? ")
browser.close()
As we see, the page doesn’t fall into browser.background_pages
it’s just not there. Also, note, for Playwright JS it falls into normal pages.
Illustrative screenshot: https://imgur.com/a/Yh1BIQr
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (7 by maintainers)
Hi, I will get back to you, probably in a few days and probably add some tests from upstream around it to ensure this works. Sorry for the inconveniences!
Closing since the issue seemed stale as part of the triage process. Please create a new issue if the issue is still persistent.