@@ -331,6 +331,21 @@ define(function (require, exports, module) {
331331 _transport . start ( ) ;
332332 }
333333
334+ let remoteFunctionsScripts = new Map ( ) ;
335+ let effectiveRemoteFunctionsScripts = RemoteFunctions ;
336+ function addRemoteFunctionScript ( scriptName , scriptText ) {
337+ if ( remoteFunctionsScripts . has ( scriptName ) ) {
338+ console . error ( `Remote function script ${ scriptName } already exists. Script wont be added.` ) ;
339+ return false ;
340+ }
341+ remoteFunctionsScripts . set ( scriptName , scriptText ) ;
342+ if ( ! RemoteFunctions . includes ( "// REPLACE_WITH_ADDED_REMOTE_SCRIPTS" ) ) {
343+ throw new Error ( "RemoteFunctions script is missing the placeholder // REPLACE_WITH_ADDED_REMOTE_SCRIPTS" ) ;
344+ }
345+ effectiveRemoteFunctionsScripts = RemoteFunctions . replace ( "// REPLACE_WITH_ADDED_REMOTE_SCRIPTS" ,
346+ Array . from ( remoteFunctionsScripts . values ( ) ) . join ( "\n" ) ) ;
347+ return true ;
348+ }
334349
335350 /**
336351 * Returns a script that should be injected into the HTML that's launched in the
@@ -343,7 +358,8 @@ define(function (require, exports, module) {
343358 // Inject DocumentObserver into the browser (tracks related documents)
344359 script += DocumentObserver ;
345360 // Inject remote functions into the browser.
346- script += "\nwindow._LD=(" + RemoteFunctions + "(" + JSON . stringify ( LiveDevMultiBrowser . config ) + "))" ;
361+ script += "\nwindow._LD=(" + effectiveRemoteFunctionsScripts +
362+ "(" + JSON . stringify ( LiveDevMultiBrowser . config ) + "))" ;
347363 return "\n" + script + "\n" ;
348364 }
349365
@@ -481,6 +497,7 @@ define(function (require, exports, module) {
481497 exports . close = close ;
482498 exports . getConnectionIds = getConnectionIds ;
483499 exports . closeAllConnections = closeAllConnections ;
500+ exports . addRemoteFunctionScript = addRemoteFunctionScript ;
484501 exports . LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME = LIVE_DEV_REMOTE_SCRIPTS_FILE_NAME ;
485502 exports . LIVE_DEV_REMOTE_WORKER_SCRIPTS_FILE_NAME = LIVE_DEV_REMOTE_WORKER_SCRIPTS_FILE_NAME ;
486503 exports . EVENT_LIVE_PREVIEW_CLICKED = EVENT_LIVE_PREVIEW_CLICKED ;
0 commit comments