I made a micro extension made for use.
The creation and the updating of notification is not in backgrounf script.
const numIndic = 10;
function someSecs() {
return new Promise((ok, ko) =>
setTimeout(ok, 2000 + parseInt(1000*Math.random()))
)
}
function go() {
var title, message, iconUrl;
var progress = 0;
var opt = {
type: 'progress',
iconUrl: '../img/wait.png',
title: 'Printing...',
message: '0 of ' + numIndic,
priority: 2,
requireInteraction: true,
progress: 0
};
chrome.notifications.create('Printing', opt, async function(id0) {
console.log(id0);
for (let r = 0; r < numIndic; r++) {
progress = (100 * (r + 1)) / numIndic;
await someSecs();
console.log('one step more...');
console.log(id0);
chrome.notifications.update(id0, {
message: (r + 1) + ' of ' + numIndic,
progress: parseInt(progress)
}, checkLastError);
}
console.log(id0);
chrome.notifications.update(id0, opt, () => {
opt = {
contextMessage: 'Done!',
iconUrl: '../img/pdfIco.png',
title: "Done!",
message: '',
progress: 100,
requireInteraction:false
};
chrome.notifications.update(id0, opt, () =>
chrome.notifications.clear(id0, checkLastError)
)
})
})
}
function lets_go() {
document.getElementById("go").addEventListener('click', go)
}
function checkLastError() {
if (chrome.runtime.lastError)
console.log(chrome.runtime.lastError.message);
else {
}
}
document.addEventListener('DOMContentLoaded', lets_go)