blob: 0a85746b04142d55a351b9e2df1c5db4c815a82d (
plain)
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
|
<!DOCTYPE html>
<script src="utils.js"></script>
<script>
const params = new URLSearchParams(location.search);
// The main test page (restriction-notification.https.html) loads the initiator
// page, then the initiator page will prerender itself with the `prerendering`
// parameter.
const isPrerendering = params.has('prerendering');
if (!isPrerendering) {
loadInitiatorPage();
} else {
// Used to communicate with the initiator page.
const prerenderChannel = new PrerenderChannel('prerender-channel');
// Used to communicate with the main test page.
const testChannel = new PrerenderChannel('test-channel');
window.addEventListener('load', () => {
// Inform the initiator page that this page is ready to be activated.
prerenderChannel.postMessage('readyToActivate');
prerenderChannel.close();
});
document.addEventListener('prerenderingchange', () => {
// Accessing the Notification API is allowed after the prerendering state
// changed.
const permission = Notification.permission;
const notification = new Notification('New Notification');
notification.onerror = function(_) {
testChannel.postMessage('notification error');
testChannel.close();
}
notification.onshow = function() {
testChannel.postMessage('notification showed');
notification.close();
testChannel.close();
};
});
}
</script>
|