4096
     +ˆÛÚÙ694ØÂÖ ¶    +‹      Õ—]oÚ0†ï÷+<_ìŽ>û2u¤ÒÐZŠÚLÛ4MÈÄ†Xqd›RöëgHX�%]­L»Š?^ŸøñëãÄîkÿ¦|^¢÷Áõ~|wÕï!\øÔêø�Ÿu´�zàr€Ž´NÏ ‹…³h9BN!¸…HÏâ6(-y¨ª)ö^¹«6ïr#F¨y"Ws3¯ŸPöˆÄ�˜kÅ)kÃ\IàIÏ)ƒ±JC(¤éå	kešðØ…l´‰y@w,èrõžÆ_Ç4C×#ãuèUQz®ŽÐ‰ù4éb-Rì¹|6EJ†]<‰‚qL’{gÊ'‘Xwñ×~ïæ›Ñ�ŽV£=— H²I¿íuç7ÝìÈŒ¹@Š5×FãcïŠ(�f‚ò	g´T|—¼ãßËú™Æg*”<Õ\$OR0ˆÛ¨¡ˆUJkÇDr[•IèŸVƒ„;‹1¼¸½~ÿ6[º
ñ4»ÂÞ�H–häsÉB-ä2'ÈÂ½IÆ*=ßTQ>?É§‘ÆB5T¨|”f�z*øâñ„O�(5AžÊÛsÝ›\³ÞlÕê�ZãÕOÏšm„J„''GRä¿ÙªÚ`i8Í/e™'÷‰X$Û8fãHF4™aZŠx4Ž…Ù¡|MVÒc²éÔ_y¨a”…di0ÒeæØnÝÍqç¤²íG¹Z�À#ñÀd,Í™
Z­$V«^Y:�ãÝÝ6
Ã¯´ËcË9®2áŠYx9¦¥”C�ve)—ƒì”¿¶YI=ÉóÍÛ@ð0KvuœF…v©¨4óJºìd^Åæ±ðrÌÿ2óÖ {™·ßfƒêèŸ˜·—yûm6ÀÚÎQev)m~±2—~íüD¾ü›v(ÃB’4CØ”ìüÎ…ïd�ßV]Xß]ÈîÙ? •¥hWÊ       -ˆÛÚÙ654ØÂÖ Ž    -‹      Å–ÑnÚ0†ïûž/v—˜�@[21uÑh@�ª�¦]˜Ø$V“8²M)}úB[¨ kÕˆ]Å>üçç|ç8Ší/î°þyàGx5 £ëï¿ †Ð�ÙGÈÝêKoy0Qªè ´X,ô…©s£pŒ•¥’J°HéDèœØ«˜sì„bR>�­˜J©ãç„> >ˆÏ•d„Zh.’	¡")NuK+dAÓÔFUVéƒ6Fö”“åÊßø°W™².O×–«¥pl•€{œ²8ïBÅèØ,‹�Q"ñ\¢iŠó;=f3pªºð·ßþ)uH%«lÇÆ tÖ…ßúÝàbØíA'ÀµÞ¯¹*5.tX*�qÂfŒ’ƒâIe8a�‡ÝJãR	V(Æó)*·Q#žÊ—¬­’ ÛªJBþÕí4cÔ{Aèúãª%deñRÝ¡É@gT.s\&h¤¸XnJ®ò¿æSY\<mÁ¦ ÁâDA ìU~€"âY!¨””l³”}ÚKáÝ†^0ñ‡ÁD�¡³³Ý®ûU¡ÍF³©Í4€atÌ6 ‡„úÙÏã]�.Ç=×.u?½qÐThûãu0¶þ#ã.Y=<Àh™'ðn&ºK§çk¢ÝýÛLmÍ0´fV§ed:mŸúÍšçw9_äï{=÷Ê{B�4š¦–ÐÙ¯ÐÐ�Oí€/–›~^Ö�LëÈgow$«Ó÷:òN®V§y~�Ë¬a<Š>¨m¢ð6|‹(#Ï(©ƒÁj›Gþ:E	Îcšòx{<{‚uÐ�é§G>y/ »Xõð ³ýÏ;ïMhs£´Ñúnj£êîûj`ÑÃ^    D   /ˆl–Ãa¾”ªi?u8 ¸Û71hß�þeË8àYŒd+nÈAÿ?Õƒh {Ú_�uÐb&=LyZËcõÄØ ¨    /# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'playwright'

module PlaywrightNative
  # One browser per process, launched on first use. TEST_BROWSER=firefox switches from
  #   Chromium. Locally the `playwright` package of `pnpm install` launches it, CI sets
  #   PLAYWRIGHT_SERVER_URL to the browser server of the zammad-playwright service container.
  module Browser
    CLI_PATH = Rails.root.join('node_modules/.bin/playwright').to_s

    def self.browser
      @browser ||= begin
        assert_version_lockstep

        if ENV['PLAYWRIGHT_SERVER_URL'].present?
          @execution = Playwright.connect_to_browser_server(server_endpoint_url(launch_options), browser_type: type)
          @execution.browser
        else
          @execution = Playwright.create(playwright_cli_executable_path: CLI_PATH)
          @execution.playwright.public_send(type).launch(headless: ENV['TEST_BROWSER_HEADLESS'].present?, **launch_options)
        end
      end
    end

    def self.type
      ENV.fetch('TEST_BROWSER', 'chromium')
    end

    def self.chromium?
      type == 'chromium'
    end

    def self.launch_options
      chromium? ? chromium_launch_options : {}
    end

    # The app's self-signed certificates are covered by the context's ignoreHTTPSErrors for
    #   page traffic, but something browser-side still validates them once per page and
    #   floods the log with "SSL alert number 46". The remote debugging port gives a live view
    #   of the headless browser in DevTools. It is opt-in: once the port is taken on 127.0.0.1
    #   and ::1, the next browser launch hangs until it times out.
    def self.chromium_launch_options
      args = ['--ignore-certificate-errors']
      args << "--remote-debugging-port=#{ENV['PLAYWRIGHT_REMOTE_DEBUGGING_PORT']}" if ENV['PLAYWRIGHT_REMOTE_DEBUGGING_PORT'].present?

      { args: args }
    end

    def self.stop
      @execution&.stop
      @execution = @browser = nil
    end

    # The browser server has no launch options parameter, but reads them from the endpoint's
    #   `launch-options` query. It honors args only when started with `--unsafe`, see services.yml.
    def self.server_endpoint_url(launch_options)
      url = ENV['PLAYWRIGHT_SERVER_URL']
      return url if launch_options.blank?

      separator = url.include?('?') ? '&' : '?'

      "#{url}#{separator}launch-options=#{CGI.escape(launch_options.to_json)}"
    end

    # The playwright npm package must stay in lockstep with the playwright-ruby-client gem,
    #   or the two protocol sides drift apart silently. 