Skip to content

Commit 9d9362c

Browse files
authoredFeb 23, 2023
Add files via upload
1 parent d78cd95 commit 9d9362c

File tree

9 files changed

+84
-0
lines changed

9 files changed

+84
-0
lines changed
 
10.4 KB
Loading

‎TEST_SW_EXTPAGE_AND_OSD/img/ico16.png

1.47 KB
Loading

‎TEST_SW_EXTPAGE_AND_OSD/manifest.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "Test OSD, EXTPage & SW",
4+
"short_name": "XXX",
5+
"version": "0.0.0.1",
6+
"description": "Questa estensione mi permette di testare...",
7+
"background": {
8+
"service_worker": "worker_wrapper.js"
9+
},
10+
"chrome_url_overrides": { "newtab": "newpage.html" },
11+
"action": {
12+
"default_icon": {
13+
"128": "img/ico128.png",
14+
"16": "img/ico16.png"
15+
}
16+
},
17+
"permissions": [
18+
"offscreen"
19+
]
20+
}

‎TEST_SW_EXTPAGE_AND_OSD/newpage.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8" />
4+
<title>NewTab</title>
5+
<script src="script/newpage.js"></script>
6+
</head>
7+
<body>Newpage</body>
8+
</html>

‎TEST_SW_EXTPAGE_AND_OSD/osd.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<script src="script/osd.js"></script>
6+
</head>
7+
<body>
8+
<audio id="mp3"></audio>
9+
</body>
10+
</html>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function OSCreateDocument(u, j, r) {
2+
return new Promise(async res => {
3+
try {
4+
await chrome.offscreen.createDocument({ 'url': u, 'justification': j, 'reasons': r });
5+
res()
6+
} catch(e) {
7+
res()
8+
}
9+
})
10+
}
11+
12+
async function openOSD() {
13+
await OSCreateDocument('osd.html', 'ignored', ['DOM_PARSER']); /* I open the OSD */
14+
var e = '<table><tr><td>foo</td><td id="bar">bar</td></tr><table>'
15+
let reply = await chrome.runtime.sendMessage({'cmd': 'DOMParser', 'html': e}); /* I send my message */
16+
chrome.offscreen.closeDocument() /* I close the document without waiting */
17+
console.log(reply)
18+
}
19+
20+
chrome.tabs.create({'url': chrome.runtime.getURL('newpage.html') })
21+
22+
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
23+
/* Here I receive messages addressed to the SW but SOMETIME also those addressed to the OSD */
24+
console.log("SW runtime.onMessage", request)
25+
});
26+
27+
chrome.action.onClicked.addListener(t => openOSD() );
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) =>
2+
/* Here I receive also messages addressed to the OSD, Why???? */
3+
console.log("Extension page runtime.onMessage", request)
4+
)

‎TEST_SW_EXTPAGE_AND_OSD/script/osd.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
2+
console.log("OSD runtime.onMessage", msg)
3+
if (msg.cmd == 'DOMParser') {
4+
let parser = new DOMParser();
5+
let doc = parser.parseFromString(msg.html, 'text/html');
6+
let tc = doc.getElementById('bar').textContent;
7+
let reply = {};
8+
sendResponse(tc)
9+
}
10+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
try {
2+
importScripts('/script/main.js');
3+
} catch (e) {
4+
console.log(e)
5+
}

0 commit comments

Comments
 (0)
Please sign in to comment.