playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Question] Attaching playwright to an existing electron window?

Open Sunny1861 opened this issue 3 years ago • 35 comments

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?

Sunny1861 avatar Nov 17 '21 03:11 Sunny1861

@sunmeixia2005 try using chromium.connect_over_cdp instead

aslushnikov avatar Nov 17 '21 17:11 aslushnikov

@sunmeixia2005 try using chromium.connect_over_cdp instead @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

Sunny1861 avatar Nov 18 '21 01:11 Sunny1861

Looks like we have a bug when connecting over CDP to electron or android.

JoelEinbinder avatar Nov 19 '21 17:11 JoelEinbinder

@JoelEinbinder Thanks, look forward the version v1.18 out.

Sunny1861 avatar Nov 20 '21 02:11 Sunny1861

@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 avatar Dec 10 '21 05:12 Sunny1861

@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.

dgozman avatar Dec 10 '21 15:12 dgozman

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.

J1s0n avatar Dec 13 '21 02:12 J1s0n

We have the same issue, please give high priority to this issue. Thanks.

970263611 avatar Feb 07 '22 08:02 970263611

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?

970263611 avatar Feb 07 '22 08:02 970263611

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.

marufrasully avatar Feb 25 '22 16:02 marufrasully

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 😁

Reed88 avatar May 20 '22 15:05 Reed88

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.

Finedas avatar May 23 '22 13:05 Finedas

I don't know how it's going now👍

luxuncang avatar Jun 09 '22 08:06 luxuncang

up vote 👍

mohghaderi avatar Jul 13 '22 19:07 mohghaderi

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 avatar Feb 03 '23 18:02 pavelfeldman

@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.

mohghaderi avatar Feb 03 '23 18:02 mohghaderi

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?

shalak avatar Mar 21 '23 19:03 shalak

up vote 👍

abhinaba-ghosh avatar May 16 '23 20:05 abhinaba-ghosh

up vote 👍

lindon0390 avatar May 17 '23 05:05 lindon0390

up vote 👍

AlexandrDimenko avatar Jul 26 '23 10:07 AlexandrDimenko

@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?

shalak avatar Jul 26 '23 14:07 shalak

up vote 👍

geo-kurian avatar Aug 06 '23 10:08 geo-kurian

up vote 👍

kyrvlasiuk avatar Aug 10 '23 15:08 kyrvlasiuk

Upvote

lixingxing1231 avatar Aug 31 '23 08:08 lixingxing1231

Upvote

vrknetha avatar Aug 31 '23 08:08 vrknetha

upvote

WorldWarriorIII avatar Sep 13 '23 08:09 WorldWarriorIII

upvote

SepOrange avatar Nov 01 '23 04:11 SepOrange

Upvote

neemspees avatar Jan 07 '24 10:01 neemspees

Upvote

crazymonkey avatar Aug 06 '24 04:08 crazymonkey

Yes, this would be very usefull on our use case as well. I'd be open to contribute.

teo-anastasiadis avatar Aug 06 '24 08:08 teo-anastasiadis