@@ -19,29 +19,54 @@ pub fn inject_invoke_key_token(document: &mut NodeRef) {
19
19
let element = node. as_element ( ) . unwrap ( ) ;
20
20
21
21
let attrs = element. attributes . borrow ( ) ;
22
- // if the script is external (has `src`) or its type is not "module" , we won't inject the token
23
- if attrs. get ( "src" ) . is_some ( ) || attrs . get ( "type" ) != Some ( "module" ) {
22
+ // if the script is external (has `src`), we won't inject the token
23
+ if attrs. get ( "src" ) . is_some ( ) {
24
24
continue ;
25
25
}
26
26
27
- let replacement_node = NodeRef :: new_element (
28
- QualName :: new ( None , ns ! ( html) , "script" . into ( ) ) ,
29
- element
30
- . attributes
31
- . borrow ( )
32
- . clone ( )
33
- . map
34
- . into_iter ( )
35
- . collect :: < Vec < _ > > ( ) ,
36
- ) ;
37
- let script = node. text_contents ( ) ;
38
- replacement_node. append ( NodeRef :: new_text ( format ! (
39
- r#"
27
+ let replacement_node = match attrs. get ( "type" ) {
28
+ Some ( "module" ) | Some ( "application/ecmascript" ) => {
29
+ let replacement_node = NodeRef :: new_element (
30
+ QualName :: new ( None , ns ! ( html) , "script" . into ( ) ) ,
31
+ element
32
+ . attributes
33
+ . borrow ( )
34
+ . clone ( )
35
+ . map
36
+ . into_iter ( )
37
+ . collect :: < Vec < _ > > ( ) ,
38
+ ) ;
39
+ let script = node. text_contents ( ) ;
40
+ replacement_node. append ( NodeRef :: new_text ( format ! (
41
+ r#"
40
42
const __TAURI_INVOKE_KEY__ = __TAURI__INVOKE_KEY_TOKEN__;
41
43
{}
42
44
"# ,
43
- script
44
- ) ) ) ;
45
+ script
46
+ ) ) ) ;
47
+ replacement_node
48
+ }
49
+ Some ( "application/javascript" ) | None => {
50
+ let replacement_node = NodeRef :: new_element (
51
+ QualName :: new ( None , ns ! ( html) , "script" . into ( ) ) ,
52
+ element
53
+ . attributes
54
+ . borrow ( )
55
+ . clone ( )
56
+ . map
57
+ . into_iter ( )
58
+ . collect :: < Vec < _ > > ( ) ,
59
+ ) ;
60
+ let script = node. text_contents ( ) ;
61
+ replacement_node. append ( NodeRef :: new_text (
62
+ script. replace ( "__TAURI_INVOKE_KEY__" , "__TAURI__INVOKE_KEY_TOKEN__" ) ,
63
+ ) ) ;
64
+ replacement_node
65
+ }
66
+ _ => {
67
+ continue ;
68
+ }
69
+ } ;
45
70
46
71
node. insert_after ( replacement_node) ;
47
72
node. detach ( ) ;
0 commit comments