@@ -33,11 +33,15 @@ export class WebWorkerService implements IWebWorkerService {
3333 protected _createWorker ( descriptor : WebWorkerDescriptor ) : Promise < Worker > {
3434 const workerRunnerUrl = this . getWorkerUrl ( descriptor ) ;
3535
36- const workerUrlWithNls = getWorkerBootstrapUrl ( descriptor . label , workerRunnerUrl ) ;
36+ const workerUrlWithNls = getWorkerBootstrapUrl ( descriptor . label , workerRunnerUrl , this . _getWorkerLoadingFailedErrorMessage ( descriptor ) ) ;
3737 const worker = new Worker ( ttPolicy ? ttPolicy . createScriptURL ( workerUrlWithNls ) as unknown as string : workerUrlWithNls , { name : descriptor . label , type : 'module' } ) ;
3838 return whenESMWorkerReady ( worker ) ;
3939 }
4040
41+ protected _getWorkerLoadingFailedErrorMessage ( _descriptor : WebWorkerDescriptor ) : string | undefined {
42+ return undefined ;
43+ }
44+
4145 getWorkerUrl ( descriptor : WebWorkerDescriptor ) : string {
4246 if ( ! descriptor . esmModuleLocation ) {
4347 throw new Error ( 'Missing esmModuleLocation in WebWorkerDescriptor' ) ;
@@ -71,7 +75,7 @@ export function createBlobWorker(blobUrl: string, options?: WorkerOptions): Work
7175 return new Worker ( ttPolicy ? ttPolicy . createScriptURL ( blobUrl ) as unknown as string : blobUrl , { ...options , type : 'module' } ) ;
7276}
7377
74- function getWorkerBootstrapUrl ( label : string , workerScriptUrl : string ) : string {
78+ function getWorkerBootstrapUrl ( label : string , workerScriptUrl : string , workerLoadingFailedErrorMessage : string | undefined ) : string {
7579 if ( / ^ ( ( h t t p : ) | ( h t t p s : ) | ( f i l e : ) ) / . test ( workerScriptUrl ) && workerScriptUrl . substring ( 0 , globalThis . origin . length ) !== globalThis . origin ) {
7680 // this is the cross-origin case
7781 // i.e. the webpage is running at a different origin than where the scripts are loaded from
@@ -101,7 +105,11 @@ function getWorkerBootstrapUrl(label: string, workerScriptUrl: string): string {
101105 `globalThis._VSCODE_FILE_ROOT = ${ JSON . stringify ( globalThis . _VSCODE_FILE_ROOT ) } ;` ,
102106 `const ttPolicy = globalThis.trustedTypes?.createPolicy('defaultWorkerFactory', { createScriptURL: value => value });` ,
103107 `globalThis.workerttPolicy = ttPolicy;` ,
108+
109+ workerLoadingFailedErrorMessage ? 'try {' : '' ,
104110 `await import(ttPolicy?.createScriptURL(${ JSON . stringify ( workerScriptUrl ) } ) ?? ${ JSON . stringify ( workerScriptUrl ) } );` ,
111+ workerLoadingFailedErrorMessage ? `} catch (err) { console.error(${ JSON . stringify ( workerLoadingFailedErrorMessage ) } , err); throw err; }` : '' ,
112+
105113 `globalThis.postMessage({ type: 'vscode-worker-ready' });` ,
106114 `/*${ label } */`
107115 ] ) . join ( '' ) ] , { type : 'application/javascript' } ) ;
0 commit comments