Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ where X.Y.Z is the semver of the most recent choreographer release.

## [Unreleased]

### Added
- Add `enable_extensions` option to control browser extension loading [[#303](https://github.com/plotly/choreographer/pull/303)], with thanks to @hirohira9119 for the contribution!

### Fixed
- Improve platform architecture detection for arm on Linux and Windows [[#290](https://github.com/plotly/choreographer/pull/290)], with thanks to @juliabeliaeva for the contribution!
- Fix license file and add a valid SPDX identifier to project settings [[#294](https://github.com/plotly/choreographer/pull/294)], with thanks to @ecederstrand for the contribution!
Expand Down
14 changes: 10 additions & 4 deletions src/choreographer/browsers/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ class Chromium:

path: str | Path | None
"""The path to the chromium executable."""
extensions_enabled: bool
"""True to enable browser extensions. True by default."""
gpu_enabled: bool
"""True if we should use the gpu. False by default for compatibility."""
headless: bool
"""True if we should not show the browser, true by default."""
"""True if we should not show the browser. True by default."""
sandbox_enabled: bool
"""True to enable the sandbox. False by default."""
skip_local: bool
Expand Down Expand Up @@ -142,9 +144,10 @@ def __init__(
channel: the `choreographer.Channel` we'll be using (WebSockets? Pipe?)
path: path to the browser
kwargs:
gpu_enabled (default False): Turn on GPU? Doesn't work in all envs.
headless (default True): Actually launch a browser?
sandbox_enabled (default False): Enable sandbox-
enable_extensions (default True): Enable extensions?
enable_gpu (default False): Turn on GPU? Doesn't work in all envs.
headless (default True): Run the browser in headless mode?
enable_sandbox (default False): Enable sandbox-
a persnickety thing depending on environment, OS, user, etc
tmp_dir (default None): Manually set the temporary directory

Expand All @@ -155,6 +158,7 @@ def __init__(
"""
_logger.info(f"Chromium init'ed with kwargs {kwargs}")
self.path = path
self.extensions_enabled = kwargs.pop("enable_extensions", True)
self.gpu_enabled = kwargs.pop("enable_gpu", False)
self.headless = kwargs.pop("headless", True)
self.sandbox_enabled = kwargs.pop("enable_sandbox", False)
Expand Down Expand Up @@ -237,6 +241,8 @@ def get_cli(self) -> Sequence[str]:
str(self.path),
]

if not self.extensions_enabled:
cli.append("--disable-extensions")
if not self.gpu_enabled:
cli.append("--disable-gpu")
if self.headless:
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def headless(request):
return request.param


@pytest.fixture(params=[True, False], ids=["enable_extensions", ""])
Comment thread
hirohira9119 marked this conversation as resolved.
def extension(request):
return request.param


# --headless is the default flag for most tests,
# but you can set --no-headless if you want to watch
def pytest_addoption(parser):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@pytest.mark.asyncio(loop_scope="function")
async def test_context(headless, sandbox, gpu):
async def test_context(headless, sandbox, gpu, extension):
_logger.info("testing...")
if sandbox and "ubuntu" in platform.version().lower():
pytest.skip(
Expand All @@ -35,6 +35,7 @@ async def test_context(headless, sandbox, gpu):
headless=headless,
enable_sandbox=sandbox,
enable_gpu=gpu,
enable_extensions=extension,
) as browser:
response = await browser.send_command(command="Target.getTargets")
assert "result" in response and "targetInfos" in response["result"] # noqa: PT018 combined assert
Expand All @@ -51,14 +52,15 @@ async def test_context(headless, sandbox, gpu):


@pytest.mark.asyncio(loop_scope="function")
async def test_no_context(headless, sandbox, gpu):
async def test_no_context(headless, sandbox, gpu, extension):
_logger.info("testing...")
if sandbox and "ubuntu" in platform.version().lower():
pytest.skip("Ubuntu doesn't support sandbox unless installed from snap.")
browser = await choreo.Browser(
headless=headless,
enable_sandbox=sandbox,
enable_gpu=gpu,
enable_extensions=extension,
)
try:
async with timeout(pytest.default_timeout): # type: ignore[reportAttributeAccessIssue]
Expand Down
Loading