@@ -21,28 +21,62 @@ <h2>Tools</h2>
2121 < a href ="https://mdn-bcd-collector.gooborg.com/ "> BCD Collector</ a >
2222 </ p >
2323
24- < button onclick ="corsTest () ">
25- CORS Test Request
24+ < button onclick ="corsTestGet () ">
25+ CORS Test Request Get
2626 </ button >
2727
28+ < button onclick ="corsTestGetCookie() ">
29+ CORS Test Request Send Cookie
30+ </ button >
31+
32+ < h3 > Test</ h3 >
33+ < div id ="testresult "> </ div >
34+
2835 < script type ="text/javascript ">
29- function corsTest ( ) {
30- fetch ( 'https://caniwebview.merz.workers.dev/' ,
36+ function corsTestGet ( ) {
37+ fetch ( 'https://caniwebview.merz.workers.dev/?echo-origin' ,
38+ {
39+ method : 'GET' ,
40+ mode : 'cors' ,
41+ credentials : 'include' ,
42+ } )
43+ . then ( response => response . text ( ) )
44+ . then ( data => {
45+ console . log ( data ) ;
46+
47+ const result = document . getElementById ( 'testresult' ) ;
48+ result . innerText = data ;
49+ } )
50+ . catch ( error => {
51+ console . error ( error ) ;
52+
53+ const result = document . getElementById ( 'testresult' ) ;
54+ result . innerText = error ;
55+ } ) ;
56+ }
57+
58+ function corsTestGetCookie ( ) {
59+ fetch ( 'https://caniwebview.merz.workers.dev/?echo-origin' ,
3160 {
32- method : 'POST ' ,
61+ method : 'GET ' ,
3362 mode : 'cors' ,
63+ credentials : 'include' ,
3464 headers : {
3565 'Cookie' : 'test=android'
3666 }
3767 } )
38- . then ( response => response . json ( ) )
68+ . then ( response => response . text ( ) )
3969 . then ( data => {
40- alert ( data ) ;
4170 console . log ( data ) ;
71+
72+ const result = document . getElementById ( 'testresult' ) ;
73+ result . innerText = data ;
4274 } )
4375 . catch ( error => {
44- alert ( 'CORS request failed' ) ;
4576 console . error ( error ) ;
77+
78+ const result = document . getElementById ( 'testresult' ) ;
79+ result . innerText = error ;
4680 } ) ;
4781 }
4882 </ script >
0 commit comments