@@ -21,6 +21,7 @@ import {
2121 withServerForEachTest ,
2222} from './ServerUtils' ;
2323import { createHash } from 'node:crypto' ;
24+ import until from 'wait-for-expect' ;
2425
2526// WebSocket is unreliable when using fake timers.
2627jest . useRealTimers ( ) ;
@@ -470,8 +471,8 @@ describe.each(['HTTP', 'HTTPS'])(
470471 }
471472 } ) ;
472473
473- test ( 'throws when attempting to pass a filesystem url' , async ( ) => {
474- const { device, debugger_} = await createAndConnectTarget (
474+ test ( 'forwards to the target for a url the proxy cannot fetch ' , async ( ) => {
475+ const { device, debugger_, sessionId } = await createAndConnectTarget (
475476 serverRef ,
476477 autoCleanup . signal ,
477478 {
@@ -495,36 +496,81 @@ describe.each(['HTTP', 'HTTPS'])(
495496 hash : createHash ( 'sha256' ) . update ( '' ) . digest ( 'hex' ) ,
496497 } ,
497498 } ) ;
498- const response = await debugger_ . sendAndGetResponse ( {
499+ const message = {
499500 id : 1 ,
500501 method : 'Debugger.getScriptSource' ,
501502 params : {
502503 scriptId : 'script1' ,
503504 } ,
505+ } ;
506+ await sendFromDebuggerToTarget ( debugger_ , device , 'page1' , message , {
507+ sessionId,
504508 } ) ;
505- expect ( response . result ) . toEqual (
506- expect . objectContaining ( {
507- error : {
508- message : expect . stringContaining (
509- 'Can\'t parse requested URL "__fixtures__/mock-source-file.txt"' ,
510- ) ,
511- } ,
512- } ) ,
513- ) ;
514509
515- // The device does not receive the getScriptSource request, since it
516- // is handled by the proxy .
517- expect ( device . wrappedEventParsed ) . not . toBeCalledWith ( {
510+ // The proxy only fetches HTTP(S) urls itself, so rather than failing
511+ // it hands the request to the target .
512+ expect ( device . wrappedEventParsed ) . toBeCalledWith ( {
518513 pageId : 'page1' ,
519- wrappedEvent : expect . objectContaining ( {
520- method : 'Debugger.getScriptSource' ,
521- } ) ,
514+ sessionId,
515+ wrappedEvent : message ,
522516 } ) ;
523517 } finally {
524518 device . close ( ) ;
525519 debugger_ . close ( ) ;
526520 }
527521 } ) ;
522+
523+ test ( 'forwards to the target for a script with no url' , async ( ) => {
524+ const { device, debugger_, sessionId} = await createAndConnectTarget (
525+ serverRef ,
526+ autoCleanup . signal ,
527+ {
528+ app : 'bar-app' ,
529+ id : 'page1' ,
530+ title : 'bar-title' ,
531+ vm : 'bar-vm' ,
532+ } ,
533+ ) ;
534+
535+ try {
536+ // Targets report an empty url for code they compiled from a debugger
537+ // expression, such as code typed into the DevTools console.
538+ await sendFromTargetToDebugger ( device , debugger_ , 'page1' , {
539+ method : 'Debugger.scriptParsed' ,
540+ params : {
541+ scriptId : 'script1' ,
542+ url : '' ,
543+ } ,
544+ } ) ;
545+ const message = {
546+ id : 1 ,
547+ method : 'Debugger.getScriptSource' ,
548+ params : {
549+ scriptId : 'script1' ,
550+ } ,
551+ } ;
552+ await sendFromDebuggerToTarget ( debugger_ , device , 'page1' , message , {
553+ sessionId,
554+ } ) ;
555+ expect ( device . wrappedEventParsed ) . toBeCalledWith ( {
556+ pageId : 'page1' ,
557+ sessionId,
558+ wrappedEvent : message ,
559+ } ) ;
560+
561+ // The target answers, and the proxy relays that back to the debugger.
562+ const response = { id : 1 , result : { scriptSource : 'debugger;' } } ;
563+ device . sendWrappedEvent ( 'page1' , response ) ;
564+ await until ( ( ) =>
565+ expect ( debugger_ . handle ) . toBeCalledWith (
566+ expect . objectContaining ( response ) ,
567+ ) ,
568+ ) ;
569+ } finally {
570+ device . close ( ) ;
571+ debugger_ . close ( ) ;
572+ }
573+ } ) ;
528574 } ) ;
529575
530576 describe ( "disabled when target has 'nativeSourceCodeFetching' capability flag" , ( ) => {
0 commit comments