fix: use blob URL for Firefox downloads (data: URLs access-denied) (#3)
build-extension / build (push) Successful in 34s

This commit was merged in pull request #3.
This commit is contained in:
2026-08-18 20:12:20 +00:00
parent d08b1d75aa
commit 89fd587c21
2 changed files with 17 additions and 9 deletions
+16 -8
View File
@@ -10,11 +10,19 @@ function errMsg(err) {
return String((err && err.message) || err);
}
// Build a download URL from PDF bytes. Chrome MV3 runs the background as a
// service worker, where URL.createObjectURL is NOT available, so we use a
// base64 data URL (works in both Firefox and Chrome). PDFs here are small
// (~150KB), well within data-URL length limits.
function pdfDataUrl(bytes) {
// Build a download URL from PDF bytes. Firefox's background is a real page
// (URL.createObjectURL available) and supports blob: URLs in downloads.
// Chrome MV3 runs the background as a service worker where URL.createObjectURL
// is NOT available, but its downloads API accepts base64 data: URLs.
// Firefox rejects data: URLs in browser.downloads.download with
// "Access denied for URL data:...", so pick per-browser.
function buildDownloadUrl(bytes) {
if (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function') {
const blob = new Blob([bytes], { type: 'application/pdf' });
return URL.createObjectURL(blob);
}
// Fallback: Chrome MV3 service worker. PDFs here are small (~150KB), well
// within data-URL length limits.
let binary = '';
const chunk = 0x8000;
for (let i = 0; i < bytes.length; i += chunk) {
@@ -45,9 +53,9 @@ function formatPeriod(period) {
async function generatePdf(data) {
const bytes = await ISMIStools.buildStudyLoadPdf(data);
// Chrome MV3 background is a service worker (no URL.createObjectURL), so we
// use a base64 data URL that works in both browsers.
const url = pdfDataUrl(bytes);
// Firefox accepts blob: object URLs; Chrome MV3 service worker has no
// URL.createObjectURL, so it falls back to a base64 data: URL there.
const url = buildDownloadUrl(bytes);
const header = data.header || {};
const year = parseInt(data.year, 10);
const period = formatPeriod(data.period || header.semester || '');
+1 -1
View File
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "ISMIS Helper",
"version": "1.2.0",
"version": "1.3.0",
"description": "Auto-login, auto-accept privacy policy, and Study Load PDF for the USC ISMIS portal.",
"permissions": ["storage", "downloads"],
"host_permissions": ["https://ismis.usc.edu.ph/*"],