about summary refs log tree commit diff stats
path: root/src/pages/background
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2024-08-19 11:49:21 +0300
committerManeraKai <manerakai@protonmail.com>2024-08-19 11:49:21 +0300
commitb4575df1594748d29faa924b5531a99878bd4dc9 (patch)
tree4a34020ed279dbab94060df0ed7ec1c14ff067bf /src/pages/background
parentAdded redirectOnlyInIncognito to each service https://github.com/libredirect/... (diff)
downloadlibredirect-b4575df1594748d29faa924b5531a99878bd4dc9.zip
Disabled onlyEmbed redirection if documentUrl is the actual target https://codeberg.org/LibRedirect/browser_extension/issues/127
Diffstat (limited to 'src/pages/background')
-rw-r--r--src/pages/background/background.js20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index 576365bd..16ca38d7 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -28,15 +28,17 @@ browser.webRequest.onBeforeRequest.addListener(
     const old_href = url.href
     if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest")
       return
-    let initiator
+    let originUrl
     try {
-      if (details.originUrl) initiator = new URL(details.originUrl)
-      else if (details.initiator && details.initiator !== "null") initiator = new URL(details.initiator)
+      if (details.originUrl) originUrl = new URL(details.originUrl)
     } catch {
       return null
     }
+    let documentUrl
+    try { if (details.documentUrl) documentUrl = new URL(details.documentUrl) }
+    catch (error) { return null }
     if (tabIdRedirects[details.tabId] == false) return null
-    let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId], details.incognito)
+    let newUrl = servicesHelper.redirect(url, details.type, originUrl, documentUrl, tabIdRedirects[details.tabId], details.incognito)
 
     if (
       details.frameAncestors &&
@@ -103,7 +105,7 @@ browser.runtime.getPlatformInfo(r => {
             browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
               if (tabs[0].url) {
                 const url = new URL(tabs[0].url)
-                const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
+                const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
                 if (newUrl) {
                   browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
                     tabIdRedirects[tabs[0].id] = true
@@ -209,7 +211,7 @@ browser.runtime.getPlatformInfo(r => {
           browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
             if (tabs[0].url) {
               const url = new URL(tabs[0].url)
-              const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
+              const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
               if (newUrl) {
                 browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
                   tabIdRedirects[tabs[0].id] = true
@@ -226,7 +228,7 @@ browser.runtime.getPlatformInfo(r => {
         case "redirectLink":
         case "redirectLinkInNewTab": {
           const url = new URL(info.linkUrl)
-          const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
+          const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
           if (newUrl) {
             if (info.menuItemId == "redirectLink") browser.tabs.update({ url: newUrl })
             else browser.tabs.create({ url: newUrl })
@@ -274,7 +276,7 @@ browser.runtime.getPlatformInfo(r => {
         case "redirectBookmarkInNewTab":
           browser.bookmarks.get(info.bookmarkId, bookmarks => {
             const url = new URL(bookmarks[0].url)
-            const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
+            const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
             if (newUrl) {
               if (info.menuItemId == "redirectBookmark") browser.tabs.update({ url: newUrl })
               else browser.tabs.create({ url: newUrl })
@@ -328,7 +330,7 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
     browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
       if (tabs[0].url) {
         const url = new URL(tabs[0].url)
-        const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
+        const newUrl = servicesHelper.redirect(url, "main_frame", null, null, true)
         if (newUrl) browser.tabs.update(tabs[0].id, { url: newUrl }, () => (tabIdRedirects[tabs[0].id] = true))
       }
     })