forked from mkonikov/web-share-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
125 lines (109 loc) · 4.38 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Web Share Testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="WSJ News Exclusive | Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book." />
<meta property="og:description" content=""Joseph Robinette Biden Jr. is an American politician who served as the 47th vice president of the United States from 2009 to 2017. He represented Delaware in the U.S. Senate from 1973 to 2009." - via Wiki" />
<meta name="twitter:title" content="WSJ News Exclusive | Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book." />
<meta name="twitter:description" content="This is a test to see if this comment "there is a bug with open graph that causes the title to be cut off" is still valid" />
<meta name="twitter:image" content="https://images.wsj.net/im-83607/social" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image:alt" content="Supreme Court Blocks Citizenship Question From 2020 Census for Now" />
<meta name="twitter:creator" content="@brkend" />
<meta name="twitter:site" content="@WSJ" />
<meta name="twitter:domain" content="wsj.com" />
</head>
<body>
<style>
:root {
--color-test: green;
}
h1 {
color: red;
color: var(--color-test);
}
</style>
<h1>
Test Web Share
</h1>
<h3>Fetch Image before Share</h3>
<input type="checkbox" name="fetch" id="fetch" /> Enabled
<h3>Share</h3>
<button id="test-web-share">
Share
</button>
<h3>Share with Delay</h3>
<button id="test-web-share-250">
Share - 250 ms
</button>
<button id="test-web-share-550">
Share - 500 ms
</button>
<button id="test-web-share-999">
Share - 999 ms
</button>
<button id="test-web-share-1005">
Share - 1005 ms
</button>
<script>
document.querySelector('#fetch').addEventListener('change', function() {
window.fetchEnabled = this.checked;
});
function directShare() {
navigator.share({
title: 'My awesome post!',
text: 'This post may or may not contain the answer to the universe',
url: window.location.href
}).then(() => {
window.alert('Thanks for sharing!');
})
.catch(err => {
window.alert(`Couldn't share because of`, err);
});
}
function webShare() {
if (navigator.share) {
if (window.fetchEnabled) {
let myRequest = new Request('https://mkonikov.com/images/instants.jpg');
fetch(myRequest)
.then(function(response) {
if (!response.ok) {
throw new Error('HTTP error, status = ' + response.status);
}
return response.blob();
})
.then(function(response) {
directShare();
})
}
else {
directShare();
}
} else {
window.alert('web share not supported');
}
}
function delayedWebShare(delay) {
window.setTimeout(webShare, delay);
}
document.querySelector('#test-web-share').addEventListener('click', () => {
webShare()
});
document.querySelector('#test-web-share-250').addEventListener('click', () => {
delayedWebShare(250)
});
document.querySelector('#test-web-share-550').addEventListener('click', () => {
delayedWebShare(550)
});
document.querySelector('#test-web-share-999').addEventListener('click', () => {
delayedWebShare(999)
});
document.querySelector('#test-web-share-1005').addEventListener('click', () => {
delayedWebShare(1005)
});
</script>
</body>
</html>