Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/crawlee/browsers/_playwright_browser_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async def _create_browser_context(
)

if proxy_info:
if browser_new_context_options['proxy']:
if browser_new_context_options.get('proxy'):
logger.warning("browser_new_context_options['proxy'] overriden by explicit `proxy_info` argument.")

browser_new_context_options['proxy'] = ProxySettings(
Expand Down
24 changes: 23 additions & 1 deletion tests/unit/crawlers/_playwright/test_playwright_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
PW_CHROMIUM_HEADLESS_DEFAULT_USER_AGENT,
PW_FIREFOX_HEADLESS_DEFAULT_USER_AGENT,
)
from crawlee.proxy_configuration import ProxyConfiguration

if TYPE_CHECKING:
from yarl import URL

from crawlee.crawlers import PlaywrightCrawlingContext
from crawlee.crawlers import PlaywrightCrawlingContext, PlaywrightPreNavCrawlingContext


async def test_basic_request(httpbin: URL) -> None:
Expand Down Expand Up @@ -188,3 +189,24 @@ async def request_handler(_context: PlaywrightCrawlingContext) -> None:
await crawler.run(['https://example.com', str(httpbin)])

assert mock_hook.call_count == 2


async def test_proxy_set() -> None:
proxy_value = 'http://1111:1111'
mock_handler = mock.AsyncMock(return_value=None)
crawler = PlaywrightCrawler(proxy_configuration=ProxyConfiguration(proxy_urls=[proxy_value]))

handler_data = {}

crawler.router.default_handler(mock_handler)

@crawler.pre_navigation_hook
async def some_hook(context: PlaywrightPreNavCrawlingContext) -> None:
if context.proxy_info:
handler_data['proxy'] = context.proxy_info.url

await context.page.route('**/*', lambda route: route.fulfill(status=200, body=''))

await crawler.run(['https://test.com'])

assert handler_data.get('proxy') == proxy_value
Loading