Skip to content

Commit

Permalink
- fix WindowsBase.hwnd
Browse files Browse the repository at this point in the history
- update debug_conversion.py
  • Loading branch information
kaliiiiiiiiii committed Apr 12, 2024
1 parent dd55558 commit c6877b5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions cdp_patches/input/os_base/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_window(self) -> WindowSpecification:
win32_app.connect(process=self.pid)

self.browser_window: WindowSpecification = win32_app.top_window()
self.hwnd = self.browser_window.handle
# Perform Window Checks
self.browser_window.verify_actionable()
assert self.browser_window.is_normal()
Expand Down
40 changes: 38 additions & 2 deletions dev/debug_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from tests.conftest import flags
import subprocess

import ctypes


async def get_conversion(async_driver: typing.Union[Chrome, async_playwright] = None) -> typing.Tuple[
typing.List[typing.Tuple], typing.List[typing.Tuple]]:
Expand Down Expand Up @@ -46,12 +48,39 @@ async def get_conversion(async_driver: typing.Union[Chrome, async_playwright] =
return points, list([(x, y) for x, y in points_received])


def is_aware(pid: int) -> bool:
process_handle = None
try:
process_handle = ctypes.windll.kernel32.OpenProcess(
0, # no permissions
False, # bInheritHandle
pid
)
aware = ctypes.c_int()
ctypes.windll.shcore.GetProcessDpiAwareness(
process_handle,
ctypes.byref(aware)
)
finally:
if process_handle:
ctypes.windll.kernel32.CloseHandle(process_handle)
return aware


async def conversion_driverless() -> typing.Tuple[typing.List[typing.Tuple], typing.List[typing.Tuple]]:
options = ChromeOptions()
for flag in flags:
options.add_argument(flag)
options.add_argument("--device-scale-factor=0.4")
async with Chrome() as driver:
driver.async_input = await AsyncInput(browser=driver)
async_input = await AsyncInput(browser=driver)

is_dpi_aware = is_aware(async_input.pid)
if is_dpi_aware:
async_input.scale_factor = async_input.scale_factor * (
ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100)

driver.async_input = async_input
return await get_conversion(driver)


Expand All @@ -60,7 +89,14 @@ async def conversion_playwright() -> typing.Tuple[typing.List[typing.Tuple], typ
browser = await p.chromium.launch(headless=False, args=flags)
context = await browser.new_context(locale="en-US")
page = await context.new_page()
page.async_input = await AsyncInput(browser=context) # type: ignore[attr-defined]
async_input = await AsyncInput(browser=context)

is_dpi_aware = is_aware(async_input.pid)
if is_dpi_aware:
async_input.scale_factor = async_input.scale_factor * (
ctypes.windll.shcore.GetScaleFactorForDevice(0) / 100)

page.async_input = async_input
return await get_conversion(page)


Expand Down

0 comments on commit c6877b5

Please sign in to comment.