Enable strict mode for extension build

This commit is contained in:
hensm
2020-01-23 00:58:33 +00:00
parent 3553912584
commit 7f84b90431
59 changed files with 526 additions and 331 deletions

View File

@@ -2,6 +2,7 @@
import defaultOptions from "../defaultOptions";
import loadSender from "../lib/loadSender";
import logger from "../lib/logger";
import options from "../lib/options";
import { getChromeUserAgent } from "../lib/userAgents";
@@ -67,6 +68,10 @@ function initBrowserAction () {
* top-level frame.
*/
browser.browserAction.onClicked.addListener(async tab => {
if (tab.id === undefined) {
throw logger.error("Tab ID not found in browser action handler.");
}
const selection = await ReceiverSelectorManager.getSelection(tab.id);
if (selection) {
@@ -140,6 +145,10 @@ async function initMenus () {
browser.menus.onClicked.addListener(async (info, tab) => {
if (info.parentMenuItemId === menuIdWhitelist) {
const pattern = whitelistChildMenuPatterns.get(info.menuItemId);
if (!pattern) {
throw logger.error(`Whitelist pattern not found for menu item ID ${info.menuItemId}.`);
}
const whitelist = await options.get("userAgentWhitelist");
// Add to whitelist and update options
@@ -150,6 +159,17 @@ async function initMenus () {
}
if (tab?.id === undefined) {
throw logger.error("Menu handler tab ID not found.");
}
if (info.frameId === undefined) {
throw logger.error("Menu handler frame ID not found.");
}
if (!info.pageUrl) {
throw logger.error("Menu handler page URL not found.");
}
const availableMediaTypes = getMediaTypesForPageUrl(info.pageUrl);
switch (info.menuItemId) {
@@ -157,6 +177,11 @@ async function initMenus () {
const selection = await ReceiverSelectorManager.getSelection(
tab.id, info.frameId);
// Selection cancelled
if (!selection) {
break;
}
loadSender({
tabId: tab.id
, frameId: info.frameId
@@ -447,6 +472,10 @@ function initWhitelist () {
const { os } = await browser.runtime.getPlatformInfo();
const chromeUserAgent = getChromeUserAgent(os);
if (!details.requestHeaders) {
throw logger.error("OnBeforeSendHeaders handler details missing requestHeaders.");
}
const host = details.requestHeaders.find(
header => header.name === "Host");
@@ -457,7 +486,7 @@ function initWhitelist () {
* so pretend to be an old version of Chrome to get the old
* site.
*/
if (host.value === "www.youtube.com") {
if (host?.value === "www.youtube.com") {
header.value = getChromeUserAgent(os, true);
break;
}