Repository navigation
fix: fix page_options for PlaywrightBrowserPlugin
#796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,13 +98,12 @@ async def new_page( | |
| proxy_info: ProxyInfo | None = None, | ||
| ) -> Page: | ||
| if not self._browser_context: | ||
| self._browser_context = await self._create_browser_context(proxy_info) | ||
| self._browser_context = await self._create_browser_context(page_options, proxy_info) | ||
|
|
||
| if not self.has_free_capacity: | ||
| raise ValueError('Cannot open more pages in this browser.') | ||
|
|
||
| page_options = dict(page_options) if page_options else {} | ||
| page = await self._browser_context.new_page(**page_options) | ||
| page = await self._browser_context.new_page() | ||
|
|
||
| # Handle page close event | ||
| page.on(event='close', f=self._on_page_close) | ||
|
|
@@ -130,17 +129,20 @@ def _on_page_close(self, page: Page) -> None: | |
| """Handle actions after a page is closed.""" | ||
| self._pages.remove(page) | ||
|
|
||
| async def _create_browser_context(self, proxy_info: ProxyInfo | None = None) -> BrowserContext: | ||
| async def _create_browser_context( | ||
| self, page_options: Mapping[str, Any] | None = None, proxy_info: ProxyInfo | None = None | ||
| ) -> BrowserContext: | ||
| """Create a new browser context with the specified proxy settings.""" | ||
| if self._header_generator: | ||
| common_headers = self._header_generator.get_common_headers() | ||
| sec_ch_ua_headers = self._header_generator.get_sec_ch_ua_headers(browser_type=self.browser_type) | ||
| user_agent_header = self._header_generator.get_user_agent_header(browser_type=self.browser_type) | ||
| extra_http_headers = dict(common_headers | sec_ch_ua_headers | user_agent_header) | ||
| user_agent = user_agent_header.get('User-Agent') | ||
|
Pijukatel marked this conversation as resolved.
Resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was here to replace the default "headless"-something user agent. Why is it removed? Does it mean we're now using the default (headless) user agent?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have a test to double-check the default UA is not leaking, it burned as several times in the past in the JS version. I think we have it tested on other places too, found this one now
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| else: | ||
| extra_http_headers = None | ||
| user_agent = None | ||
|
|
||
| page_options = dict(page_options) if page_options else {} | ||
| page_options['extra_http_headers'] = page_options.get('extra_http_headers', extra_http_headers) | ||
|
|
||
| proxy = ( | ||
| ProxySettings( | ||
|
|
@@ -152,8 +154,4 @@ async def _create_browser_context(self, proxy_info: ProxyInfo | None = None) -> | |
| else None | ||
| ) | ||
|
|
||
| return await self._browser.new_context( | ||
| user_agent=user_agent, | ||
| extra_http_headers=extra_http_headers, | ||
| proxy=proxy, | ||
| ) | ||
| return await self._browser.new_context(proxy=proxy, **page_options) | ||
Uh oh!
There was an error while loading. Please reload this page.