playwright
playwright copied to clipboard
[Question] Attaching playwright to an existing electron window?
Hi guys,
I am new on playwright, currently investigate if playwright can connect to an existing electron application? I try to some code:
browser_aut = playwright.chromium.connect("ws://127.0.0.1:8768/devtools/browser/b62e618c-27e9-456a-a0d2-363a27d46755")
Error happen when try to execute it:
**Task exception was never retrieved**
future: <Task finished name='Task-11' coro=<Connection.run.<locals>.init() done, defined at C:\Users\sunme\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py:174> exception=Error('Playwright connection closed')>
Traceback (most recent call last):
File "C:\Users\sunme\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 175, in init
self.playwright_future.set_result(await self._root_object.initialize())
File "C:\Users\sunme\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 135, in initialize
await self._channel.send(
File "C:\Users\sunme\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 39, in send
return await self.inner_send(method, params, False)
File "C:\Users\sunme\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_connection.py", line 63, in inner_send
result = next(iter(done)).result()
File "C:\Users\sunme\AppData\Local\Programs\Python\Python310\lib\site-packages\playwright\_impl\_browser_type.py", line 203, in connect
playwright: "Playwright" = next(iter(done)).result()
playwright._impl._api_types.Error: Playwright connection closed
My electron is start with argument --remote-debugging-port=8768, I want to know if playwright has such feature to attach existing electron app? if not, is any plan to support in future?
@sunmeixia2005 try using chromium.connect_over_cdp instead
@sunmeixia2005 try using
chromium.connect_over_cdpinstead @aslushnikov Thanks for replying.
I try 3 different ways, all of them give some errors:
a. call connect_over_cdp using http endpoint url, not work, error say:
#playwright._impl._api_types.Error: Protocol error (Browser.setDownloadBehavior): Browser context management is not supported.
browser_aut = playwright.chromium.connect_over_cdp("http://localhost:8768")
b. call connect_over_cdp using ws endpoint, not work, error say:
#playwright._impl._api_types.Error: Protocol error (Browser.setDownloadBehavior): Browser context management is not supported.
browser_aut = playwright.chromium.connect_over_cdp("ws://127.0.0.1:8768/devtools/browser/1e139584-1b76-4533-a41f-1c52e802751b")
c. call connect using ws endpoint, also not work, error message is attached in first post, say:
#playwright._impl._api_types.Error: Playwright connection closed
browser_aut = playwright.chromium.connect("ws://127.0.0.1:8768/devtools/browser/1e139584-1b76-4533-a41f-1c52e802751b")
Not sure if this may help, just post there: I start my electron app with --remote-debugging-port as following: electron . --remote-debugging-port=8768
Looks like we have a bug when connecting over CDP to electron or android.
@JoelEinbinder Thanks, look forward the version v1.18 out.
@dgozman , May I know what kind of feedback want to collect? We are in research stage for new product UI automation, it is matter for us if playwright support to attach existing electron or not.
@Sunny1861 Electron is not a priority for Playwright, so I don't expect this to be fixed soon. Especially, without a clear repro script.
May I know what kind of feedback want to collect?
This means we acknowledge the issue, but we'll prioritize it depending on the amount of feedback/similar requests/thumbs up.
Hi, We are also doing some research on UI automation and how to attach to the exist Electron process and for now if we want to use Playwright we can only use electron.launch("main.js"). Actually it works well but it would be better if Playwright support attach to an existing Electron process. @dgozman is there any possiable that playwright will spuuort this? it really matter to us, Thanks.
We have the same issue, please give high priority to this issue. Thanks.
Hi, We are also doing some research on UI automation and how to attach to the exist Electron process and for now if we want to use Playwright we can only use electron.launch("main.js"). Actually it works well but it would be better if Playwright support attach to an existing Electron process. @dgozman is there any possiable that playwright will spuuort this? it really matter to us, Thanks.
We have the same issue, could you leave your email here so that we could discuss about this issue?
We have the same issue. For us this is a blocker to use playwright framework, because we simply can not connect to an instance over remote debugging port. Can you please deal with it with highest priority? Thanks.
Connecting to a running electron application would also be good for us. Generally upping the priority of electron would be great, but that's just my selfish point of view 😁
Not being able to attach Playwright to an existing instance of Electron is a blocker for us too. It would be very much appreciated if this was dealt with with more priority. Thanks.
I don't know how it's going now👍
up vote 👍
Could you share with us why this is a blocker? I.e. why the current functionality when we start up app is not working?
@pavelfeldman This can be one reason: We needed developers to run E2E on their machines without exiting Electron. Running Electron app takes 1 minute (thanks to awesome Webpack masterpiece design!), and building the app takes several minutes (again thanks to the same tool). So, let's say something goes wrong during the test and the developer needs to change E2E or the app to pass the test, it will takes minutes to re-test again. Attaching to the same instance avoid webpack build time and allows using its hot reloading feature and solves this problem. Switching to a faster build tools like Vite is not an option for us at this point.
This case is blocking us from introducing playwright, we must be able to connect to standalone electron app.
Are there any workarounds to achieve this as of today?
up vote 👍
up vote 👍
up vote 👍
@Sunny1861 Electron is not a priority for Playwright, so I don't expect this to be fixed soon. Especially, without a clear repro script.
@dgozman - I created the reproduction scripts: https://github.com/shalak/example-electron
Having electron supported is crucial for my company to migrate from Selenium tests. Is there anything else I could do to help with this?
up vote 👍
up vote 👍
Upvote
Upvote
upvote
upvote
Upvote
Upvote
Yes, this would be very usefull on our use case as well. I'd be open to contribute.