-
Notifications
You must be signed in to change notification settings - Fork 1k
Adding extension causes extra unwanted blank page to open and extension's opened page becomes a 'ghost' page and is completely unreachable! #689
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
Comments
I don't think I get it. Your Python script has an extra As for the bg page, it lands in a separate collection: https://playwright.dev/python/docs/next/api/class-browsercontext#browser_contextbackground_pages |
It doesn't land in Good spot, the two tabs is my mistake. MetaMask tab being unreachable tho' - still the issue there. I'm pretty certain it's a bug. Unless you can provide me another way to access this page (that I don't know of) - then I could use to work around this issue. |
Probably you are affected by this bug: microsoft/playwright#2676 Something like that works for me, I've added the wait_for_event call to wait until we got a background page: 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/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:
context = p.chromium.launch_persistent_context(USER_DIR, headless=False, args=ARGS)
context.wait_for_event("backgroundpage")
print("len_pages()", len(context.pages), len(context.background_pages))
for pg in context.pages:
pg.close()
_ = input("Close browser? ")
context.close() |
@mxschmitt I tried your snippet, len works; but I'm unable to do anything on this background page. I cannot close it using also, the me being unable to close it using code is the biggest issue for me. illustrative images: |
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! |
Hi! Yeah that's fine. I'll monitor this thread and check with what you come up. Thanks! |
I have the assumption you don't want to interact with the background page, more you want to interact with the extension itself. I tried the following which worked for me: with sync_playwright() as p:
context = p.chromium.launch_persistent_context(USER_DIR, headless=False, args=ARGS)
page = context.wait_for_event("page")
print(page.title())
page.click("text=Get Started")
page.click("text=Import wallet")
page.click("text=I Agree")
context.close() Let me know about your use-case, thanks! |
@mxschmitt as per my exact use case; 1) I wanna log in to the extension's opened page, 2) then close it. Your solution works, but I don't get it. Why does What's the internal logic behind this behavior? Especially if it's not a bug; I just don't get how / why it works in this exact way? |
@mxschmitt on your prev. question. I don't know the web /slash/ extension making internals good enough, I don't know in-an-actual-sense what a background page is. So apologies if my answer to your prev. question is a bit naive and not tech-savvy. |
(I'm no Chromium extension expert) From my understanding background pages are non-user facing scripts which extensions can use to hook into the Chromium extension API etc. In your case, you want to automate the user-facing part of the extension, so this is a regular page. Coming back to the question why wait_for_event("page"). This is because the page in your extension get's created asynchronously and takes some time to initialize. You could also use a while loop and check e.g. every 100ms if len(context.pages) == 2 but we emit the pages event when new pages get created, so it's probably better. The reason because time.sleep(5) is not working is probably because it halts the whole execution and we internally use greenlet to schedule new incoming events which would add it to context.pages. |
@mxschmitt thanks for your input; but My code.
and then I use this one instead of |
Okay, sorry for the delay. The issue is that time.sleep blocks the whole thread and does not allow other asynchronous operations to process. To bypass that you should use page.wait_for_timeout(5000), I will add that to the known issues section. |
Thanks; please leave this as 'triaging' for longer for now. I need more time given to me to practically try out the your adviced on using |
Closing since the issue seemed stale as part of the triage process. Please create a new issue if the issue is still persistent. |
Uh oh!
There was an error while loading. Please reload this page.
On 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 #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
EDIT: update to @pavelfeldman 's input.
new source
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
The text was updated successfully, but these errors were encountered: