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:
1 parent
5f67725a60
commit
0a53bbd942
4 files changed
+13
-7
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
// app.js - Logic for Magnetflix Page
|
// app.js - Logic for Magnetflix Page
|
||||||
const browserAPI = window.browser || window.chrome;
|
const browserAPI = typeof browser !== "undefined" ? browser : (typeof chrome !== "undefined" ? chrome : null);
|
||||||
|
|
||||||
// State
|
// State
|
||||||
let selectedMovie = null;
|
let selectedMovie = null;
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// Background script for Magnetflix extension
|
// 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
|
// Listen for messages from content scripts and popups
|
||||||
browserAPI.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
browserAPI.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||||
|
|||||||
+10
-4
@@ -1,6 +1,6 @@
|
|||||||
// Content script for Magnetflix: intercepts magnet links and displays popup modal
|
// Content script for Magnetflix: intercepts magnet links and displays popup modal
|
||||||
(function () {
|
(function () {
|
||||||
const browserAPI = window.browser || window.chrome;
|
const browserAPI = typeof browser !== "undefined" ? browser : (typeof chrome !== "undefined" ? chrome : null);
|
||||||
let activeModalHost = null;
|
let activeModalHost = null;
|
||||||
|
|
||||||
// Helper to extract display name from magnet link
|
// Helper to extract display name from magnet link
|
||||||
@@ -330,14 +330,20 @@
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
|
// Show popup modal on the page
|
||||||
|
showMagnetModal(href);
|
||||||
|
|
||||||
// Inform background script of captured magnet
|
// Inform background script of captured magnet
|
||||||
|
if (browserAPI && browserAPI.runtime && browserAPI.runtime.sendMessage) {
|
||||||
|
try {
|
||||||
browserAPI.runtime.sendMessage({
|
browserAPI.runtime.sendMessage({
|
||||||
action: "magnet_captured",
|
action: "magnet_captured",
|
||||||
magnet: href
|
magnet: href
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
// Show popup modal on the page
|
console.warn("Magnetflix: Could not notify background script:", err);
|
||||||
showMagnetModal(href);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// popup.js for Magnetflix toolbar popup
|
// 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";
|
const SAMPLE_MAGNET = "magnet:?xt=urn:btih:1234567890abcdef1234567890abcdef12345678&dn=Perfect.Blue.1997.1080p.BluRay.x264";
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user