-37
-38
-39
-40
-41
+43
+44
+45
+46
+47
- # File 'lib/htmlcsstoimage/recordings.rb', line 37
+ # File 'lib/htmlcsstoimage/recordings.rb', line 43
def create_html_css_recording(html, params = {})
body = { html: html }.merge(params).to_json
@@ -2736,14 +2753,14 @@
-59
-60
-61
-62
-63
+65
+66
+67
+68
+69
|
- # File 'lib/htmlcsstoimage/recordings.rb', line 59
+ # File 'lib/htmlcsstoimage/recordings.rb', line 65
def create_url_recording(url, params = {})
body = { url: url }.merge(params).to_json
@@ -3001,14 +3018,14 @@
-82
-83
-84
-85
-86
+91
+92
+93
+94
+95
|
- # File 'lib/htmlcsstoimage/recordings.rb', line 82
+ # File 'lib/htmlcsstoimage/recordings.rb', line 91
def delete_recording(recording_id)
response = self.class.delete("/v1/recordings/#{recording_id}", basic_auth: @auth)
@@ -3079,20 +3096,20 @@
-93
-94
-95
-96
-97
-98
-99
-100
-101
102
-103
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
|
- # File 'lib/htmlcsstoimage/recordings.rb', line 93
+ # File 'lib/htmlcsstoimage/recordings.rb', line 102
def delete_recording_batch(recording_ids)
return true if recording_ids.empty?
@@ -3121,10 +3138,13 @@
- Fetches a recording's current lifecycle state once.
+ Fetches a recording's current lifecycle state once. Checking status is
+optional: requesting the recording_url directly waits until it is ready.
HTTP 200 and 202 both return status information. The states ready,
failed, and cancelled are terminal; an error can also describe an
-earlier, retryable attempt. Requesting the media URL waits for processing.
+earlier, retryable attempt. .status is the raw API string: treat values
+not listed here, which newer API versions may add, as unknown; the client
+passes them through as-is.
@@ -3159,7 +3179,7 @@
—
- .status, .attempt_count, .status_entered_at, .stored_duration_ms, .recording_url, and optional .error
+ .id, .status, .attempt_count, .status_entered_at, .stored_duration_ms, .storage_destination_hcti_storage_disabled, .recording_url, and optional .error
@@ -3178,12 +3198,12 @@
-74
-75
-76
+83
+84
+85
|
- # File 'lib/htmlcsstoimage/recordings.rb', line 74
+ # File 'lib/htmlcsstoimage/recordings.rb', line 83
def fetch_recording_status(recording_id)
self.class.get("/v1/recordings/#{recording_id}/status", basic_auth: @auth)
@@ -4332,7 +4352,7 @@
diff --git a/docs/file.README.html b/docs/file.README.html
index 5fa4423..0d28223 100644
--- a/docs/file.README.html
+++ b/docs/file.README.html
@@ -158,8 +158,8 @@ Recordings
)
Both methods accept browser, timeline, and output options as hashes, following
-the image methods. Options pass through to the API without local validation.
-Omitted settings use API defaults. Recordings do not include audio.
+the image methods. Omitted settings use API defaults.
+To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. Audio sources and playback options.
Triggers and actions use a type discriminator. For example, wait until an
element is visible, click a button, and hold the result:
demo = client.create_url_recording(
@@ -176,9 +176,22 @@ Recordings
Nested branches run on the API. For JavaScript actions, omitting if_error or
setting it to nil fails on a script error; if_error: [] ignores errors.
Empty arrays, explicit nil, false, and zero values are preserved in JSON.
-Creation returns the recording URLs while rendering can continue in the
-background. Requesting recording_url waits for processing. Fetch the current
-status once with:
+A scroll action moves through ordered steps. Each step's duration_ms is
+required and must be at least 1:
+client.create_url_recording(
+ "https://example.com",
+ duration_ms: 6000,
+ actions: [
+ { type: "scroll", steps: [
+ { to: { type: "selector", selector: "#pricing" }, duration_ms: 1200, easing: "ease_in_out_cubic" },
+ { to: { type: "position", position: "bottom" }, duration_ms: 1500 }
+ ] }
+ ]
+)
+
+Embed or request recording_url directly; the request waits until the
+recording is ready, so checking status is optional. To inspect progress, fetch
+the current status once with:
status = client.fetch_recording_status(recording.id)
puts status.status
puts status.attempt_count
@@ -186,6 +199,8 @@ Recordings
HTTP 200 and 202 both return status information. The states ready, failed,
and cancelled are terminal. A successful status fetch can report a failed
recording, and status.error can describe an earlier, retryable attempt.
+status.status is the raw API string. Treat values not listed here, which
+newer API versions may add, as unknown; the client passes them through as-is.
API errors and transport failures follow the existing image-method behavior.
Delete recordings individually or in a batch:
client.delete_recording("recording-id")
@@ -339,7 +354,7 @@ Templated image batches
See the API reference for plan limits and examples.
diff --git a/docs/index.html b/docs/index.html
index b31a8f1..400627e 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -158,8 +158,8 @@ Recordings
)
Both methods accept browser, timeline, and output options as hashes, following
-the image methods. Options pass through to the API without local validation.
-Omitted settings use API defaults. Recordings do not include audio.
+the image methods. Omitted settings use API defaults.
+To add a soundtrack to MP4 or WebM, pass audio: { asset_id: "YOUR_ASSET_ID", delay_ms: 500 } or audio: { url: "https://cdn.example.com/audio/intro.mp3" } to either recording method. Audio sources and playback options.
Triggers and actions use a type discriminator. For example, wait until an
element is visible, click a button, and hold the result:
demo = client.create_url_recording(
@@ -176,9 +176,22 @@ Recordings
Nested branches run on the API. For JavaScript actions, omitting if_error or
setting it to nil fails on a script error; if_error: [] ignores errors.
Empty arrays, explicit nil, false, and zero values are preserved in JSON.
-Creation returns the recording URLs while rendering can continue in the
-background. Requesting recording_url waits for processing. Fetch the current
-status once with:
+A scroll action moves through ordered steps. Each step's duration_ms is
+required and must be at least 1:
+client.create_url_recording(
+ "https://example.com",
+ duration_ms: 6000,
+ actions: [
+ { type: "scroll", steps: [
+ { to: { type: "selector", selector: "#pricing" }, duration_ms: 1200, easing: "ease_in_out_cubic" },
+ { to: { type: "position", position: "bottom" }, duration_ms: 1500 }
+ ] }
+ ]
+)
+
+Embed or request recording_url directly; the request waits until the
+recording is ready, so checking status is optional. To inspect progress, fetch
+the current status once with:
status = client.fetch_recording_status(recording.id)
puts status.status
puts status.attempt_count
@@ -186,6 +199,8 @@ Recordings
HTTP 200 and 202 both return status information. The states ready, failed,
and cancelled are terminal. A successful status fetch can report a failed
recording, and status.error can describe an earlier, retryable attempt.
+status.status is the raw API string. Treat values not listed here, which
+newer API versions may add, as unknown; the client passes them through as-is.
API errors and transport failures follow the existing image-method behavior.
Delete recordings individually or in a batch:
client.delete_recording("recording-id")
@@ -339,7 +354,7 @@ Templated image batches
See the API reference for plan limits and examples.
diff --git a/lib/htmlcsstoimage/recordings.rb b/lib/htmlcsstoimage/recordings.rb
index 766d959..0371cc6 100644
--- a/lib/htmlcsstoimage/recordings.rb
+++ b/lib/htmlcsstoimage/recordings.rb
@@ -8,6 +8,7 @@ class HTMLCSSToImage
# @see https://docs.htmlcsstoimage.com/parameters/actions/
# @see https://docs.htmlcsstoimage.com/parameters/trigger/
# @see https://docs.htmlcsstoimage.com/parameters/output/
+ # @see https://docs.htmlcsstoimage.com/parameters/audio/
#
# @param html [String] HTML to record, as a fragment or a complete document
# @param params [Hash] browser, timeline, and output options passed to the API
@@ -30,7 +31,11 @@ class HTMLCSSToImage
# @option params [Array] :request_overrides Browser request block rules. Requires a paid plan.
# @option params [Hash] :trigger Start condition: `type: "immediate"` (default), `"element_visible"` with a `selector`, or `"function_call"` to wait for `window.RecordingReady()`. Waiting triggers accept `timeout_ms`.
# @option params [Array] :actions Ordered timeline interactions: `simple_scroll`, `scroll`, `stall`, `click`, `locate_selector`, `execute_javascript`, or `error`. Each action has a `type` discriminator. Each `scroll` action step requires `duration_ms` of at least 1. Omit or use an empty array to record without interactions.
- # @option params [Hash] :output Media `format` (`mp4`, `webm`, or `gif`), `fps`, and pixel `scale`. Defaults to MP4 at 30 fps; GIF defaults to 15 fps. Recordings have no audio.
+ # @option params [Hash] :output Media `format` (`mp4`, `webm`, or `gif`), `fps`, and pixel `scale`. Defaults to MP4 at 30 fps; GIF defaults to 15 fps.
+ # @option params [Hash] :audio Optional MP4 or WebM soundtrack. Supply exactly one source, an Asset Library `asset_id` or a public HTTP(S) `url`.
+ # `source_start_ms` skips into the track and `delay_ms` delays playback in the video. Both default to 0.
+ # `when_audio_ends` accepts `"silence"` (default), `"loop"`, or `"trim_video"`.
+ # Set `error_on_source_invalid: false` to return the full video silently if the track cannot play.
# @option params [String] :duration_mode `at_most` (default) stops when actions finish or the duration is reached. `fixed` pads or cuts off at that duration. `at_least` lets actions finish up to 90 seconds. `target` adjusts playback speed to fit the duration.
# @option params [Boolean] :defer_render Wait to render until media or storage is requested. Defaults to false; does not reset deduplicated recordings.
# @option params [Boolean] :skip_scroll_preload Skip the preparation scroll that loads lazy content. Scrolling actions still run. Defaults to false.
diff --git a/lib/htmlcsstoimage/version.rb b/lib/htmlcsstoimage/version.rb
index a2a8154..0575e77 100644
--- a/lib/htmlcsstoimage/version.rb
+++ b/lib/htmlcsstoimage/version.rb
@@ -1,4 +1,4 @@
class HTMLCSSToImage
# Current version of the Ruby client gem.
- VERSION = "1.0.0"
+ VERSION = "1.1.0"
end
diff --git a/spec/recordings_spec.rb b/spec/recordings_spec.rb
index e42f5d6..765dc8a 100644
--- a/spec/recordings_spec.rb
+++ b/spec/recordings_spec.rb
@@ -47,7 +47,7 @@
{ type: "simple_scroll", scroll_distance: 900 },
{ type: "stall", duration_ms: 0 }
],
- output: { format: "gif", fps: 15, scale: 0.5 },
+ output: { format: "webm", fps: 15, scale: 0.5 },
duration_mode: "at_least",
defer_render: false,
skip_scroll_preload: true
@@ -67,7 +67,13 @@ def stub_api(method, path, status: 200, body: nil)
end
it "creates HTML recordings with all options and preserves nested branches without mutation" do
- params = options.merge(google_fonts: "Roboto|Open Sans").freeze
+ params = options.merge(
+ google_fonts: "Roboto|Open Sans",
+ audio: {
+ asset_id: "asset_1", source_start_ms: 0, delay_ms: 500,
+ when_audio_ends: "loop", error_on_source_invalid: false
+ }
+ ).freeze
before = Marshal.dump(params)
expected = JSON.parse({ html: "Hello" }.merge(params).to_json)
WebMock.stub_request(:post, "https://hcti.io/v1/recording").with do |request|
@@ -87,6 +93,7 @@ def stub_api(method, path, status: 200, body: nil)
it "creates URL recordings with headers and source-specific options" do
params = options.merge(
+ audio: { "url" => "https://cdn.example.com/audio/intro.mp3" },
headers: { "Authorization" => "Bearer test" },
additional_header_origins: ["https://assets.example.com"],
include_headers_on_subrequests: false,
@@ -121,6 +128,15 @@ def stub_api(method, path, status: 200, body: nil)
expect(client.create_html_css_recording("", duration_ms: 0).error).to eq("Bad Request")
end
+ it "returns the API error when both audio sources are supplied" do
+ audio = { asset_id: "asset_1", url: "https://cdn.example.com/audio/intro.mp3" }
+ stub_api(:post, "/v1/recording", status: 400, body: { error: "Bad Request" }).with(
+ body: { html: "Demo", duration_ms: 1000, audio: audio }.to_json
+ )
+
+ expect(client.create_html_css_recording("Demo", duration_ms: 1000, audio: audio).code).to eq(400)
+ end
+
{
"awaiting_render" => 202,
"processing" => 202,
|