Skip to content

Instantly share code, notes, and snippets.

@fregante
Last active September 30, 2022 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fregante/60fb96400de9efedc4d36af47dd4b794 to your computer and use it in GitHub Desktop.
Save fregante/60fb96400de9efedc4d36af47dd4b794 to your computer and use it in GitHub Desktop.
MV3 lifetime test
// Respond to CS
const startTime = Date.now()
const delay = 13000;
chrome.runtime.onMessage.addListener( (message, sender, respond) => {
setTimeout(respond, delay, Math.round((Date.now() - startTime + delay) / 1000));
return true
})
// Overlapping fetch requests
console.log('will req');
let id = new Date().getMinutes() + ':'
let i = 0;
chrome.storage.local.get().then(console.log)
setInterval(async () => {
const thisId = id + i;
i++;
console.log(thisId, 'req')
chrome.storage.local.set({[thisId]: 'req'})
await fetch('https://deelay.me/19000/https://pixiebrix.com')
console.log(thisId, 'req done')
chrome.storage.local.set({[thisId]: 'req done'})
}, 13000);
console.log('Starting');
setInterval(() => {
console.log('sending')
chrome.runtime.sendMessage('lifetime in seconds', console.log)
}, 7000);
{
"manifest_version": 3,
"name": "MV3 test",
"version": "0.0.0",
"permissions": ["storage"],
"background": {
"service_worker": "background.worker.js"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["content.js"]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment