-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 16 additions & 9 deletions
25
webdriver/tests/bidi/browsing_context/capture_screenshot/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
from webdriver.bidi.modules.script import ContextTarget | ||
|
||
from ... import get_viewport_dimensions | ||
|
||
async def viewport_dimensions(bidi_session, context): | ||
"""Get the dimensions of the context's viewport. | ||
async def physical_viewport_dimensions(bidi_session, context): | ||
"""Get the physical dimensions of the context's viewport. | ||
:param bidi_session: BiDiSession | ||
:param context: Browsing context ID | ||
:returns: Tuple of (int, int) containing viewport width, viewport height. | ||
""" | ||
viewport = await get_viewport_dimensions(bidi_session, context) | ||
dpr = await device_pixel_ratio(bidi_session, context) | ||
return (viewport["width"] * dpr, viewport["height"] * dpr) | ||
|
||
async def device_pixel_ratio(bidi_session, context): | ||
"""Get the DPR of the context. | ||
:param bidi_session: BiDiSession | ||
:param context: Browsing context ID | ||
:returns: (int) devicePixelRatio. | ||
""" | ||
result = await bidi_session.script.call_function( | ||
function_declaration="""() => { | ||
const {devicePixelRatio, innerHeight, innerWidth} = window; | ||
return [ | ||
Math.floor(innerWidth * devicePixelRatio), | ||
Math.floor(innerHeight * devicePixelRatio) | ||
]; | ||
return Math.floor(window.devicePixelRatio); | ||
}""", | ||
target=ContextTarget(context["context"]), | ||
await_promise=False) | ||
return tuple(item["value"] for item in result["value"]) | ||
return result["value"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters