@@ -69,6 +69,11 @@ <h1>Web Share Test</h1>
69
69
logText ( message , true ) ;
70
70
}
71
71
72
+ function setShareButtonsEnabled ( enabled ) {
73
+ document . querySelector ( '#share' ) . disabled = ! enabled ;
74
+ document . querySelector ( '#share-no-gesture' ) . disabled = ! enabled ;
75
+ }
76
+
72
77
function checkboxChanged ( e ) {
73
78
const checkbox = e . target ;
74
79
const textfield = document . querySelector ( '#' + checkbox . id . split ( '_' ) [ 0 ] ) ;
@@ -79,11 +84,6 @@ <h1>Web Share Test</h1>
79
84
}
80
85
81
86
async function testWebShare ( ) {
82
- if ( navigator . share === undefined ) {
83
- logError ( 'Error: Unsupported feature: navigator.share()' ) ;
84
- return ;
85
- }
86
-
87
87
const title_input = document . querySelector ( '#title' ) ;
88
88
const text_input = document . querySelector ( '#text' ) ;
89
89
const url_input = document . querySelector ( '#url' ) ;
@@ -97,19 +97,23 @@ <h1>Web Share Test</h1>
97
97
if ( files && files . length > 0 ) {
98
98
if ( ! navigator . canShare || ! navigator . canShare ( { files} ) ) {
99
99
logError ( 'Error: Unsupported feature: navigator.canShare()' ) ;
100
+ setShareButtonsEnabled ( true ) ;
100
101
return ;
101
102
}
102
103
}
103
104
105
+ setShareButtonsEnabled ( false ) ;
104
106
try {
105
107
await navigator . share ( { files, title, text, url} ) ;
106
108
logText ( 'Successfully sent share' ) ;
107
109
} catch ( error ) {
108
110
logError ( 'Error sharing: ' + error ) ;
109
111
}
112
+ setShareButtonsEnabled ( true ) ;
110
113
}
111
114
112
115
async function testWebShareDelay ( ) {
116
+ setShareButtonsEnabled ( false ) ;
113
117
await sleep ( 6000 ) ;
114
118
testWebShare ( ) ;
115
119
}
@@ -128,6 +132,7 @@ <h1>Web Share Test</h1>
128
132
testWebShareDelay ) ;
129
133
130
134
if ( navigator . share === undefined ) {
135
+ setShareButtonsEnabled ( false ) ;
131
136
if ( window . location . protocol === 'http:' ) {
132
137
// navigator.share() is only available in secure contexts.
133
138
window . location . replace ( window . location . href . replace ( / ^ h t t p : / , 'https:' ) ) ;
0 commit comments