|
13 | 13 | // See the License for the specific language governing permissions and |
14 | 14 | // limitations under the License. |
15 | 15 |
|
| 16 | +using Gotenberg.Sharp.API.Client.Domain.ValueObjects; |
| 17 | + |
16 | 18 | using Newtonsoft.Json.Linq; |
17 | 19 |
|
18 | 20 | namespace Gotenberg.Sharp.API.Client.Domain.Builders.Faceted; |
@@ -174,6 +176,171 @@ public HtmlConversionBehaviorBuilder SkipNetworkIdleEvent() |
174 | 176 | return this; |
175 | 177 | } |
176 | 178 |
|
| 179 | + /// <summary> |
| 180 | + /// Sets a CSS selector to wait for before conversion. |
| 181 | + /// Chromium will delay conversion until the specified element appears in the DOM. |
| 182 | + /// </summary> |
| 183 | + /// <param name="selector">A validated CSS selector.</param> |
| 184 | + /// <returns>The builder instance for method chaining.</returns> |
| 185 | + public HtmlConversionBehaviorBuilder SetWaitForSelector(CssSelector selector) |
| 186 | + { |
| 187 | + _htmlConversionBehaviors.WaitForSelector = selector ?? throw new ArgumentNullException(nameof(selector)); |
| 188 | + |
| 189 | + return this; |
| 190 | + } |
| 191 | + |
| 192 | + /// <summary> |
| 193 | + /// Sets a CSS selector to wait for before conversion. |
| 194 | + /// Chromium will delay conversion until the specified element appears in the DOM. |
| 195 | + /// </summary> |
| 196 | + /// <param name="selector">A CSS selector string (e.g., "#content", ".loaded").</param> |
| 197 | + /// <returns>The builder instance for method chaining.</returns> |
| 198 | + public HtmlConversionBehaviorBuilder SetWaitForSelector(string selector) |
| 199 | + { |
| 200 | + return SetWaitForSelector(CssSelector.Create(selector)); |
| 201 | + } |
| 202 | + |
| 203 | + /// <summary> |
| 204 | + /// Adds a CSS media feature override for Chromium rendering. |
| 205 | + /// </summary> |
| 206 | + /// <param name="feature">A validated emulated media feature.</param> |
| 207 | + /// <returns>The builder instance for method chaining.</returns> |
| 208 | + public HtmlConversionBehaviorBuilder AddEmulatedMediaFeature(EmulatedMediaFeature feature) |
| 209 | + { |
| 210 | + if (feature == null) throw new ArgumentNullException(nameof(feature)); |
| 211 | + |
| 212 | + _htmlConversionBehaviors.EmulatedMediaFeatures ??= new List<EmulatedMediaFeature>(); |
| 213 | + _htmlConversionBehaviors.EmulatedMediaFeatures.Add(feature); |
| 214 | + |
| 215 | + return this; |
| 216 | + } |
| 217 | + |
| 218 | + /// <summary> |
| 219 | + /// Adds a CSS media feature override by name and value. |
| 220 | + /// </summary> |
| 221 | + /// <param name="name">CSS media feature name (e.g., "prefers-color-scheme").</param> |
| 222 | + /// <param name="value">CSS media feature value (e.g., "dark").</param> |
| 223 | + /// <returns>The builder instance for method chaining.</returns> |
| 224 | + public HtmlConversionBehaviorBuilder AddEmulatedMediaFeature(string name, string value) |
| 225 | + { |
| 226 | + return AddEmulatedMediaFeature(EmulatedMediaFeature.Create(name, value)); |
| 227 | + } |
| 228 | + |
| 229 | + /// <summary> |
| 230 | + /// Sets HTTP status codes that trigger a 409 Conflict when the main page returns them. |
| 231 | + /// </summary> |
| 232 | + /// <param name="statusCodes">Validated HTTP status codes.</param> |
| 233 | + /// <returns>The builder instance for method chaining.</returns> |
| 234 | + public HtmlConversionBehaviorBuilder SetFailOnHttpStatusCodes(IEnumerable<GotenbergStatusCode> statusCodes) |
| 235 | + { |
| 236 | + if (statusCodes == null) throw new ArgumentNullException(nameof(statusCodes)); |
| 237 | + |
| 238 | + var codes = statusCodes.ToList(); |
| 239 | + |
| 240 | + if (codes.Any(c => c == null)) |
| 241 | + throw new ArgumentException("Status codes collection must not contain null elements.", nameof(statusCodes)); |
| 242 | + |
| 243 | + _htmlConversionBehaviors.FailOnHttpStatusCodes = codes; |
| 244 | + |
| 245 | + return this; |
| 246 | + } |
| 247 | + |
| 248 | + /// <summary> |
| 249 | + /// Sets HTTP status codes that trigger a 409 Conflict when the main page returns them. |
| 250 | + /// </summary> |
| 251 | + /// <param name="statusCodes">Raw HTTP status code integers (must be 100-599).</param> |
| 252 | + /// <returns>The builder instance for method chaining.</returns> |
| 253 | + public HtmlConversionBehaviorBuilder SetFailOnHttpStatusCodes(params int[] statusCodes) |
| 254 | + { |
| 255 | + if (statusCodes == null) throw new ArgumentNullException(nameof(statusCodes)); |
| 256 | + |
| 257 | + return SetFailOnHttpStatusCodes(statusCodes.Select(GotenbergStatusCode.Create)); |
| 258 | + } |
| 259 | + |
| 260 | + /// <summary> |
| 261 | + /// Sets HTTP status codes that trigger a failure when page resources return them. |
| 262 | + /// </summary> |
| 263 | + /// <param name="statusCodes">Validated HTTP status codes.</param> |
| 264 | + /// <returns>The builder instance for method chaining.</returns> |
| 265 | + public HtmlConversionBehaviorBuilder SetFailOnResourceHttpStatusCodes(IEnumerable<GotenbergStatusCode> statusCodes) |
| 266 | + { |
| 267 | + if (statusCodes == null) throw new ArgumentNullException(nameof(statusCodes)); |
| 268 | + |
| 269 | + var codes = statusCodes.ToList(); |
| 270 | + |
| 271 | + if (codes.Any(c => c == null)) |
| 272 | + throw new ArgumentException("Status codes collection must not contain null elements.", nameof(statusCodes)); |
| 273 | + |
| 274 | + _htmlConversionBehaviors.FailOnResourceHttpStatusCodes = codes; |
| 275 | + |
| 276 | + return this; |
| 277 | + } |
| 278 | + |
| 279 | + /// <summary> |
| 280 | + /// Sets HTTP status codes that trigger a failure when page resources return them. |
| 281 | + /// </summary> |
| 282 | + /// <param name="statusCodes">Raw HTTP status code integers (must be 100-599).</param> |
| 283 | + /// <returns>The builder instance for method chaining.</returns> |
| 284 | + public HtmlConversionBehaviorBuilder SetFailOnResourceHttpStatusCodes(params int[] statusCodes) |
| 285 | + { |
| 286 | + if (statusCodes == null) throw new ArgumentNullException(nameof(statusCodes)); |
| 287 | + |
| 288 | + return SetFailOnResourceHttpStatusCodes(statusCodes.Select(GotenbergStatusCode.Create)); |
| 289 | + } |
| 290 | + |
| 291 | + /// <summary> |
| 292 | + /// Adds a domain to exclude from HTTP status code checks on resources. |
| 293 | + /// </summary> |
| 294 | + /// <param name="domain">A validated domain name.</param> |
| 295 | + /// <returns>The builder instance for method chaining.</returns> |
| 296 | + public HtmlConversionBehaviorBuilder AddIgnoreResourceHttpStatusDomain(DomainName domain) |
| 297 | + { |
| 298 | + if (domain == null) throw new ArgumentNullException(nameof(domain)); |
| 299 | + |
| 300 | + _htmlConversionBehaviors.IgnoreResourceHttpStatusDomains ??= new List<DomainName>(); |
| 301 | + _htmlConversionBehaviors.IgnoreResourceHttpStatusDomains.Add(domain); |
| 302 | + |
| 303 | + return this; |
| 304 | + } |
| 305 | + |
| 306 | + /// <summary> |
| 307 | + /// Adds a domain to exclude from HTTP status code checks on resources. |
| 308 | + /// </summary> |
| 309 | + /// <param name="domain">A domain string (e.g., "cdn.example.com").</param> |
| 310 | + /// <returns>The builder instance for method chaining.</returns> |
| 311 | + public HtmlConversionBehaviorBuilder AddIgnoreResourceHttpStatusDomain(string domain) |
| 312 | + { |
| 313 | + return AddIgnoreResourceHttpStatusDomain(DomainName.Create(domain)); |
| 314 | + } |
| 315 | + |
| 316 | + /// <summary> |
| 317 | + /// Adds multiple domains to exclude from HTTP status code checks on resources. |
| 318 | + /// </summary> |
| 319 | + /// <param name="domains">Domain strings to exclude.</param> |
| 320 | + /// <returns>The builder instance for method chaining.</returns> |
| 321 | + public HtmlConversionBehaviorBuilder AddIgnoreResourceHttpStatusDomains(params string[] domains) |
| 322 | + { |
| 323 | + if (domains == null) throw new ArgumentNullException(nameof(domains)); |
| 324 | + |
| 325 | + var validated = domains.Select(DomainName.Create).ToList(); |
| 326 | + |
| 327 | + _htmlConversionBehaviors.IgnoreResourceHttpStatusDomains ??= new List<DomainName>(); |
| 328 | + _htmlConversionBehaviors.IgnoreResourceHttpStatusDomains.AddRange(validated); |
| 329 | + |
| 330 | + return this; |
| 331 | + } |
| 332 | + |
| 333 | + /// <summary> |
| 334 | + /// Tells Gotenberg to return a 409 Conflict if any resource fails to load due to network errors. |
| 335 | + /// </summary> |
| 336 | + /// <returns>The builder instance for method chaining.</returns> |
| 337 | + public HtmlConversionBehaviorBuilder FailOnResourceLoadingFailed() |
| 338 | + { |
| 339 | + _htmlConversionBehaviors.FailOnResourceLoadingFailed = true; |
| 340 | + |
| 341 | + return this; |
| 342 | + } |
| 343 | + |
177 | 344 | /// <summary> |
178 | 345 | /// Sets the format of the resulting PDF document. |
179 | 346 | /// </summary> |
|
0 commit comments