Open a new page in a browser using the specified or a random browser plugin. Args: page_id: The ID to assign to the new page. If not provided, a random ID is generated. browser_plugin: browser_plugin: The browser plugin to use for creating the new page.
(
self,
*,
page_id: str | None = None,
browser_plugin: BrowserPlugin | None = None,
proxy_info: ProxyInfo | None = None,
)
| 252 | |
| 253 | @ensure_context |
| 254 | async def new_page( |
| 255 | self, |
| 256 | *, |
| 257 | page_id: str | None = None, |
| 258 | browser_plugin: BrowserPlugin | None = None, |
| 259 | proxy_info: ProxyInfo | None = None, |
| 260 | ) -> CrawleePage: |
| 261 | """Open a new page in a browser using the specified or a random browser plugin. |
| 262 | |
| 263 | Args: |
| 264 | page_id: The ID to assign to the new page. If not provided, a random ID is generated. |
| 265 | browser_plugin: browser_plugin: The browser plugin to use for creating the new page. |
| 266 | If not provided, the next plugin in the rotation is used. |
| 267 | proxy_info: The proxy configuration to use for the new page. |
| 268 | |
| 269 | Returns: |
| 270 | The newly created browser page. |
| 271 | """ |
| 272 | if page_id in self.pages: |
| 273 | raise ValueError(f'Page with ID: {page_id} already exists.') |
| 274 | |
| 275 | if browser_plugin and browser_plugin not in self.plugins: |
| 276 | raise ValueError('Provided browser_plugin is not one of the plugins used by BrowserPool.') |
| 277 | |
| 278 | page_id = page_id or crypto_random_object_id(self._GENERATED_PAGE_ID_LENGTH) |
| 279 | plugin = browser_plugin or next(self._plugins_cycle) |
| 280 | |
| 281 | return await self._get_new_page(page_id, plugin, proxy_info) |
| 282 | |
| 283 | @ensure_context |
| 284 | async def new_page_with_each_plugin(self) -> Sequence[CrawleePage]: |