Skip to content

Commit

Permalink
Add browsingContext.setViewport (#425)
Browse files Browse the repository at this point in the history
* Add emulation.setViewport

This provides the ability to customize the viewport dimensions for a top level navigable e.g. for emulating a different device class.

Co-authored-by: Julian Descottes <julian.descottes@gmail.com>
Co-authored-by: jgraham <james@hoppipolla.co.uk>
  • Loading branch information
3 people authored Jun 19, 2023
1 parent 88b5c82 commit ce67907
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,62 @@ The [=remote end steps=] with |command parameters| are:

</div>

#### The browsingContext.setViewport Command #### {#command-browsingContext-setViewport}

The <dfn export for=commands>browsingContext.setViewport</dfn> command specific viewport characteristics (e.g. viewport width and viewport height) on the given top-level browsing context.

<dl>
<dt>Command Type</dt>
<dd>
<pre class="cddl remote-cddl">
browsingContext.SetViewport = {
method: "browsingContext.setViewport",
params: browsingContext.SetViewportParameters
};

browsingContext.SetViewportParameters = {
context: browsingContext.BrowsingContext,
viewport: browsingContext.Viewport / null,
}

browsingContext.Viewport = {
width: js-uint,
height: js-uint,
}
</pre>
</dd>
<dt>Result Type</dt>
<dd>
<pre class="cddl">
EmptyResult
</pre>
</dd>
</dl>

<div algorithm="remote end steps for browsingContext.setViewport">

The [=remote end steps=] with |command parameters| are:

1. Let |context id| be the value of the |command parameters|["<code>context</code>"] field.

1. Let |context| be the result of [=trying=] to [=get a browsing context=] with |context id|.

1. If |context| is not a [=top-level browsing context=], return [=error=] with [=error code=] [=invalid argument=].

1. Let |viewport parameter| be the |command parameters|["<code>viewport</code>"] field.

1. If |viewport parameter| is not null:
1. Let |width| be the |viewport parameter|["<code>width</code>"]
1. Let |height| be the |viewport parameter|["<code>height</code>"]
1. If the |width| or |height| is outside of the implementation-specific or runtime constraints, return an [=error=] with the [=error code=] [=unsupported operation=].
1. Set the layout [[css2#viewport]] of the |context| to be |width| CSS pixels wide and |height| CSS pixels high.
1. Else:
1. Set the layout [[css2#viewport]] of |context| to the implementation-defined default layout viewport for |context|.
1. Run the [[cssom-view-1#resizing-viewports]] steps.
1. Return [=success=] with data null.

</div>


### Events ### {#module-contexts-events}

Expand Down

0 comments on commit ce67907

Please sign in to comment.