Coder Social home page Coder Social logo

tomassurin / chrome-remote-interface Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrewvy/chrome-remote-interface

0.0 0.0 0.0 285 KB

Elixir Client for the Chrome Debugger Protocol

Home Page: https://hexdocs.pm/chrome_remote_interface

Elixir 100.00%

chrome-remote-interface's Introduction

Chrome Remote Interface

CircleCI

This library provides an Elixir Client to the Chrome Debugging Protocol with a small layer of abstraction for handling and subscribing to domain events.

Note: This is a super minimal client wrapper around the Chrome Debugging Protocol.

Installation

Add :chrome_remote_interface to your mix.exs file!

def deps do
  [
    {:chrome_remote_interface, "~> 0.4.1"}
  ]
end

Chrome DevTools Protocol Selection

Chrome Remote Interface generated its API at compile time from the protocol definition released by the Chrome DevTools Team. For more info see: https://chromedevtools.github.io/devtools-protocol/

This can be overridden by setting CRI_PROTOCOL_VERSION environment variable to:

  • 1-2
  • 1-3 * default
  • tot

Example:

CRI_PROTOCOL_VERSION=1-2 mix compile
CRI_PROTOCOL_VERSION=1-3 mix compile
CRI_PROTOCOL_VERSION=tot mix compile

Usage

Note: In these examples, it assumes you're already running chrome headless with remote debugging enabled.

chrome --headless --disable-gpu --remote-debugging-port=9222

Basic API

# ChromeRemoteInterface works off by creating a Session to the remote debugging port.
# By default, connects to 'localhost:9222
iex(1)> server = ChromeRemoteInterface.Session.new()
%ChromeRemoteInterface.Server{host: "localhost", port: 9222}

iex(2)> {:ok, pages} = ChromeRemoteInterface.Session.list_pages(server)
{:ok,
 [%{"description" => "",
    "devtoolsFrontendUrl" => "/devtools/inspector.html?ws=localhost:9222/devtools/page/d4357ff1-47e8-4e53-8289-fc54089da33e",
    "id" => "d4357ff1-47e8-4e53-8289-fc54089da33e", "title" => "Google",
    "type" => "page", "url" => "https://www.google.com/?gws_rd=ssl",
    "webSocketDebuggerUrl" => "ws://localhost:9222/devtools/page/d4357ff1-47e8-4e53-8289-fc54089da33e"}]}

# Now that we have a list of pages, we can connect to any page by using their 'webSocketDebuggerUrl'
iex(3)> first_page = pages |> List.first()
iex(4)> {:ok, page_pid} = ChromeRemoteInterface.PageSession.start_link(first_page)

# Any methods from https://chromedevtools.github.io/devtools-protocol/1-2/ should be available
# to execute on that Page.

# 'Page.navigate'
iex(5)> ChromeRemoteInterface.RPC.Page.navigate(page_pid, %{url: "https://google.com"})
%{"id" => 1, "result" => %{"frameId" => "95446.1"}}

# 'Page.printToPDF'
iex(6)> ChromeRemoteInterface.RPC.Page.printToPDF(page_pid, %{})
{:ok, %{"id" => 2, "result" => %{"data" => "JVBERi0xLj..."}}}

chrome-remote-interface's People

Contributors

andrewvy avatar bcardarella avatar holsee avatar jackalcooper avatar refriedchicken avatar

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.