Launches the actual browser.
(self=None)
| 596 | return connection |
| 597 | |
| 598 | async def start(self=None) -> Browser: |
| 599 | """Launches the actual browser.""" |
| 600 | if not self: |
| 601 | warnings.warn( |
| 602 | "Use ``await Browser.create()`` to create a new instance!" |
| 603 | ) |
| 604 | return |
| 605 | if self._process or self._process_pid: |
| 606 | if self._process.returncode is not None: |
| 607 | return await self.create(config=self.config) |
| 608 | warnings.warn( |
| 609 | "Ignored! This call has no effect when already running!" |
| 610 | ) |
| 611 | return |
| 612 | # self.config.update(kwargs) |
| 613 | connect_existing = False |
| 614 | if self.config.host is not None and self.config.port is not None: |
| 615 | connect_existing = True |
| 616 | else: |
| 617 | self.config.host = "127.0.0.1" |
| 618 | self.config.port = util.free_port() |
| 619 | if not connect_existing: |
| 620 | logger.debug( |
| 621 | "BROWSER EXECUTABLE PATH: %s" |
| 622 | % self.config.browser_executable_path, |
| 623 | ) |
| 624 | if not pathlib.Path(self.config.browser_executable_path).exists(): |
| 625 | raise FileNotFoundError( |
| 626 | ( |
| 627 | """ |
| 628 | --------------------------------------- |
| 629 | Could not determine browser executable. |
| 630 | --------------------------------------- |
| 631 | Browser must be installed in the default location / path! |
| 632 | If you are sure about the browser executable, |
| 633 | set it using `browser_executable_path='{}` parameter.""" |
| 634 | ).format( |
| 635 | "/path/to/your/browser/executable" |
| 636 | if is_posix |
| 637 | else "c:/path/to/your/browser.exe" |
| 638 | ) |
| 639 | ) |
| 640 | if getattr(self.config, "_extensions", None): |
| 641 | self.config.add_argument( |
| 642 | "--load-extension=%s" |
| 643 | % ",".join(str(_) for _ in self.config._extensions) |
| 644 | ) |
| 645 | exe = self.config.browser_executable_path |
| 646 | params = self.config() |
| 647 | logger.debug( |
| 648 | "Starting\n\texecutable :%s\n\narguments:\n%s", |
| 649 | exe, |
| 650 | "\n\t".join(params), |
| 651 | ) |
| 652 | if not connect_existing: |
| 653 | self._process: asyncio.subprocess.Process = ( |
| 654 | await asyncio.create_subprocess_exec( |
| 655 | exe, |
no test coverage detected