@@ -29,8 +29,7 @@ def scan_urls():
2929 options .add_argument ("--no-sandbox" )
3030 options .add_argument ("--disable-dev-shm-usage" )
3131
32- service = Service ("/usr/local/bin/geckodriver" )
33- driver = webdriver .Firefox (service = service , options = options )
32+ driver = create_firefox_driver ()
3433
3534 all_results = {
3635 "total_violations" : 0 ,
@@ -69,6 +68,103 @@ def scan_urls():
6968 print (json .dumps (all_results , indent = 2 ))
7069
7170
71+ def create_firefox_driver ():
72+ """Create a Firefox WebDriver configured for CI/headless environment"""
73+
74+ # Firefox options for CI environment
75+ options = Options ()
76+
77+ # Essential headless options
78+ options .add_argument ('--headless' )
79+ options .add_argument ('--no-sandbox' )
80+ options .add_argument ('--disable-dev-shm-usage' )
81+ options .add_argument ('--disable-extensions' )
82+ options .add_argument ('--disable-gpu' )
83+ options .add_argument ('--window-size=1280,1024' )
84+ options .add_argument ('--disable-web-security' )
85+ options .add_argument ('--disable-features=VizDisplayCompositor' )
86+
87+ # CI-specific Firefox preferences
88+ preferences = {
89+ # Disable caching
90+ 'browser.cache.disk.enable' : False ,
91+ 'browser.cache.memory.enable' : False ,
92+ 'browser.cache.offline.enable' : False ,
93+
94+ # Disable session restore and startup
95+ 'browser.sessionstore.resume_from_crash' : False ,
96+ 'browser.startup.page' : 0 ,
97+ 'browser.startup.homepage' : 'about:blank' ,
98+
99+ # Disable tabs and process isolation (helps in CI)
100+ 'browser.tabs.remote.autostart' : False ,
101+ 'browser.tabs.remote.autostart.2' : False ,
102+ 'dom.ipc.processCount' : 1 ,
103+
104+ # Disable sandbox (often needed in CI)
105+ 'security.sandbox.content.level' : 0 ,
106+ 'security.sandbox.gpu.level' : 0 ,
107+
108+ # Disable various features that can cause issues
109+ 'browser.safebrowsing.enabled' : False ,
110+ 'browser.safebrowsing.malware.enabled' : False ,
111+ 'browser.safebrowsing.phishing.enabled' : False ,
112+ 'datareporting.healthreport.uploadEnabled' : False ,
113+ 'datareporting.policy.dataSubmissionEnabled' : False ,
114+ 'toolkit.telemetry.enabled' : False ,
115+ 'toolkit.telemetry.unified' : False ,
116+
117+ # Media and WebRTC
118+ 'media.navigator.enabled' : False ,
119+ 'media.peerconnection.enabled' : False ,
120+ 'media.autoplay.default' : 2 ,
121+
122+ # Notifications and geolocation
123+ 'dom.webnotifications.enabled' : False ,
124+ 'geo.enabled' : False ,
125+
126+ # Disable automatic updates
127+ 'app.update.enabled' : False ,
128+ 'app.update.auto' : False ,
129+
130+ # Network settings
131+ 'network.http.phishy-userpass-length' : 255 ,
132+ 'network.manage-offline-status' : False ,
133+
134+ # Accessibility (don't disable - we need this for axe)
135+ 'accessibility.force_disabled' : 0 ,
136+ }
137+
138+ # Apply all preferences
139+ for key , value in preferences .items ():
140+ options .set_preference (key , value )
141+
142+ # Service configuration
143+ service_args = [
144+ '--log=debug' , # Enable debug logging
145+ '--marionette-port=2828' , # Explicit port
146+ ]
147+
148+ try :
149+ service = Service (
150+ executable_path = '/usr/local/bin/geckodriver' ,
151+ service_args = service_args
152+ )
153+
154+ print ("Creating Firefox WebDriver..." )
155+ driver = webdriver .Firefox (service = service , options = options )
156+
157+ # Set timeouts
158+ driver .set_page_load_timeout (30 )
159+ driver .implicitly_wait (10 )
160+
161+ print ("Firefox WebDriver created successfully" )
162+ return driver
163+
164+ except Exception as e :
165+ print (f"Failed to create Firefox WebDriver: { str (e )} " )
166+ raise
167+
72168def get_axe_results (driver ):
73169 axe = Axe (driver )
74170 axe .inject ()
0 commit comments