Giter Club home page Giter Club logo

Comments (7)

iainbeeston avatar iainbeeston commented on May 19, 2024 1

I hope you don't mind @sj26 but I've raised a PR using your code, as I'd like to use it in my own project, and I figured if I was editing the code anyway I might as well raise it as a PR. I've credited you in the commit message. Let me know if you object and I'll close it right away.

FYI I've updated it slightly to use a monotonic clock (rather than CPU time) as suggested in this blog post.

from cuprite.

sj26 avatar sj26 commented on May 19, 2024

If I start a process manually it starts fine:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --disable-gpu --hide-scrollbars --mute-audio --enable-automation --disable-web-security --window-size=1024,768 --remote-debugging-port=0 --remote-debugging-address=127.0.0.1
[0118/155835.406981:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/sv/kt7w98jx5zj16c4whzrwmx9m0000gn/T/: Operation not permitted (1)
[0118/155835.408449:ERROR:file_io.cc(89)] ReadExactly: expected 8, observed 0
[0118/155835.408905:ERROR:xattr.cc(64)] setxattr org.chromium.crashpad.database.initialized on file /var/folders/sv/kt7w98jx5zj16c4whzrwmx9m0000gn/T/: Operation not permitted (1)
[0118/155835.451772:WARNING:dns_config_service_posix.cc(182)] dns_config has unhandled options!
[0118/155835.452613:ERROR:gpu_process_transport_factory.cc(967)] Lost UI shared context.

DevTools listening on ws://127.0.0.1:50152/devtools/browser/bc758536-c437-49af-8f04-359421e57c5d

I think it's just aborting too early. It looks like it tries to read up to 3 times, but I think the read will return when it encounters a newline, so perhaps it needs to be time based instead of attempt-count based.

from cuprite.

sj26 avatar sj26 commented on May 19, 2024

Confirmed, changing attempts from 3 to 10 gets it working

from cuprite.

sj26 avatar sj26 commented on May 19, 2024

Making this based on elapsed cpu time seems sensible. This works well for me:

      def parse_ws_url(read_io)
        output = ""
        start = ::Process.clock_gettime(::Process::CLOCK_PROCESS_CPUTIME_ID)
        timeout = start + 1.0
        regexp = /DevTools listening on (ws:\/\/.*)/
        while (now = ::Process.clock_gettime(::Process::CLOCK_PROCESS_CPUTIME_ID)) < timeout
          begin
            output += read_io.read_nonblock(512)
          rescue IO::WaitReadable
            IO.select([read_io], nil, nil, timeout - now)
          else
            if output.match?(regexp)
              @ws_url = Addressable::URI.parse(output.match(regexp)[1])
              @host = @ws_url.host
              @port = @ws_url.port
              break
            end
          end
        end

        unless @ws_url
          raise "Chrome process did not produce websocket url within 1 second"
        end
      end

from cuprite.

route avatar route commented on May 19, 2024

I decided to drop everything Chrome produces, didn't find anything important there except ws_url.
I like your solution, do you want to open a PR?

from cuprite.

iainbeeston avatar iainbeeston commented on May 19, 2024

For what it's worth I'm seeing this as well. Both solutions (increasing attempts to 10 and @sj26 's while loop) work on my project.

from cuprite.

route avatar route commented on May 19, 2024

Closing this after merging #24

from cuprite.

Related Issues (20)

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.