@@ -58,6 +58,7 @@ spec: WEBDRIVER; urlPrefix: https://w3c.github.io/webdriver/
5858 text: no such alert; url: dfn-no-such-alert
5959 text: no such element; url: dfn-no-such-element
6060 text: no such frame; url: dfn-no-such-frame
61+ text: parse a page range; url: dfn-parse-a-page-range
6162 text: process capabilities; url: dfn-processing-capabilities
6263 text: readiness state; url: dfn-readiness-state
6364 text: remote end steps; url: dfn-remote-end-steps
@@ -161,6 +162,9 @@ spec: HTML; urlPrefix: https://html.spec.whatwg.org/multipage/
161162 text: window open steps; url: window-object.html#window-open-steps
162163 text: worker event loop; url: webappapis.html#worker-event-loop-2
163164 text: worklet global scopes; url: worklets.html#concept-document-worklet-global-scopes
165+ spec: RFC4648; urlPrefix: https://tools.ietf.org/html/rfc4648
166+ type: dfn
167+ text: Base64 Encode; url: section-4
164168</pre>
165169
166170<style>
@@ -2725,6 +2729,7 @@ BrowsingContextCommand = (
27252729 browsingContext.GetTree //
27262730 browsingContext.HandleUserPrompt //
27272731 browsingContext.Navigate //
2732+ browsingContext.Print //
27282733 browsingContext.Reload
27292734)
27302735</pre>
@@ -2736,7 +2741,8 @@ BrowsingContextResult = (
27362741 browsingContext.CaptureScreenshotResult //
27372742 browsingContext.CreateResult //
27382743 browsingContext.GetTreeResult //
2739- browsingContext.NavigateResult
2744+ browsingContext.NavigateResult //
2745+ browsingContext.PrintResult
27402746)
27412747
27422748BrowsingContextEvent = (
@@ -3430,6 +3436,150 @@ The [=remote end steps=] with <var ignore>session</var> and |command parameters|
34303436
34313437</div>
34323438
3439+ #### The browsingContext.print Command #### {#command-browsingContext-print}
3440+
3441+ The <dfn export for=commands>browsingContext.print</dfn> command
3442+ creates a paginated representation of a document, and returns it as a
3443+ PDF document represented as a Base64-encoded string.
3444+
3445+
3446+ <dl>
3447+ <dt> Command Type</dt>
3448+ <dd>
3449+ <pre class="cddl remote-cddl">
3450+ browsingContext.Print = {
3451+ method: "browsingContext.print",
3452+ params: browsingContext.PrintParameters
3453+ }
3454+
3455+ browsingContext.PrintParameters = {
3456+ context: browsingContext.BrowsingContext,
3457+ ?background: bool .default false,
3458+ ?margin: browsingContext.PrintMarginParameters,
3459+ ?orientation: ("portrait" / "landscape") .default "portrait",
3460+ ?page: browsingContext.PrintPageParameters,
3461+ ?pageRanges: [*text] ,
3462+ ?scale: 0.1..2.0 .default 1.0,
3463+ ?shrinkToFit: bool .default true,
3464+ }
3465+
3466+ browsingContext.PrintMarginParameters = {
3467+ ?bottom: (float .ge 0.0) .default 1.0,
3468+ ?left: (float .ge 0.0) .default 1.0,
3469+ ?right: (float .ge 0.0) .default 1.0,
3470+ ?top: (float .ge 0.0) .default 1.0,
3471+ }
3472+
3473+ browsingContext.PrintPageParameters = {
3474+ ?height: (float .ge 0.0) .default 27.94,
3475+ ?width: (float .ge 0.0) .default 21.59,
3476+ }
3477+ </pre>
3478+ </dd>
3479+ <dt> Result Type</dt>
3480+ <dd>
3481+ <pre class="cddl local-cddl">
3482+ browsingContext.PrintResult = {
3483+ data: text
3484+ }
3485+ </pre>
3486+ </dd>
3487+ </dl>
3488+
3489+ The [=remote end steps=] with <var ignore> session</var> and |command parameters| are:
3490+
3491+ 1. Let |context id| be the value of the <code> context</code> field of
3492+ |command parameters|.
3493+
3494+ 1. Let |context| be the result of [=trying=] to [=get a browsing context=]
3495+ with |context id|.
3496+
3497+ 1. If the implementation is unable to provide a paginated representation of
3498+ |context| for any reason then return [=error=] with [=error code=]
3499+ [=unsupported operation=] .
3500+
3501+ 1. Let |margins| be the value of the <code> margins</code> field of |command
3502+ parameters| if present, or otherwise a [=/map=] matching the
3503+ <code> browsingContext.PrintMarginParameters</code> with the fields set to
3504+ their default values.
3505+
3506+ 1. Let |page size| be the value of the <code> page</code> field of |command
3507+ parameters| if present, or otherwise a [=/map=] matching the
3508+ <code> browsingContext.PrintPageParameters</code> with the fields set to
3509+ their default values.
3510+
3511+ 1. Let |page ranges| be the value of the <code> pageRanges</code> field of
3512+ |command parameters| if present or an empty [=/list=] otherwise.
3513+
3514+ 1. Let |document| be |context|'s [=active document=] .
3515+
3516+ 1. Immediately after the next invocation of the [=run the animation frame
3517+ callbacks=] algorithm for |document|:
3518+
3519+ Issue: This ought to be integrated into the update rendering algorithm
3520+ in some more explicit way.
3521+
3522+ 1. Let |pdf data| be the result taking UA-specific steps to generate a
3523+ paginated representation of |document|, with the CSS [=media type=] set to
3524+ <code> print</code> , encoded as a PDF, with the following paper settings:
3525+
3526+ <table>
3527+ <tr>
3528+ <th> Property
3529+ <th> Value
3530+ <tr>
3531+ <td> Width in cm
3532+ <td> |page size|["<code>width</code>"] if
3533+ |command parameters|["<code>orientation</code>"] is
3534+ "<code> portrait</code> " otherwise |page size|["<code>height</code>"]
3535+ <tr>
3536+ <td> Height in cm
3537+ <td> |page size|["<code>height</code>"] if
3538+ |command parameters|["<code>orientation</code>"] is
3539+ "<code> portrait</code> " otherwise |page size|["<code>width</code>"]
3540+ <tr>
3541+ <td> Top margin, in cm
3542+ <td> |margins|["<code>top</code>"]
3543+ <tr>
3544+ <td> Bottom margin, in cm
3545+ <td> |margins|["<code>bottom</code>"]
3546+ <tr>
3547+ <td> Left margin, in cm
3548+ <td> |margins|["<code>left</code>"]
3549+ <tr>
3550+ <td> Right margin, in cm
3551+ <td> |margins|["<code>right</code>"]
3552+ </table>
3553+
3554+ In addition, the following formatting hints should be applied by the UA:
3555+ <dl>
3556+ <dt> If |command parameters|["<code>scale</code>"] is not equal to <code> 1</code> :
3557+ <dd> Zoom the size of the content by a factor |command parameters|["<code>scale</code>"]
3558+ <dt> If |command parameters|["<code>background</code>"] is false:
3559+ <dd> Suppress output of background images
3560+ <dt> If |command parameters|["<code>shrinkToFit</code>"] is true:
3561+ <dd> Resize the content to match the page width, overriding any page
3562+ width specified in the content
3563+ </dl>
3564+
3565+ 1. If |page ranges| is not [=list/empty=] , let |pages| be the result of
3566+ [=trying=] to [=parse a page range=] with |page ranges| and the number of
3567+ pages contained in |pdf data|, then remove any pages from |pdf data|
3568+ whose one-based index is not contained in |pages|.
3569+
3570+ 1. Let |encoding result| be the result of calling [=Base64 Encode=] on
3571+ |pdf data|.
3572+
3573+ 1. Let |encoded data| be |encoding result|’s data.
3574+
3575+ 1. Let |body| be a [=/map=] matching the
3576+ <code> browsingContext.PrintResult</code> production, with the
3577+ <code> data</code> field set to |encoded data|.
3578+
3579+ 1. Return [=success=] with data |body|.
3580+
3581+ </div>
3582+
34333583#### The browsingContext.reload Command #### {#command-browsingContext-reload}
34343584
34353585The <dfn export for=commands>browsingContext.reload</dfn> command reloads a
0 commit comments