From eeb9cb3b606bbab7bd36673a9e9b2a163b9ca72f Mon Sep 17 00:00:00 2001 From: daijro Date: Tue, 13 Aug 2024 06:32:13 -0500 Subject: [PATCH] Makefile: Add run-pw to test Playwright --- Makefile | 7 +++++- scripts/run-pw.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 scripts/run-pw.py diff --git a/Makefile b/Makefile index 0f8d469..319e183 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ dir: @if [ ! -d $(cf_source_dir) ]; then \ make setup; \ fi - make clean + make revert python3 scripts/patch.py $(version) $(release) touch $(cf_source_dir)/_READY @@ -137,6 +137,11 @@ package-windows: --arch $(arch) \ --fonts macos linux +run-pw: + python3 scripts/run-pw.py \ + --version $(version) \ + --release $(release) + run: cd $(cf_source_dir) && rm -rf ~/.camoufox && ./mach run diff --git a/scripts/run-pw.py b/scripts/run-pw.py new file mode 100644 index 0000000..77a3d13 --- /dev/null +++ b/scripts/run-pw.py @@ -0,0 +1,58 @@ +import argparse +import os +import time + +from _mixin import find_src_dir, get_moz_target, temp_cd +from playwright.sync_api import sync_playwright + + +def launch_playwright(executable_path): + """Launch playwright Firefox with unlimited time""" + with sync_playwright() as p: + print('Launching browser.') + browser = p.firefox.launch(executable_path=executable_path, headless=False) + page = browser.new_page() + url = os.getenv('URL') or 'https://google.com' + page.goto(url) + try: + time.sleep(1e9) + except: + print('Closing...') + finally: + browser.close() + + +def get_args(): + """Get CLI parameters""" + parser = argparse.ArgumentParser( + description='Package Camoufox for different operating systems.' + ) + parser.add_argument('--version', required=True, help='Camoufox version') + parser.add_argument('--release', required=True, help='Camoufox release number') + return parser.parse_args() + + +def main(): + """Run the browser with Playwright""" + args = get_args() + + src_dir = find_src_dir('.', args.version, args.release) + moz_target = get_moz_target(target='linux', arch='x86_64') + + with temp_cd(src_dir): + print(f'Looking for file: obj-{moz_target}/dist/bin/camoufox-bin') + with temp_cd(f'obj-{moz_target}/dist/bin'): + if os.path.exists('camoufox-bin'): + file_name = 'camoufox-bin' + elif os.path.exists('firefox-bin'): + file_name = 'firefox-bin' + else: + raise FileNotFoundError(f'Binary not found: obj-{moz_target}/dist/bin') + file_path = os.path.abspath(f'obj-{moz_target}/dist/bin/{file_name}') + + with temp_cd(os.path.dirname(file_path)): + launch_playwright(file_path) + + +if __name__ == '__main__': + main()