Coder Social home page Coder Social logo

playwright-ruby-client's Introduction

Gem Version

🎭 Playwright client for Ruby

Getting Started

gem 'playwright-ruby-client'

and then 'bundle install'.

Since playwright-ruby-client doesn't include the playwright driver, we have to install playwright in advance.

npm install playwright
./node_modules/.bin/playwright install

And set playwright_cli_executable_path: './node_modules/.bin/playwright'

Prefer playwrighting without Node.js?

Instead of npm, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from here

Capture a site

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    page = browser.new_page
    page.goto('https://github.com/YusukeIwaki')
    page.screenshot(path: './YusukeIwaki.png')
  end
end

image

Simple scraping

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    page = browser.new_page
    page.goto('https://github.com/')

    page.get_by_placeholder("Search or jump to...").click
    page.locator('input[name="query-builder-test"]').click

    expect(page.keyboard).to be_a(::Playwright::Keyboard)

    page.keyboard.type("playwright")
    page.expect_navigation {
      page.keyboard.press("Enter")
    }

    list = page.get_by_test_id('results-list').locator('.search-title')

    # wait for item to appear
    list.first.wait_for

    # list them
    list.locator('.search-title').all.each do |item|
      title = item.text_content
      puts("==> #{title}")
    end
  end
end
$ bundle exec ruby main.rb
==> microsoft/playwright
==> microsoft/playwright-python
==> microsoft/playwright-cli
==> checkly/headless-recorder
==> microsoft/playwright-sharp
==> playwright-community/jest-playwright
==> microsoft/playwright-test
==> mxschmitt/playwright-go
==> microsoft/playwright-java
==> MarketSquare/robotframework-browser

Android browser automation

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  devices = playwright.android.devices
  unless devices.empty?
    device = devices.last
    begin
      puts "Model: #{device.model}"
      puts "Serial: #{device.serial}"
      puts device.shell('ls /system')

      device.launch_browser do |context|
        page = context.pages.first
        page.goto('https://github.com/YusukeIwaki')
        page.click('header button')
        page.click('input[name="q"]')
        page.keyboard.type('puppeteer')
        page.expect_navigation {
          page.keyboard.press('Enter')
        }
        page.screenshot(path: 'YusukeIwaki.android.png')
      end
    ensure
      device.close
    end
  end
end

android-browser

Android native automation

We have to download android-driver for Playwright in advance.

wget https://github.com/microsoft/playwright/raw/master/bin/android-driver-target.apk -O /path/to/playwright-driver/package/bin/android-driver-target.apk
wget https://github.com/microsoft/playwright/raw/master/bin/android-driver.apk -O /path/to/playwright-driver/package/bin/android-driver.apk

(If you downloaded Playwright via npm, replace /path/to/playwright-driver/package/ with ./node_modules/playwright/ above.)

require 'playwright'

Playwright.create(playwright_cli_executable_path: ENV['PLAYWRIGHT_CLI_EXECUTABLE_PATH']) do |playwright|
  devices = playwright.android.devices
  unless devices.empty?
    device = devices.last
    begin
      device.shell('input keyevent POWER')
      device.shell('input keyevent POWER')
      device.shell('input keyevent 82')
      sleep 1
      device.shell('cmd statusbar expand-notifications')

      # pp device.tree
      # pp device.info(res: 'com.android.systemui:id/clock')
      device.tap_on(res: 'com.android.systemui:id/clock')
    ensure
      device.close
    end
  end
end

Communicate with Playwright server

If your environment doesn't accept installing browser or creating browser process, consider separating Ruby client and Playwright server.

structure

For launching Playwright server, just execute:

npx playwright install && npx playwright run-server --port 8080 --path /ws

and we can connect to the server with the code like this:

Playwright.connect_to_playwright_server('ws://127.0.0.1:8080/ws?browser=chromium') do |playwright|
  playwright.chromium.launch do |browser|
    page = browser.new_page
    page.goto('https://github.com/YusukeIwaki')
    page.screenshot(path: './YusukeIwaki.png')
  end
end

When Playwright.connect_to_playwright_server is used, playwright_cli_executable_path is not required.

For more detailed instraction, refer this article: https://playwright-ruby-client.vercel.app/docs/article/guides/playwright_on_alpine_linux

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Playwright project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

playwright-ruby-client's People

Contributors

abr-storm avatar daguar avatar firien avatar ina-yuzen avatar isimluk avatar jean-francois-labbe avatar knu avatar konnorrogers avatar mdwagner avatar rammpeter avatar rohitpaulk avatar yrgoldteeth avatar yuki24 avatar yusukeiwaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

playwright-ruby-client's Issues

[BUG] exception no such file or directory, chmod '/node_modules/playwright-internal/lib/cli/cli.js' occurred in custom focal docker-image

I have tried to replace python with ruby inside following docker configuration https://github.com/microsoft/playwright/blob/master/utils/docker/Dockerfile.focal

custom Dockerfile

FROM ubuntu:focal
# === INSTALL Node.js ===
ARG PLAYWRIGHT_VERSION=1.14.1
# Install node14
RUN apt-get update && apt-get install -y curl && \
    curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
    apt-get install -y tzdata -y nodejs

# Feature-parity with node.js base images.
RUN apt-get update && apt-get install -y --no-install-recommends git ssh && \
    npm install -g yarn

# Create the pwuser (we internally create a symlink for the pwuser and the root user)
RUN adduser pwuser

# Install Ruby 2.6

RUN apt -y update && apt -y install software-properties-common && apt-add-repository -y ppa:brightbox/ruby-ng && apt -y install ruby2.6


# === BAKE BROWSERS INTO IMAGE ===

ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright

# 1. Add tip-of-tree Playwright package to install its browsers.
#    The package should be built beforehand from tip-of-tree Playwright.

RUN apt-get update && apt-get install -y wget default-jdk \
    && wget -qO /tmp/playwright.tar.gz https://github.com/microsoft/playwright/archive/refs/tags/v"$PLAYWRIGHT_VERSION".tar.gz \
    && tar -xf /tmp/playwright.tar.gz --directory=/tmp/


# 2. Install playwright and then delete the installation.
#    Browsers will remain downloaded in `/ms-playwright`.
#    Note: make sure to set 777 to the registry so that any user can access
#    registry.
RUN mkdir /ms-playwright

RUN mkdir /tmp/pw
RUN cd /tmp/pw
RUN npm init -y
RUN ls -la /tmp/
RUN npm i /tmp/playwright.tar.gz
RUN DEBIAN_FRONTEND=noninteractive npx playwright install-deps
RUN rm -rf /tmp/pw
RUN rm /tmp/playwright.tar.gz
RUN chmod -R 777 /ms-playwright


WORKDIR /workspace

COPY . /workspace

RUN bundle install

CMD ["/bin/bash"]

Describe the bug
When I have tried to build Dockerfile after run npm i /tmp/playwright.tar.gz, exception below occurred.

Step 14/22 : RUN npm i /tmp/playwright.tar.gz
 ---> Running in d8df7ffd946d
npm WARN @1.0.0 No description
npm WARN @1.0.0 No repository field.

npm ERR! code ENOENT
npm ERR! syscall chmod
npm ERR! path /node_modules/playwright-internal/lib/cli/cli.js
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, chmod '/node_modules/playwright-internal/lib/cli/cli.js'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-09-21T11_45_07_551Z-debug.log

undefined method `create' for Playwright:Module (NoMethodError) occurred

Step To Reproduce / Observed behavior

  1. test.rb file created
require 'playwright'

Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    page = browser.new_page
    page.goto('https://github.com/YusukeIwaki')
    page.screenshot(path: './YusukeIwaki.png')
  end
end
  1. Gemfile created with
source 'https://rubygems.org/'

gem 'playwright', '~> 0.1.1'
gem 'capybara-playwright-driver', '~> 0.1.5'

  1. bundle install command called
  2. bundle exec ruby test.rb
    Returned ->

test.rb:3:in <main>': undefined method create' for Playwright:Module (NoMethodError)

Expected behavior

Running at tests as on gif under https://github.com/YusukeIwaki/playwright-ruby-client

Environment

Paste the output of ruby --version

ruby --version
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin20]

Error: Unknown scheme for .initialize

Issue Description

Encounter the error Error: Unknown scheme for .initialize after debugging it seems failing in launching the browser or connecting to the remote server when running it remotely

  • Operating System: Windows
  • Operating System: Linux
  • Node version 12.18.3
  • playwright-ruby-client (1.25.0)

Expected behavior

It should open the browser

Environment

Production
Development
Paste the output of ruby --version
ruby 2.6.6

Below is the code snippet
Screenshot from 2022-08-22 17-04-41

uninitialized constant Playwright::ChannelOwners::WebSocket (NameError)

STEP TO REPRODUCE

page.goto('https://www.websocket.org/echo.html')
page.click('#connect')

#<Thread:0x00007f342403ce60@/home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/transport.rb:53 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
	5: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/transport.rb:53:in `block in async_run'
	4: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/transport.rb:71:in `handle_stdout'
	3: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:13:in `block in initialize'
	2: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:126:in `dispatch'
	1: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:202:in `create_remote_object'
/home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:202:in `const_get': uninitialized constant Playwright::ChannelOwners::WebSocket (NameError)
Did you mean?  Playwright::WebSocket
               Webpacker
	5: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/transport.rb:53:in `block in async_run'
	4: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/transport.rb:71:in `handle_stdout'
	3: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:13:in `block in initialize'
	2: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:126:in `dispatch'
	1: from /home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:201:in `create_remote_object'
/home/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/playwright-ruby-client-0.6.3/lib/playwright/connection.rb:209:in `rescue in create_remote_object': Missing type WebSocket (RuntimeError)

Here's new issue I am getting recently

Invalid JSON being recieved by browerless/chrome

Step To Reproduce / Observed behavior

I've spent a while trying to get to the bottom of this but have exhausted my knowledge here. I have the following docker container running (from my docker-compose.yml file):

browser:
    image: browserless/chrome
    restart: unless-stopped
    environment:
      - DEBUG=*
      - ENABLE_DEBUGGER=true
      - PREBOOT_CHROME=true

By using the documented code snippet I run the following command:

Playwright.connect_to_playwright_server('ws://browser:3000') do |playwright|
  playwright.chromium.launch do |browser|
    page = browser.new_page
    page.goto('https://github.com/YusukeIwaki')
    page.screenshot(path: './YusukeIwaki.png')
  end
end

Which throws the following error:

#<Thread:0x00007fe38023d000 /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_client.rb:101 run> terminated with exception (report_on_exception is true):
/usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/errors.rb:5:in `parse': undefined method `[]' for nil:NilClass (NoMethodError)

      if error_payload['name'] == 'TimeoutError'
                      ^^^^^^^^
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/connection.rb:143:in `dispatch'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/connection.rb:11:in `block in initialize'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_transport.rb:93:in `handle_on_message'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_transport.rb:74:in `block in async_run'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_client.rb:161:in `handle_on_message'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_client.rb:90:in `block in setup'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/event_emitter.rb:39:in `block in emit'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/event_emitter.rb:38:in `each'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/event_emitter.rb:38:in `emit'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/hybi.rb:408:in `emit_message'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/hybi.rb:390:in `emit_frame'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/hybi.rb:118:in `parse'
        from /usr/local/bundle/gems/websocket-driver-0.7.5/lib/websocket/driver/client.rb:63:in `parse'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_client.rb:95:in `wait_for_data'
        from /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_client.rb:102:in `block in start'

The communication is received by the browser docker container as it emits the following messages:

2023-05-01T13:03:59.284Z browserless:job DNUFVB3LDB41LFLPC1655Z2RU8FAATZA: /: Inbound WebSocket request.                                                      
2023-05-01T13:03:59.291Z browserless:hardware Checking overload status: CPU 6% Memory 43%                                                                     
2023-05-01T13:03:59.292Z browserless:job DNUFVB3LDB41LFLPC1655Z2RU8FAATZA: Adding new job to queue.                                                           
2023-05-01T13:03:59.293Z browserless:server Starting new job                                                                                                  
2023-05-01T13:03:59.293Z browserless:system Waiting pre-booted chrome instance                                                                                
2023-05-01T13:03:59.293Z browserless:job DNUFVB3LDB41LFLPC1655Z2RU8FAATZA: Getting browser.                                                                                                                                                
2023-05-01T13:03:59.294Z browserless:system Got chrome instance                                                                                               
2023-05-01T13:03:59.294Z browserless:job DNUFVB3LDB41LFLPC1655Z2RU8FAATZA: Starting session.                                                                  
2023-05-01T13:03:59.294Z browserless:job DNUFVB3LDB41LFLPC1655Z2RU8FAATZA: Proxying request to /devtools/browser route: ws://127.0.0.1:34393/devtools/browser/8251171f-21c8-4194-b0b7-4188ed78eaa2.                                         
2023-05-01T13:03:59.297Z puppeteer:protocol:RECV ◀ [                                                                                                          
  '{"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"30f0f222-cdaa-40e2-9499-0816088ecea7","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}}'                                             
]                                                                                                                                                             
2023-05-01T13:03:59.297Z puppeteer:protocol:RECV ◀ [                                                                                                          
  '{"method":"Target.targetInfoChanged","params":{"targetInfo":{"targetId":"30f0f222-cdaa-40e2-9499-0816088ecea7","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}}'                                          
]

Debugging the issue further up the call stack I can see the following response from the docker container:

Stop by #1  BP - Line  /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_transport.rb:93 (line)
(rdbg) i    # info command
%self = #<Playwright::WebSocketTransport:0x00007faf4a39f9d0 @ws_endpoint="ws://browser:3000/ws", @de...>
data = "{\"id\":1,\"error\":{\"code\":-32600,\"message\":\"Message has property other than 'id', 'met...
obj = {"id"=>1, "error"=>{"code"=>-32600, "message"=>"Message has property other than 'id', 'method',...
@debug = false
@on_driver_crashed = #<Proc:0x00007faf4a7e98b0 /usr/local/bundle/gems/playwright-ruby-client-1.33.0/...>
@on_message = #<Proc:0x00007faf4a7ea3f0 /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/pla...>
@ws = #<Playwright::WebSocketClient:0x00007faf4a39f8e0 @impl=#<Playwright::WebSocketClient::DriverIm...>
@ws_endpoint = "ws://browser:3000/ws"
(rdbg) data
"{\"id\":1,\"error\":{\"code\":-32600,\"message\":\"Message has property other than 'id', 'method', 'sessionId', 'params'\"}}"
(rdbg) 

So it appears we are sending malformed JSON. Setting a breakpoint at web_socket_transport.rb:27 I can see the message we are sending:

Stop by #0  BP - Line  /usr/local/bundle/gems/playwright-ruby-client-1.33.0/lib/playwright/web_socket_transport.rb:27 (line)
(rdbg) message
{:id=>1, :guid=>"", :method=>"initialize", :params=>{:sdkLanguage=>"python"}, :metadata=>{}}

Has something recently changed in the API which is causing the issue?

Expected behavior

To communicate with the websocket service correctly.

Environment

Ruby: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux-musl]
Rails: 7.0.4.2
playwright-ruby-client: 1.33.0
browserless/chrome: latest (Digest:sha256:11a7103f1d40ce3c04dbebdfff3f60fd01d9f1975763957b4557263eb5564c14)

Appreciate any help.

NoMethodError from #trace_discarded

Step To Reproduce / Observed behavior

context = browser.new_context
page = context.new_page

context.tracing.start_chunk
page.click('button')
context.tracing.stop_chunk

raises an exception

     NoMethodError:
       undefined method `trace_discarded' for #<localUtils>
       Did you mean?  tracing_discarded
     # ./lib/playwright/channel_owners/tracing.rb:48:in `do_stop_chunk'

Expected behavior

no error

Environment

Paste the output of ruby --version

$ ruby --version
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin21]

Firefox bug

I tested firefox browser and got issue

Playwright::Error (Error: Navigation failed because page crashed!
=========================== logs ===========================
navigating to "https://be.oui.sncf/en", waiting until "load"
============================================================
Note: use DEBUG=pw:api environment variable to capture Playwright logs.):

Can you please check on your side?

How can I set --use-gl=egl?

Usecase / What to achieve

I want to improve performance

Question

How would I provide --use-gl=egl to the args tp the playwright binary? Read the following; https://michelkraemer.com/enable-gpu-for-slow-playwright-tests-in-headless-mode/

It seems on my M2 Max it is as fast to round headless as in the browser visible ;)

DRIVER_OPTS = {
  playwright_cli_executable_path: "./node_modules/.bin/playwright",
  browser_type: BROWSER,
  headless: HEADLESS,
  slowMo: 60,
  args: %w[--use-gl=egl],
}.freeze

Capybara.register_driver(:playwright) do |app|
  Capybara::Playwright::Driver.new(app, **DRIVER_OPTS)
end

File uploading / downloading

Simple description about the feature

Playwright helps us to automate file uploading / downloading operation, which is not supported in Puppeteer.

       with page.expect_download() as download_info:
            await page.click("text='Download PDF'")
    
        download = download_info.value
        path = download.path()
        with page.expect_file_chooser() as file_chooser:
            page.click('text="Upload File"') 
            file_chooser.value.set_files(files=['/absolute/path/to/large/file'])

Usecase / Motivation

uploading, downloading PDF, CSV, XML, and so on.

Playwright Android doesn't work

Step To Reproduce / Observed behavior

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  devices = playwright.android.devices
  devices.each do |device|
    puts device.model
  end
  devices.map(&:close)
end
$ bundle exec ruby main.rb 
Traceback (most recent call last):
	12: from main.rb:3:in `<main>'
	11: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright.rb:79:in `create'
	10: from main.rb:4:in `block in <main>'
	 9: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright_api/android.rb:30:in `devices'
	 8: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright/channel_owners/android.rb:8:in `devices'
	 7: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright/channel.rb:20:in `send_message_to_server'
	 6: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright/channel.rb:33:in `send_message_to_server_result'
	 5: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright/channel.rb:67:in `with_logging'
	 4: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright/channel.rb:34:in `block in send_message_to_server_result'
	 3: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.20.1/lib/playwright/connection.rb:77:in `send_message_to_server'
	 2: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promises.rb:1471:in `value!'
	 1: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promises.rb:1257:in `wait_until_resolved!'
/Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promises.rb:1257:in `raise': Error: port: expected number, got object (Playwright::Error)

Expected behavior

It works

Environment

Paste the output of ruby --version

Using "check" on radiobutton element leads to ArgumentError: unknown keyword: position

Step To Reproduce / Observed behavior

page.query_selector("#database_modus_host").check
raises "ArgumentError: unknown keyword: position"

It calls
playwright-ruby-client-0.5.2/lib/playwright_api/element_handle.rb:134:in check' which calls playwright-ruby-client-0.5.2/lib/playwright/channel_owners/element_handle.rb:234:in check'
with parameter "position:" which is not defined in element_handle.rb:234

Expected behavior

selecting radio button without error

Environment

Paste the output of ruby --version
jruby-9.2.17.0

Workaround exists in still using click instead of check.

Hang with 'undefined:1'

Step To Reproduce / Observed behavior

RSpec on GitHub Actions often fails with

sometimed driver crashes with the error below.
--------
undefined:1
�
^

SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at Transport.transport.onmessage (/home/runner/work/playwright-ruby-client/playwright-ruby-client/node_modules/playwright/lib/cli/driver.js:42:73)
    at Immediate.<anonymous> (/home/runner/work/playwright-ruby-client/playwright-ruby-client/node_modules/playwright/lib/protocol/transport.js:74:26)
    at processImmediate (internal/timers.js:461:21)

We can also reproduce this issue with bundle exec rspec spec/integration/

Expected behavior

No crash, or retry on crash

Environment

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]

How to run script on opening new page?

driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })
  """
})

Like above, I want to run some script on new document. How can I do this?
Above ruby script is for selenium.

Ctrl+C unexpectedly stops Playwright driver

Step To Reproduce / Observed behavior

ref: YusukeIwaki/puppeteer-ruby#194

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    page = browser.new_page
    binding.irb # Press Ctrl+C here!
    page.goto('https://github.com/YusukeIwaki')
  end
end
irb(main):001:0> 
^C
irb(main):001:0> page.goto('https://github.com/YusukeIwaki')
/Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/transport.rb:36:in `rescue in send_message': send_message failed (Playwright::Transport::AlreadyDisconnectedError)
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/transport.rb:28:in `send_message'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/connection.rb:65:in `block in async_send_message_to_server'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/connection.rb:89:in `with_generated_id'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/connection.rb:51:in `async_send_message_to_server'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/connection.rb:77:in `send_message_to_server'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/channel.rb:34:in `block in send_message_to_server_result'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/channel.rb:67:in `with_logging'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/channel.rb:33:in `send_message_to_server_result'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/channel.rb:20:in `send_message_to_server'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/channel_owners/frame.rb:52:in `goto'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/channel_owners/page.rb:318:in `goto'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright_api/page.rb:606:in `goto'
	from /Users/yusuke-iwaki/Desktop/hoge/main.rb:1:in `block (2 levels) in <main>'
	from <internal:prelude>:5:in `irb'
	from main.rb:6:in `block (2 levels) in <main>'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/playwright_api.rb:121:in `block in wrap_block_call'
	... 25 levels...
/Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/transport.rb:32:in `write': Broken pipe (Errno::EPIPE)
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/transport.rb:32:in `block in send_message'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/transport.rb:31:in `synchronize'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-1.18.1/lib/playwright/transport.rb:31:in `send_message'

Expected behavior

Ctrl+C doesn't stop Playwright driver

Environment

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin21]

Crash: Missing type BrowserContext

Step To Reproduce / Observed behavior

Using playwright-ruby-client with capybara-playwright-driver. It crash with:

#<Thread:0x000055b12519e6b0@/usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/transport.rb:52 run> terminated with exception (report_on_exception is true):
/usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:218:in `rescue in create_remote_object': Missing type BrowserContext (RuntimeError)
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:210:in `create_remote_object'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:132:in `dispatch'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:11:in `block in initialize'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/transport.rb:82:in `handle_stdout'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/transport.rb:52:in `block in async_run'
/usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/channel_owner.rb:6:in `from': undefined method `object' for nil:NilClass (NoMethodError)
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/channel_owners/browser_context.rb:21:in `after_initialize'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/channel_owner.rb:40:in `initialize'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:211:in `new'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:211:in `create_remote_object'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:132:in `dispatch'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/connection.rb:11:in `block in initialize'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/transport.rb:82:in `handle_stdout'
	from /usr/local/rvm/gems/ruby-2.6.10/gems/playwright-ruby-client-1.23.0/lib/playwright/transport.rb:52:in `block in async_run'

Maybe the gem needs a specific version of playwright (just guessing) ?

Expected behavior

Run the test normally :)

Environment

root@2887a861369a:/app# ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [x86_64-linux]

Thanks!

ElementHandle#set_input_files shoula allow Pathname and File

Step To Reproduce / Observed behavior

element = page.query_selector('input')
element.set_input_files(File.new('./test.rb'))

causes

    Errno::ENOENT:
       No such file or directory @ rb_stat_init - # frozen_string_literal: true

File is enumerable. So

if files.is_a?(Enumerable)
this doesn't work as expected.

[3] pry(#<Playwright::InputFiles>)> @files.is_a?(File)
=> true
[4] pry(#<Playwright::InputFiles>)> @files.is_a?(Enumerable)
=> true

Expected behavior

set upload file

Environment

Paste the output of ruby --version

wait_for_load_state(state: "networkidle")

Step To Reproduce / Observed behavior

page.wait_for_load_state(state: 'networkidle')

f:\programming\source\repos\git\dsisnero\scrapers\cwp_scraper>ruby lib\cwp_scraper.rb
f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/concurrent-ruby-1.2.0/lib/concurrent-ruby/
concurrent/promises.rb:1258:in `raise': Navigating frame was detached! (Playwright::FrameAlreadyD
etachedError)
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/concurrent-ruby-1.2.0/lib/con
current-ruby/concurrent/promises.rb:1258:in `wait_until_resolved!'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/concurrent-ruby-1.2.0/lib/con
current-ruby/concurrent/promises.rb:1472:in `value!'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright/channel_owners/frame.rb:142:in `wait_for_load_state'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright/channel_owners/page.rb:343:in `wait_for_load_state'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright_api/page.rb:1479:in `wait_for_load_state'
        from lib/cwp_scraper.rb:40:in `block (2 levels) in <main>'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright/playwright_api.rb:121:in `block in wrap_block_call'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright/channel_owners/browser_type.rb:20:in `launch'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright_api/browser_type.rb:104:in `launch'
        from lib/cwp_scraper.rb:25:in `block in <main>'
        from f:/windows/tools/ruby/Ruby3.2/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.30.0
/lib/playwright.rb:96:in `create'
        from lib/cwp_scraper.rb:7:in `<main>'

Expected behavior

non error

Environment

Paste the output of ruby --version

f:\programming\source\repos\git\dsisnero\scrapers\cwp_scraper>ruby --version
ruby 3.2.0 (2022-12-25 revision a528908271) [x64-mingw-ucrt]

Data seeding creation and clean up

Apologies for the simplistic question as I am not a Ruby or RoR dev.

Your documentation makes no mention of data seeding or data creation and such test automation matters. Which is fine as it may be out of scope and something that is handled and should be known by Rails folks? Maybe?

Am I correct in thinking that the data "aspect" of tests would still be done via tooling in the RoR ecosystem? Factory_bot for example?

I ask because similar tooling to your tool, cypress-on-rails and cypress-rails, seem to at least mention the HOW-TO of data in their READMEs?

Any thoughts on this matter please?

Thank you @YusukeIwaki

Resource temporarily unavailable

@YusukeIwaki

    Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
      playwright.chromium.launch(headless: false) do |browser|
        page = browser.new_page

        page.goto url
        
        scrape page
      end
    end

Here's summary code.
Do I need to add begin...rescue there?

Originally posted by @goldenking0412 in #105 (comment)

response.body stucked/freeze

Step To Reproduce / Observed behavior

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    page = browser.new_page
    page.on("response", ->(response) { puts response.body }) //When I call response.body it get freezed and not returning responsebody
    page.goto('https://github.com/YusukeIwaki/playwright-ruby-client/issues')
    sleep(1)  
  end
end

Expected behavior

page.on("response", ->(response) { puts response.body }) This line should print the response of the api on console

Environment

ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
Paste the output of ruby --version

Clicking on elements that trigger file choosers consecutively cause the process to hang.

Step To Reproduce / Observed behavior

1.) Click button that opens file chooser, select file, click another button that opens file chooser, process hangs.

https://github.com/KonnorRogers/ash-editor/blob/547927784e72990d0a1b0879c062ad3318bef94e/tests/rails/test/system/attachments/attachment_attributes_test.rb#L41-L65

^ Theres an extra "click bold button to fix file chooser" in here.

Expected behavior

It should be expected you choose a file, click another button, open file chooser, choose another button without issue.

Environment

Paste the output of ruby --version

Ruby 3.1.2
Rails 7.0.4
Playwright 1.27.1

Repo: https://github.com/KonnorRogers/ash-editor (need to remove an extra click)

Im not sure if the issue lies with the Playwright-Ruby-Client or with Playwright itself.

Click on link in headless mode only works if directly called on page, but not on element

Step To Reproduce / Observed behavior

Calling click on a Playwright::ElementHandle selected by query_selector in headless Chromium mode leads to:

Playwright::Error: Error: Element is not attached to the DOM
attempting click action
waiting for element to be visible, enabled and stable

In non-headless mode that works.
In contrast using page.click(<selector>) directly works also in headless mode.

Example:
Does not work in headless mode:
page.query_selector('.slick-cell.l0.r0 a:visible').click
Does work in headless mode:
page.click('.slick-cell.l0.r0 a:visible')

Initialization of playwright is done this way:

playwright = Playwright.create(playwright_cli_executable_path: 'npx playwright')
browser  = playwright.playwright.chromium.launch(headless: true)
page = browser.new_page(viewport: { width: 800, height: 500 })
page.set_default_timeout(60000)
page.goto("http://#{host}:#{port}")

Expected behavior

Method click should also work in headless mode if called on elements

Environment

jruby 9.3.3.0 (2.6.8) 2022-01-19 b26de1f5c5 OpenJDK 64-Bit Server VM 17.0.2+0 on 17.0.2+0 +jit [darwin-x86_64]

Error with Rails and Spring: Playwright::Error: Error: stack[60].file: expected string, got object

Step To Reproduce / Observed behavior

Found in YusukeIwaki/capybara-playwright-driver#46
Caused by #168 (from v1.15.beta2)

Prepare Rails application with Spring enabled.
Then launch rails console and paste the code below:

require 'playwright'
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch(headless: false) do |browser|
    page = browser.new_page
    page.goto('https://google.com')
  end
end
SEND>{:id=>3, :guid=>"browser-type@35aa768ca4f2bc303905cfc166d1594d", :method=>"launch", :params=>{:headless=>false}}
RECV>{"id"=>3, "error"=>{"error"=>{"message"=>"stack[60].file: expected string, got object", "stack"=>"Error: stack[60].file: expected string, got object\n    at tString (/Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:48:9)\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:99:21\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validator.js:45:14\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:86:34\n    at Array.map (<anonymous>)\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:86:16\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:77:12\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:99:21\n    at /Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/protocol/validatorPrimitives.js:77:12\n    at DispatcherConnection._validateMetadata (/Users/yusuke-iwaki/Desktop/railsfeature/node_modules/playwright-core/lib/dispatchers/dispatcher.js:227:69)", "name"=>"Error"}}}
Playwright::Error: Error: stack[60].file: expected string, got object
from /Users/yusuke-iwaki/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/concurrent-ruby-1.1.9/lib/concurrent-ruby/concurrent/promises.rb:1257:in `wait_until_resolved!'

Expected behavior

Showing google.com

undefined method `did_launch_browser' for #<>

Step To Reproduce / Observed behavior

require 'playwright'

Playwright.connect_to_browser_server(ENV['BROWSER_SERVER_URL']) do |browser|
  	page = browser.new_page
  	page.goto('https://github.com/YusukeIwaki')
  	page.close
end
$ npx [email protected] launch-server --browser chromium 
ws://127.0.0.1:59237/3f5b568c34a1032be192ec94a4224011
$ BROWSER_SERVER_URL=ws://127.0.0.1:59237/3f5b568c34a1032be192ec94a4224011 bundle exec ruby a.rb 
/Users/yusuke-iwaki/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/playwright-ruby-client-1.34.0/lib/playwright.rb:162:in `connect_to_browser_server': undefined method `did_launch_browser' for #<> (NoMethodError)

        browser.browser_type.send(:did_launch_browser, browser)
                            ^^^^^
	from a.rb:3:in `<main>'

Expected behavior

Successfully connect to browser server.

Environment

Paste the output of ruby --version

$ ruby --version
ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin22]

Browser#new_page error, on Ruby 3.0

/Users/yusuke-iwaki/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-0.0.3/lib/playwright/channel_owners/browser.rb:17:in `new_context': wrong number of arguments (given 1, expected 0) (ArgumentError)
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-0.0.3/lib/playwright/channel_owners/browser.rb:40:in `new_page'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-0.0.3/lib/playwright_api/browser.rb:110:in `new_page'
	from main.rb:5:in `block (2 levels) in <main>'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-0.0.3/lib/playwright/playwright_api.rb:61:in `block in wrap_block_call'
	from /Users/yusuke-iwaki/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/playwright-ruby-client-0.0.3/lib/playwri

Execution commands page.location("[name='search']").visible? or page.query_selector("[name='search']").visible? ended with Timeout error

Step To Reproduce / Observed behavior

require 'playwright'

@playwright_exec = Playwright.create(playwright_cli_executable_path: 'npx playwright')

playwright = @playwright_exec.playwright

browser = playwright.chromium.launch(headless: false, channel: "chrome")
context = browser.new_context
page = context.new_page
page.goto('https://bing.com')
page.location("[name='search']").visible?
image

Expected behavior

True response is occurred.

Environment

Paste the output of ruby --version
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin20]

Support tracing

Simple description about the feature

Playwright driver 1.11 introduces a tracing feature.

Usecase / Motivation

Most users are recommended to use puppeteer for tracing because it is available only in Chrome.
However it is not so bad to support the feature also in playwright which has more user-friendly features (like auto-waiting).

Missing type FetchRequest

Step To Reproduce / Observed behavior

require 'playwright'

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch do |browser|
  	page = browser.new_page
  	page.goto('https://playwright.dev/')
  end
end
$ bundle exec ruby playwright_dev.
Traceback (most recent call last):
/Users/yusuke-iwaki/.rbenv/versions/2.7.2/bin/ruby: No such file or directory -- playwright_dev. (LoadError)
YusukenoMacBook:pl-py yusuke-iwaki $ bundle exec ruby playwright_dev.rb
#<Thread:0x00007f8bc59d1658 /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/transport.rb:52 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
	4: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/transport.rb:52:in `block in async_run'
	3: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/transport.rb:70:in `handle_stdout'
	2: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:11:in `block in initialize'
	1: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:121:in `dispatch'
/Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:197:in `create_remote_object': uninitialized constant Playwright::ChannelOwners::FetchRequest (NameError)
	5: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/transport.rb:52:in `block in async_run'
	4: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/transport.rb:70:in `handle_stdout'
	3: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:11:in `block in initialize'
	2: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:121:in `dispatch'
	1: from /Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:196:in `create_remote_object'
/Users/yusuke-iwaki/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.15.beta2/lib/playwright/connection.rb:204:in `rescue in create_remote_object': Missing type FetchRequest (RuntimeError)

Expected behavior

browser playwright.dev

Environment

Ruby 2.7.2
playwright-ruby-client 1.15.beta2

Cannot connect to Playwright server

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)

1.18.2 以降を Windows Ruby 2.7 で動かすと `wrong exec option symbol: pgroup (ArgumentError)` が発生する

Step To Reproduce / Observed behavior

https://github.com/owayo/playwright-demo

require 'bundler/setup'
require 'playwright'

LAUNCH_PARAMS = {
  headless: false, 
  channel: 'chrome', ignoreDefaultArgs: ['--enable-automation']
}.freeze

Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
  playwright.chromium.launch_persistent_context("./chrome/", **LAUNCH_PARAMS) do |browser|
    browser.new_page.goto("https://www.google.co.jp/")
    sleep 5
  end
end

エラー内容

Traceback (most recent call last):
        6: from main.rb:14:in `<main>'
        5: from D:/msys64/mingw64/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.19.0/lib/playwright.rb:66:in `create'
        4: from D:/msys64/mingw64/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.19.0/lib/playwright/connection.rb:36:in `async_run'
        3: from D:/msys64/mingw64/lib/ruby/gems/2.7.0/gems/playwright-ruby-client-1.19.0/lib/playwright/transport.rb:49:in `async_run'
        2: from D:/msys64/mingw64/lib/ruby/2.7.0/open3.rb:101:in `popen3'
        1: from D:/msys64/mingw64/lib/ruby/2.7.0/open3.rb:213:in `popen_run'
D:/msys64/mingw64/lib/ruby/2.7.0/open3.rb:213:in `spawn': wrong exec option symbol: pgroup (ArgumentError)

Expected behavior

エラーが発生しないこと

Environment

playwright 1.19.0
playwright-ruby-client 1.19.0
(1.18では問題なく動作)
Paste the output of ruby --version
以下の2バージョンでエラーになることを確認

ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]

MacのRubyではエラーが発生しない

ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]

こちらのコミットによるものだと思われます
690501317c0b310c54ebeec05e4a1b59d8665b91

Page#expect_response is not working

Step To Reproduce / Observed behavior

response = page.expect_response(url) do
  page.click('a')
end

This code is expected to trigger clicking the first link, but clicking is not triggered actually.

Expected behavior

Waiting for the response after the action specifed in block.

Environment

Paste the output of ruby --version

Add documentation

Simple description about the feature

Provide API documentations for users.

Usecase / Motivation

Currently API codes are autogen, and users cannot imagine which API is available nor which parameters to set, and so on.

Async scraping

How to write async scraping code?
Can you please give me example?

Resource temporarily unavailable - ./node_modules/.bin/playwright run-driver

I am running playwright scraper in windows. About 5 scraping requests at once.
Did npm install playwright to install playwright in windows

And it works at first.
But after a few mins or few requests, I am getting error
Resource temporarily unavailable - ./node_modules/.bin/playwright run-driver

Can you please check what's wrong with this?

uninitialized constant Playwright::ChannelOwners::Worker (NameError)

Step To Reproduce / Observed behavior

  1. spring rails c
  2. Playwright::ChannelOwners.const_get('Worker')
Stack Trace
 #<Thread:0x00007fa4f9bb30f0 /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/transport.rb:53 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
	5: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/transport.rb:53:in `block in async_run'
	4: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/transport.rb:71:in `handle_stdout'
	3: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:13:in `block in initialize'
	2: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:126:in `dispatch'
	1: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:202:in `create_remote_object'
/Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:202:in `const_get': uninitialized constant Playwright::ChannelOwners::Worker (NameError)
Did you mean?  Playwright::Worker
	5: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/transport.rb:53:in `block in async_run'
	4: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/transport.rb:71:in `handle_stdout'
	3: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:13:in `block in initialize'
	2: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:126:in `dispatch'
	1: from /Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:201:in `create_remote_object'
/Users/amirsharif/.rvm/gems/ruby-2.7.2/gems/playwright-ruby-client-0.6.0/lib/playwright/connection.rb:209:in `rescue in create_remote_object': Missing type Worker (RuntimeError)

Expected behavior

No error.

Environment

ruby 2.7.2p137
Rails 6.1.3.2

[development] Ctrl+C does not stop RSpec execution immediately

Step To Reproduce / Observed behavior

bundle exec rspec

It doesn't stop RSpec execution immediately.

It seems Puma implicitly consumes SIGINT signal
https://github.com/teamcapybara/capybara/blob/0468de5a810aae75ab9de20447e246c5c35473f0/lib/capybara/registrations/servers.rb#L24
https://github.com/puma/puma/blob/3c5d12db6b41e65082a6ed58f247b9ab513effd9/lib/puma/launcher.rb

Expected behavior

Environment

Paste the output of ruby --version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.