fix(extension): resolve browserAPI from global lexical scope instead of window

- In Firefox WebExtension content scripts, window is the webpage DOM window and does not expose extension APIs for security
- Access global browser/chrome identifiers directly via typeof checks
- Wrap background message dispatch in try-catch to prevent uncaught exceptions from blocking in-page modal display
This commit is contained in:
kiskaadee committed 2026-09-25 16:51:40 -05:00
1 parent 5f67725a60
commit 0a53bbd942
4 files changed
+16 -10

No files matched your search

+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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) => {
+13 -7
View File
@@ -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);
}
}
}
}
},
+1 -1
View File
@@ -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";