Hey trying to redirect from page1 to page2 (within tab, not open new ones) at a specific time.
manifest.json:
{
"name": "Google",
"description": "Test",
"version": "1.0",
"manifest_version": 2,
"background": {"scripts":["script.js"]},
"permissions": [
"alarms",
"webRequest",
"*://www.google.com/*",
"webRequestBlocking"
]
}
script.js:
var host = "https://www.facebook.com/"
chrome.alarms.onAlarm.addListener(function(alarm){
return {redirectUrl: host}
})
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
return chrome.alarms.create("redirect", {when: Date.now() + 5000})
},{
urls: [
"*://www.google.com/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
["blocking"]
)
code to redirect was taken from This Question, code to use timer was taken from This Question
EDIT: Solution thanks to Xan's answer below
manifest.json
{
"name": "Google",
"description": "Test",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [{
"matches": ["*://www.google.com/*"],
"js": ["script.js"]
}]
}
script.js (modify setTimeout with Date.now() to get correct wait)
setTimeout(function() {
window.location = "https://www.facebook.com/"
}, 5000)