@@ -25,18 +25,37 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
25
25
// tslint:disable-next-line:no-any
26
26
return oldCreateElement . call ( document , tagName as any ) ;
27
27
} ;
28
+ // tslint:disable-next-line:no-any
29
+ const getPropertyDescriptor = ( object : any , id : string ) : PropertyDescriptor | undefined => {
30
+ let op = Object . getPrototypeOf ( object ) ;
31
+ while ( ! Object . getOwnPropertyDescriptor ( op , id ) ) {
32
+ op = Object . getPrototypeOf ( op ) ;
33
+ }
34
+
35
+ return Object . getOwnPropertyDescriptor ( op , id ) ;
36
+ } ;
37
+
38
+ if ( tagName === "img" ) {
39
+ const img = createElement ( "img" ) ;
40
+ const oldSrc = getPropertyDescriptor ( img , "src" ) ;
41
+ if ( ! oldSrc ) {
42
+ throw new Error ( "Failed to find src property" ) ;
43
+ }
44
+ Object . defineProperty ( img , "src" , {
45
+ get : ( ) : string => {
46
+ return oldSrc ! . get ! . call ( img ) ;
47
+ } ,
48
+ set : ( value : string ) : void => {
49
+ value = value . replace ( / f i l e : \/ \/ / g, "/resource" ) ;
50
+ oldSrc ! . set ! . call ( img , value ) ;
51
+ } ,
52
+ } ) ;
53
+
54
+ return img ;
55
+ }
28
56
29
57
if ( tagName === "style" ) {
30
58
const style = createElement ( "style" ) ;
31
- // tslint:disable-next-line:no-any
32
- const getPropertyDescriptor = ( object : any , id : string ) : PropertyDescriptor | undefined => {
33
- let op = Object . getPrototypeOf ( object ) ;
34
- while ( ! Object . getOwnPropertyDescriptor ( op , id ) ) {
35
- op = Object . getPrototypeOf ( op ) ;
36
- }
37
-
38
- return Object . getOwnPropertyDescriptor ( op , id ) ;
39
- } ;
40
59
const oldInnerHtml = getPropertyDescriptor ( style , "innerHTML" ) ;
41
60
if ( ! oldInnerHtml ) {
42
61
throw new Error ( "Failed to find innerHTML property" ) ;
0 commit comments