Greetings everyone, this is my first post here!
I'm currently working on a chrome extension where I am utilizing a recursive setTimeout function. Interestingly, I've noticed that setting the timeout to 13 seconds works fine, but anything beyond 14 seconds does not. Hmm...
Let me share a snippet from my background.js to illustrate:
function start() {
var timeout = setTimeout( function() { start(); }, 1000*15);
alert('test');
}
chrome.webNavigation.onCompleted.addListener(function(o) {
start();
}, {
url: [
{urlContains: 'http://www.example.com/in.php'},
{urlContains: 'http://www.example.com/out.php'}
]
}
);
Interestingly, reducing the timeout to 1000*13 makes it work smoothly.
Here's a glimpse of my manifest.json file:
{
"name": "Extension",
"version": "0.0.7",
"manifest_version": 2,
"description": "Keeps proxy session alive",
"homepage_url": "http://www.example.com",
"icons": {
"16": "icons/icon16-on.png",
"48": "icons/icon48-on.png",
"128": "icons/icon128-on.png"
},
"default_locale": "en",
"background": {
"scripts": [
"src/bg/background.js"
],
"persistent": false
},
"browser_action": {
"default_icon": "icons/icon19.png",
"default_title": "Example - Off",
"default_popup": ""
},
"permissions": [
"webNavigation",
"*://*/*",
"https://*/*"
]
}
Any thoughts on what could be causing this strangeness? I'm just experimenting in developer mode, by the way.
Appreciate any wisdom you can share!
EDIT
Issue has been resolved:
manifest.json
Added "alarms" to the permissions
background.js
Introduced an event listener for alarms.create:
chrome.alarms.onAlarm.addListener(function(alarm){
start();
});
Replaced the setTimeout function with the line below:
chrome.alarms.create("Start", {periodInMinutes:1});
Hope this update is helpful to others facing a similar challenge!