Fix addon not working with Firefox

pull/25/head v0.6.1
neobooru 2021-02-01 12:47:03 +01:00
parent 225981d26d
commit 091693c15a
3 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "szuru-chrome", "name": "szuru-chrome",
"version": "0.6.0", "version": "0.6.1",
"description": "Import media from various sites into szurubooru.", "description": "Import media from various sites into szurubooru.",
"author": "neobooru", "author": "neobooru",
"license": "MIT", "license": "MIT",

View File

@ -30,3 +30,7 @@ export function getUrl(root: string, ...parts: string[]): string {
} }
return url; return url;
} }
export function isChrome() {
return /Chrome/.test(navigator.userAgent);
}

View File

@ -100,7 +100,7 @@ import { ScrapedPost, ScrapedTag, ScrapeResults } from "neo-scraper";
import SzuruWrapper from "../SzuruWrapper"; import SzuruWrapper from "../SzuruWrapper";
import { Post, SzuruError } from "../SzuruTypes"; import { Post, SzuruError } from "../SzuruTypes";
import { Config, SzuruSiteConfig } from "../Config"; import { Config, SzuruSiteConfig } from "../Config";
import { BrowserCommand, Message, getUrl } from "../Common"; import { BrowserCommand, Message, getUrl, isChrome } from "../Common";
class ScrapedPostViewModel extends ScrapedPost { class ScrapedPostViewModel extends ScrapedPost {
name: string = ""; name: string = "";
@ -324,6 +324,11 @@ export default Vue.extend({
} }
}); });
let extraInfoSpec: WebRequest.OnBeforeSendHeadersOptions[] = ["requestHeaders", "blocking"];
if (isChrome()) {
extraInfoSpec.push("extraHeaders" as any);
}
browser.webRequest.onBeforeSendHeaders.addListener( browser.webRequest.onBeforeSendHeaders.addListener(
(details: WebRequest.OnBeforeSendHeadersDetailsType) => { (details: WebRequest.OnBeforeSendHeadersDetailsType) => {
let requestHeaders = details.requestHeaders ?? []; let requestHeaders = details.requestHeaders ?? [];
@ -342,7 +347,7 @@ export default Vue.extend({
}; };
}, },
{ urls: ["<all_urls>"] }, { urls: ["<all_urls>"] },
["requestHeaders", "blocking", "extraHeaders" as any] extraInfoSpec
); );
// Always call grabPost, even when there is no activeSite // Always call grabPost, even when there is no activeSite