diff --git a/app.js b/app.js index 8712c35..fce7c3f 100644 --- a/app.js +++ b/app.js @@ -1,5 +1,5 @@ // app.js - Logic for Magnetflix Page -const browserAPI = window.browser || window.chrome; +const browserAPI = typeof browser !== "undefined" ? browser : (typeof chrome !== "undefined" ? chrome : null); // State let selectedMovie = null; diff --git a/background.js b/background.js index e55dde8..3cf1410 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,5 @@ // Background script for Magnetflix extension -const browserAPI = window.browser || window.chrome; +const browserAPI = typeof browser !== "undefined" ? browser : (typeof chrome !== "undefined" ? chrome : null); // Listen for messages from content scripts and popups browserAPI.runtime.onMessage.addListener((request, sender, sendResponse) => { diff --git a/content.js b/content.js index 7dc1c07..bec50dc 100644 --- a/content.js +++ b/content.js @@ -1,6 +1,6 @@ // Content script for Magnetflix: intercepts magnet links and displays popup modal (function () { - const browserAPI = window.browser || window.chrome; + const browserAPI = typeof browser !== "undefined" ? browser : (typeof chrome !== "undefined" ? chrome : null); let activeModalHost = null; // Helper to extract display name from magnet link @@ -330,14 +330,20 @@ event.preventDefault(); event.stopPropagation(); - // Inform background script of captured magnet - browserAPI.runtime.sendMessage({ - action: "magnet_captured", - magnet: href - }); - // Show popup modal on the page showMagnetModal(href); + + // Inform background script of captured magnet + if (browserAPI && browserAPI.runtime && browserAPI.runtime.sendMessage) { + try { + browserAPI.runtime.sendMessage({ + action: "magnet_captured", + magnet: href + }); + } catch (err) { + console.warn("Magnetflix: Could not notify background script:", err); + } + } } } }, diff --git a/popup.js b/popup.js index 6dcfae8..fad3202 100644 --- a/popup.js +++ b/popup.js @@ -1,5 +1,5 @@ // popup.js for Magnetflix toolbar popup -const browserAPI = window.browser || window.chrome; +const browserAPI = typeof browser !== "undefined" ? browser : (typeof chrome !== "undefined" ? chrome : null); const SAMPLE_MAGNET = "magnet:?xt=urn:btih:1234567890abcdef1234567890abcdef12345678&dn=Perfect.Blue.1997.1080p.BluRay.x264";