mirror of
https://github.com/nextcloud/docker.git
synced 2025-03-15 19:05:09 +01:00
Headless new mode introduced for chrome
This commit is contained in:
parent
e77d27ed5b
commit
6e3ddc458a
6 changed files with 45 additions and 36 deletions
|
@ -11,10 +11,11 @@ def log_note(message: str) -> None:
|
||||||
def run(playwright: Playwright, browser_name: str) -> None:
|
def run(playwright: Playwright, browser_name: str) -> None:
|
||||||
log_note(f"Launch browser {browser_name}")
|
log_note(f"Launch browser {browser_name}")
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browser_type = playwright.firefox
|
browser = playwright.firefox.launch(headless=True)
|
||||||
else:
|
else:
|
||||||
browser_type = playwright.chromium
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
browser = browser_type.launch(headless=True)
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browser = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -10,12 +10,12 @@ def log_note(message: str) -> None:
|
||||||
|
|
||||||
def run(playwright: Playwright, browser_name: str) -> None:
|
def run(playwright: Playwright, browser_name: str) -> None:
|
||||||
log_note(f"Launch browser {browser_name}")
|
log_note(f"Launch browser {browser_name}")
|
||||||
headless = True
|
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browser = playwright.firefox.launch(headless=headless)
|
browser = playwright.firefox.launch(headless=True)
|
||||||
else:
|
else:
|
||||||
browser = playwright.chromium.launch(headless=headless)
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browser = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,11 @@ def log_note(message: str) -> None:
|
||||||
def create_user(playwright: Playwright, browser_name: str, username: str, password: str) -> None:
|
def create_user(playwright: Playwright, browser_name: str, username: str, password: str) -> None:
|
||||||
log_note(f"Launch browser {browser_name}")
|
log_note(f"Launch browser {browser_name}")
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browser_type = playwright.firefox
|
browser = playwright.firefox.launch(headless=True)
|
||||||
else:
|
else:
|
||||||
browser_type = playwright.chromium
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
browser = browser_type.launch(headless=True)
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browser = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
try:
|
try:
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
|
|
|
@ -19,15 +19,21 @@ def log_note(message: str) -> None:
|
||||||
def collaborate(playwright: Playwright, browser_name: str) -> None:
|
def collaborate(playwright: Playwright, browser_name: str) -> None:
|
||||||
log_note(f"Launch two {browser_name} browsers")
|
log_note(f"Launch two {browser_name} browsers")
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browser_type = playwright.firefox
|
browser = playwright.firefox.launch(headless=True)
|
||||||
else:
|
else:
|
||||||
browser_type = playwright.chromium
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
browser = browser_type.launch(headless=True)
|
browser = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
admin_user = context.new_page()
|
admin_user = context.new_page()
|
||||||
|
|
||||||
browser_two = browser_type.launch(headless=True)
|
|
||||||
|
if browser_name == "firefox":
|
||||||
|
browser_two = playwright.firefox.launch(headless=True)
|
||||||
|
else:
|
||||||
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browser_two = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context_two = browser_two.new_context()
|
context_two = browser_two.new_context()
|
||||||
docs_user = context_two.new_page()
|
docs_user = context_two.new_page()
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,11 @@ def main(browser_name: str = "chromium"):
|
||||||
with sync_playwright() as playwright:
|
with sync_playwright() as playwright:
|
||||||
log_note(f"Launch browser {browser_name}")
|
log_note(f"Launch browser {browser_name}")
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browser_type = playwright.firefox
|
browser = playwright.firefox.launch(headless=True)
|
||||||
else:
|
else:
|
||||||
browser_type = playwright.chromium
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
browser = browser_type.launch(headless=True)
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browser = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -23,12 +23,13 @@ def send_message(sender, message):
|
||||||
log_note("GMT_SCI_R=1")
|
log_note("GMT_SCI_R=1")
|
||||||
|
|
||||||
def create_conversation(playwright: Playwright, browser_name: str) -> str:
|
def create_conversation(playwright: Playwright, browser_name: str) -> str:
|
||||||
headless = True
|
|
||||||
log_note(f"Launch browser {browser_name}")
|
log_note(f"Launch browser {browser_name}")
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browser = playwright.firefox.launch(headless=headless)
|
browser = playwright.firefox.launch(headless=True)
|
||||||
else:
|
else:
|
||||||
browser = playwright.chromium.launch(headless=headless)
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browser = playwright.chromium.launch(headless=False,args=["--headless=new"])
|
||||||
context = browser.new_context()
|
context = browser.new_context()
|
||||||
page = context.new_page()
|
page = context.new_page()
|
||||||
try:
|
try:
|
||||||
|
@ -55,14 +56,13 @@ def create_conversation(playwright: Playwright, browser_name: str) -> str:
|
||||||
page.get_by_role("button", name="Close modal").click(timeout=15_000)
|
page.get_by_role("button", name="Close modal").click(timeout=15_000)
|
||||||
|
|
||||||
# Headless browsers trigger a warning in Nextcloud, however they actually work fine
|
# Headless browsers trigger a warning in Nextcloud, however they actually work fine
|
||||||
if headless:
|
log_note("Close headless warning")
|
||||||
log_note("Close headless warning")
|
with contextlib.suppress(Exception):
|
||||||
with contextlib.suppress(Exception):
|
page.wait_for_selector('.toast-close')
|
||||||
page.wait_for_selector('.toast-close')
|
page.click('.toast-close')
|
||||||
page.click('.toast-close')
|
|
||||||
|
|
||||||
page.wait_for_selector('.toast-close')
|
page.wait_for_selector('.toast-close')
|
||||||
page.click('.toast-close')
|
page.click('.toast-close')
|
||||||
|
|
||||||
log_note("Create conversation")
|
log_note("Create conversation")
|
||||||
page.get_by_role("button", name="Create a new group conversation").click()
|
page.get_by_role("button", name="Create a new group conversation").click()
|
||||||
|
@ -86,16 +86,17 @@ def create_conversation(playwright: Playwright, browser_name: str) -> str:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def talk(playwright: Playwright, url: str, browser_name: str) -> None:
|
def talk(playwright: Playwright, url: str, browser_name: str) -> None:
|
||||||
headless = True
|
|
||||||
action_delay_ms = 300
|
action_delay_ms = 300
|
||||||
browser_count = 5
|
browser_count = 5
|
||||||
|
|
||||||
# Launch browsers
|
# Launch browsers
|
||||||
log_note(f"Launching {browser_count} {browser_name} browsers")
|
log_note(f"Launching {browser_count} {browser_name} browsers")
|
||||||
if browser_name == "firefox":
|
if browser_name == "firefox":
|
||||||
browsers = [playwright.firefox.launch(headless=headless, slow_mo=action_delay_ms) for _ in range(browser_count)]
|
browsers = [playwright.firefox.launch(headless=False, slow_mo=action_delay_ms) for _ in range(browser_count)]
|
||||||
else:
|
else:
|
||||||
browsers = [playwright.chromium.launch(headless=headless, slow_mo=action_delay_ms) for _ in range(browser_count)]
|
# this leverages new headless mode by Chromium: https://developer.chrome.com/articles/new-headless/
|
||||||
|
# The mode is however ~40% slower: https://github.com/microsoft/playwright/issues/21216
|
||||||
|
browsers = [playwright.chromium.launch(headless=False,args=["--headless=new"], slow_mo=action_delay_ms) for _ in range(browser_count)]
|
||||||
contexts = [browser.new_context() for browser in browsers]
|
contexts = [browser.new_context() for browser in browsers]
|
||||||
pages = [context.new_page() for context in contexts]
|
pages = [context.new_page() for context in contexts]
|
||||||
|
|
||||||
|
@ -105,11 +106,10 @@ def talk(playwright: Playwright, url: str, browser_name: str) -> None:
|
||||||
page.goto(url)
|
page.goto(url)
|
||||||
|
|
||||||
# Close toast messages for headless browsers
|
# Close toast messages for headless browsers
|
||||||
if headless:
|
log_note("Close headless warning")
|
||||||
log_note("Close headless warning")
|
with contextlib.suppress(Exception):
|
||||||
with contextlib.suppress(Exception):
|
for page in pages:
|
||||||
for page in pages:
|
page.wait_for_selector('.toast-close').click()
|
||||||
page.wait_for_selector('.toast-close').click()
|
|
||||||
|
|
||||||
# Perform actions for all users
|
# Perform actions for all users
|
||||||
log_note("Set guest usernames")
|
log_note("Set guest usernames")
|
||||||
|
|
Loading…
Add table
Reference in a new issue