Skip to content

Commit

Permalink
Support custom pixel density
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Oct 3, 2023
1 parent a39b84d commit e5e18dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 4 additions & 6 deletions superset/utils/machine_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ class MachineAuthProvider:
def __init__(
self,
auth_webdriver_func_override: Callable[[WebDriver, User], WebDriver],
auth_browser_context_func_override: Callable[
[BrowserContext, User], BrowserContext
],
auth_context_func_override: Callable[[BrowserContext, User], BrowserContext],
):
# This is here in order to allow for the authenticate_webdriver func to be
# overridden via config, as opposed to the entire provider implementation
self._auth_webdriver_func_override = auth_webdriver_func_override
self._auth_browser_context_func_override = auth_browser_context_func_override
self._auth_context_func_override = auth_context_func_override

def authenticate_webdriver(
self,
Expand Down Expand Up @@ -81,8 +79,8 @@ def authenticate_browser_context(
user: User,
) -> BrowserContext:
# Short-circuit this method if we have an override configured
if self._auth_browser_context_func_override: # type: ignore
return self._auth_browser_context_func_override(browser_context, user)
if self._auth_context_func_override: # type: ignore
return self._auth_context_func_override(browser_context, user)

# Setting cookies requires doing a request first
page = browser_context.new_page()
Expand Down
4 changes: 4 additions & 0 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,16 @@ def find_unexpected_errors(page: Page) -> list[str]:
def get_screenshot(self, url: str, element_name: str, user: User) -> bytes | None:
with sync_playwright() as playwright:
browser = playwright.chromium.launch()
pixel_density = current_app.config["WEBDRIVER_WINDOW"].get(
"pixel_density", 1
)
context = browser.new_context(
bypass_csp=True,
viewport={
"height": self._window[1],
"width": self._window[0],
},
device_scale_factor=pixel_density,
)
self.auth(user, context)
page = context.new_page()
Expand Down

0 comments on commit e5e18dd

Please sign in to comment.