Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ screenshot = client.sessions.action(session_id, "screenshot", "fullPage" => true
client.sessions.close(session_id)
```

### CDP Sessions

Pass `"cdp" => true` when creating a browser session to get a Chrome DevTools Protocol connection URL in the response.

```ruby
session = client.sessions.create(
"maxTtlSeconds" => 300,
"cdp" => true
)

connect_url = session["session"]["connect_url"] || session["session"]["connectUrl"]
```

CDP sessions cannot be combined with `proxy` or `bypassBotDetection`.

## Configuration Options

### Constructor Options
Expand Down
36 changes: 36 additions & 0 deletions spec/capture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,42 @@ def initialize(body)
expect(Net::HTTP).to have_received(:start).with("edge.test", 443, use_ssl: true)
end

it "creates a CDP session with cdp enabled" do
stub_const("Capture::EDGE_URL", "https://edge.test")
client = Capture.new("user_123", "secret")
requests = []
http = double("http")
response = FakeSessionSuccess.new("201", JSON.generate(
"success" => true,
"session" => {
"id" => "sess_cdp",
"status" => "active",
"connectUrl" => "wss://edge.capture.page/v1/sessions/sess_cdp/cdp"
}
))

allow(http).to receive(:request) do |request|
requests << request
response
end
allow(Net::HTTP).to receive(:start).and_yield(http)

result = client.sessions.create("maxTtlSeconds" => 300, "cdp" => true)

expect(result).to eq(
"success" => true,
"session" => {
"id" => "sess_cdp",
"status" => "active",
"connectUrl" => "wss://edge.capture.page/v1/sessions/sess_cdp/cdp"
}
)
expect(requests.first).to be_a(Net::HTTP::Post)
expect(requests.first["Authorization"]).to eq("Bearer dXNlcl8xMjM6c2VjcmV0")
expect(requests.first["Content-Type"]).to eq("application/json")
expect(JSON.parse(requests.first.body)).to eq("maxTtlSeconds" => 300, "cdp" => true)
end

it "gets, closes, and executes actions against session paths" do
stub_const("Capture::EDGE_URL", "https://edge.test")
client = Capture.new("user_123", "secret")
Expand Down