Post

Replies

Boosts

Views

Activity

Why tabs.update doesn't work if url filters are added?
I am trying to make a safari extension that will redirect some specific URLs to some other URLs. background.js function redirect(event) { console.log("called ") const redirectURL = "https://apple.com/" chrome.tabs.update(event.tabId, { url: redirectURL }) } // This works and redirects everything to apple.com chrome.webNavigation.onBeforeNavigate.addListener(redirect) /* tabs.update doesn't work as soon as URL filter is added, but the same piece of code works in a chrome extension but not in safari OnBeforeNavigate is called on accessing girlcodeit.com as the console statement is printed on accessing girlcodeit.com but tab is not updated. */ chrome.webNavigation.onBeforeNavigate.addListener(redirect, { 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" ] } How do I redirect only specific URLs and not all URLs or is there something wrong with the above piece of code, but because it works on chrome, it could be a bug in safari?
0
0
1.1k
Feb ’22
declarativeNetRequest - redirect action type not supported
I am trying to write a URL-redirection safari web extension. manifest.json "declarative_net_request": { "rule_resources": [ { "id": "ruleset", "enabled": true, "path": "rules.json" } ] }, "permissions": [ "declarativeNetRequest", "webNavigation" ] } Rules.json [ { "id": 1, "priority": 1, "action": { "type": "redirect", "redirect": { "regexSubstitution": "https://example.com/" } }, "condition": { "regexFilter": "http://*/", "resourceTypes": [ "main_frame" ] } } ] Expectation - any search should redirect to example.com Getting this error Non-fatal issue: Rule with id 1 is invalid. redirect is not a supported action type. The same code works fine in chrome as a chrome extension, giving error in safari browser only. Is redirect not supported by safari? If no, what other options do i have to achieve it?
1
0
1.9k
Feb ’22
webNavigate doesn't work in safari web extension with tabs.update
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.
3
2
1.7k
Feb ’22