I am trying to write a safari web extension that redirects users to Y URL if they type X URL without ever loading the X URL.
The piece of code that I have attached below works smoothly on chrome, but not on safari.
background.js
function onBeforeNavigate(event) {
const redirectURL = "https://google.com/"
chrome.tabs.update(event.tabId, { url: redirectURL })
}
chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate,{
url: [
{urlMatches: "https://girlcodeit.com/*"},
{urlMatches: "http://girlcodeit.com/*"}
]
})
manifest.json
"manifest_version": 2,
"name": "",
"description": "",
"version": "1.0",
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"webNavigation",
"tabs"
]
}
I have tried writing browser.tabs.update and just tabs.update in place of chrome.tabs.update in safari version, no change.
I want to achieve the redirection anyhow through a safari web extension, please suggest changes in this one or share any other approaches.
webRequestBlocking is not supported by Safari, so that doesn't work either.