@@ -23,6 +23,8 @@ import { URI } from 'vs/base/common/uri';
23
23
24
24
declare function postMessage ( data : any , transferables ?: Transferable [ ] ) : void ;
25
25
26
+ declare type _Fetch = typeof fetch ;
27
+
26
28
declare namespace self {
27
29
let close : any ;
28
30
let postMessage : any ;
@@ -32,6 +34,8 @@ declare namespace self {
32
34
let indexedDB : { open : any , [ k : string ] : any } ;
33
35
let caches : { open : any , [ k : string ] : any } ;
34
36
let importScripts : any ;
37
+ let fetch : _Fetch ;
38
+ let XMLHttpRequest : any ;
35
39
}
36
40
37
41
const nativeClose = self . close . bind ( self ) ;
@@ -40,6 +44,27 @@ self.close = () => console.trace(`'close' has been blocked`);
40
44
const nativePostMessage = postMessage . bind ( self ) ;
41
45
self . postMessage = ( ) => console . trace ( `'postMessage' has been blocked` ) ;
42
46
47
+ const nativeFetch = fetch . bind ( self ) ;
48
+ self . fetch = function ( input , init ) {
49
+ if ( input instanceof Request ) {
50
+ // Request object - massage not supported
51
+ return nativeFetch ( input , init ) ;
52
+ }
53
+ if ( / ^ f i l e : / i. test ( String ( input ) ) ) {
54
+ input = FileAccess . asBrowserUri ( URI . parse ( String ( input ) ) ) . toString ( true ) ;
55
+ }
56
+ return nativeFetch ( input , init ) ;
57
+ } ;
58
+
59
+ self . XMLHttpRequest = class extends XMLHttpRequest {
60
+ override open ( method : string , url : string | URL , async ?: boolean , username ?: string | null , password ?: string | null ) : void {
61
+ if ( / ^ f i l e : / i. test ( url . toString ( ) ) ) {
62
+ url = FileAccess . asBrowserUri ( URI . parse ( url . toString ( ) ) ) . toString ( true ) ;
63
+ }
64
+ return super . open ( method , url , async ?? true , username , password ) ;
65
+ }
66
+ } ;
67
+
43
68
self . importScripts = ( ) => { throw new Error ( `'importScripts' has been blocked` ) ; } ;
44
69
45
70
// const nativeAddEventListener = addEventListener.bind(self);
0 commit comments