Skip to content

Commit

Permalink
Initial Chromium support
Browse files Browse the repository at this point in the history
Signed-off-by: Elmer Miroslav Mosher Golovin <[email protected]>

Initial Chromium support

Signed-off-by: Elmer Miroslav Mosher Golovin <[email protected]>
  • Loading branch information
mishamosher committed Apr 26, 2023
1 parent 9aed218 commit 26f3d85
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions recording/src/nextcloud/talk/recording/Participant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# @copyright Copyright (c) 2023, Daniel Calviño Sánchez ([email protected])
# @copyright Copyright (c) 2023, Elmer Miroslav Mosher Golovin ([email protected])
#
# @license GNU AGPL version 3 or any later version
#
Expand Down Expand Up @@ -33,7 +34,12 @@
from secrets import token_urlsafe
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.webdriver import WebDriver as ChromeDriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.firefox.webdriver import WebDriver as FirefoxDriver
from selenium.webdriver.support.wait import WebDriverWait
from shutil import disk_usage
from time import sleep
Expand Down Expand Up @@ -202,6 +208,52 @@ def __del__(self):
# created in "/tmp".
self.driver.quit()

def startChrome(self, width, height, env):
"""
Starts a Chrome instance.
Will use Chromium is Google Chrome is not installed.
:param width: the width of the browser window.
:param height: the height of the browser window.
:param env: the environment variables, including the display to start
the browser in.
"""

options = ChromeOptions()

# "webSocketUrl" is needed for BiDi.
options.set_capability('webSocketUrl', True)

options.add_argument('--use-fake-ui-for-media-stream')

# Allow to play media without user interaction.
options.add_argument('--autoplay-policy=no-user-gesture-required')

options.add_argument('--kiosk')
options.add_argument(f'--window-size={width},{height}')
options.add_argument('--disable-infobars')
options.add_argument('--no-sandbox')
options.add_experimental_option("excludeSwitches", ["enable-automation"])

if disk_usage('/dev/shm').free < 2147483648:
self._logger.info('Less than 2 GiB available in "/dev/shm", usage disabled')
options.add_argument("--disable-dev-shm-usage")

if disk_usage('/tmp').free < 134217728:
self._logger.warning('Less than 128 MiB available in "/tmp", strange failures may occur')

service = ChromeService(
env=env,
)

self.driver = ChromeDriver(
options=options,
service=service,
)

self.bidiLogsHelper = BiDiLogsHelper(self.driver, self._parentLogger)

def startFirefox(self, width, height, env):
"""
Starts a Firefox instance.
Expand All @@ -212,7 +264,7 @@ def startFirefox(self, width, height, env):
the browser in.
"""

options = webdriver.FirefoxOptions()
options = FirefoxOptions()

# "webSocketUrl" is needed for BiDi; this should be set already by
# default, but just in case.
Expand All @@ -239,7 +291,7 @@ def startFirefox(self, width, height, env):
env=env,
)

self.driver = webdriver.Firefox(
self.driver = FirefoxDriver(
options=options,
service=service,
)
Expand Down Expand Up @@ -418,7 +470,9 @@ def __init__(self, browser, nextcloudUrl, width, height, env, parentLogger):

self.seleniumHelper = SeleniumHelper(parentLogger)

if browser == 'firefox':
if browser == 'chrome':
self.seleniumHelper.startChrome(width, height, env)
elif browser == 'firefox':
self.seleniumHelper.startFirefox(width, height, env)
else:
raise Exception('Invalid browser: ' + browser)
Expand Down

0 comments on commit 26f3d85

Please sign in to comment.