|
5 | 5 | from logging import getLogger
|
6 | 6 | from typing import Annotated, Any
|
7 | 7 |
|
8 |
| -from pydantic import AliasChoices, BeforeValidator, Field |
9 |
| -from typing_extensions import deprecated |
| 8 | +from pydantic import AliasChoices, BeforeValidator, Field, model_validator |
| 9 | +from typing_extensions import Self, deprecated |
10 | 10 |
|
11 | 11 | from crawlee._utils.models import timedelta_ms
|
12 | 12 | from crawlee._utils.urls import validate_http_url
|
@@ -365,6 +365,19 @@ class Configuration(CrawleeConfiguration):
|
365 | 365 | ),
|
366 | 366 | ] = None
|
367 | 367 |
|
| 368 | + @model_validator(mode='after') |
| 369 | + def disable_browser_sandbox_on_platform(self) -> Self: |
| 370 | + """Disable the browser sandbox mode when running on the Apify platform. |
| 371 | +
|
| 372 | + Running in environment where `is_at_home` is True does not benefit from browser sandbox as it is already running |
| 373 | + in a container. It can be on the contrary undesired as the process in the container might be running as root and |
| 374 | + this will crash chromium that was started with browser sandbox mode. |
| 375 | + """ |
| 376 | + if self.is_at_home and not self.disable_browser_sandbox: |
| 377 | + self.disable_browser_sandbox = True |
| 378 | + logger.warning('Actor is running on the Apify platform, `disable_browser_sandbox` was changed to True.') |
| 379 | + return self |
| 380 | + |
368 | 381 | @classmethod
|
369 | 382 | def get_global_configuration(cls) -> Configuration:
|
370 | 383 | """Retrieve the global instance of the configuration.
|
|
0 commit comments