Skip to content
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

Cannot connect to Playwright server #254

Closed
alxppp opened this issue Jun 14, 2023 · 3 comments
Closed

Cannot connect to Playwright server #254

alxppp opened this issue Jun 14, 2023 · 3 comments
Labels
question Further information is requested

Comments

@alxppp
Copy link

alxppp commented Jun 14, 2023

Usecase / What to achieve

Connect client to a Playwright server on the same Docker network.

Question

I'm running into the following error when connecting to a Playwright server:

irb(main):012:1* Playwright.connect_to_browser_server('ws://playwright:8080') do |browser|
irb(main):013:1*   page = browser.new_page
irb(main):014:1*   page.goto('https://github.com/YusukeIwaki')
irb(main):015:1*   page.screenshot(path: 'YusukeIwaki.png')
irb(main):016:0> end
Traceback (most recent call last):
       11: from /usr/local/bin/irb:23:in `<main>'
       10: from /usr/local/bin/irb:23:in `load'
        9: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        8: from (irb):11
        7: from (irb):12:in `rescue in irb_binding'
        6: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright.rb:160:in `connect_to_browser_server'
        5: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/connection.rb:50:in `initialize_playwright'
        4: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/connection.rb:104:in `send_message_to_server'
        3: from /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promises.rb:1472:in `value!'
        2: from /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promises.rb:1258:in `wait_until_resolved!'
        1: from /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promises.rb:1258:in `raise'
Playwright::Error (TypeError: Cannot read properties of undefined (reading 'launch'))

Same error when using the connect_to_playwright_server method:

irb(main):009:1* Playwright.connect_to_playwright_server('ws://playwright:8080') do |playwright|
irb(main):010:2*   playwright.chromium.launch do |browser|
irb(main):011:2*     page = browser.new_page
irb(main):012:2*     page.goto('https://github.com/YusukeIwaki')
irb(main):013:2*     page.screenshot(path: './YusukeIwaki.png')
irb(main):014:1*   end
irb(main):015:0> end
Traceback (most recent call last):
       10: from /usr/local/bin/irb:23:in `<main>'
        9: from /usr/local/bin/irb:23:in `load'
        8: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        7: from (irb):9
        6: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright.rb:123:in `connect_to_playwright_server'
        5: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/connection.rb:50:in `initialize_playwright'
        4: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/connection.rb:104:in `send_message_to_server'
        3: from /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promises.rb:1472:in `value!'
        2: from /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promises.rb:1258:in `wait_until_resolved!'
        1: from /usr/local/bundle/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/promises.rb:1258:in `raise'
Playwright::Error (TypeError: Cannot read properties of undefined (reading 'launch'))

It doesn't seem to be the connection that's not working, when I turn off the Playwright server, I'm getting a different error:

Traceback (most recent call last):
        9: from /usr/local/bin/irb:23:in `<main>'
        8: from /usr/local/bin/irb:23:in `load'
        7: from /usr/local/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        6: from (irb):16
        5: from (irb):17:in `rescue in irb_binding'
        4: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright.rb:156:in `connect_to_browser_server'
        3: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/connection.rb:39:in `async_run'
        2: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/web_socket_transport.rb:58:in `async_run'
        1: from /usr/local/bundle/gems/playwright-ruby-client-1.34.0/lib/playwright/web_socket_transport.rb:84:in `rescue in async_run'
Playwright::WebSocketClient::TransportError (Connection refused - connect(2) for "playwright" port 8080)
@alxppp alxppp added the question Further information is requested label Jun 14, 2023
@YusukeIwaki
Copy link
Owner

YusukeIwaki commented Jun 18, 2023

It seems the specification of playwright run-server was changed in 1.35.0

@YusukeIwaki
Copy link
Owner

YusukeIwaki commented Jun 19, 2023

@alxppp It seems export PW_EXTENSION_MODE=1 would enable playwright server feature. However it is a little strange.
microsoft/playwright#23215

Please keep playwright driver version at 1.34.x at this moment by explicitly specifying the version playwright@1.34.3.


Playwright server feature is just an internal feature of Playwright test runner and can be changed unexpectedly.

Browser server is a good alternative.

npx playwright@1.35.0 launch-server --browser chromium 

However playwright-ruby-client 1.34 is buggy #256, it will be fixed in 1.35. Sorry for inconvenience.

@alxppp
Copy link
Author

alxppp commented Jun 26, 2023

Thanks a lot for the quick response @YusukeIwaki.

Please keep playwright driver version at 1.34.x at this moment by explicitly specifying the version playwright@1.34.3.

Unfortunately, I get the same error on 1.34.3.

But I switched to browser server after you published the 1.35 gem version, and everything is working again – thank you!

@alxppp alxppp closed this as completed Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants