diff --git a/src/background/actions.ts b/src/background/actions.ts index 946cfd8..c539ee6 100644 --- a/src/background/actions.ts +++ b/src/background/actions.ts @@ -1,6 +1,6 @@ import { Actions, Request } from "../common"; import { sendMessage } from "./messaging"; -import { logger } from "./common"; +import { logger } from "./logger"; /** * redirect tab to url. diff --git a/src/background/caches.ts b/src/background/caches.ts index 1ee79a1..c51f2ea 100644 --- a/src/background/caches.ts +++ b/src/background/caches.ts @@ -1,4 +1,4 @@ -import { logger } from "./common"; +import { logger } from "./logger"; import { Actions } from "../common"; import { messageSubscribers } from "./messaging"; @@ -26,4 +26,6 @@ export class Caches { } }, 30000); } -} \ No newline at end of file +} + +export const caches = new Caches(); diff --git a/src/background/common.ts b/src/background/common.ts deleted file mode 100644 index 9b6960f..0000000 --- a/src/background/common.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Logger, LOGGER_LEVEL } from "./logger"; -import { Caches } from "./caches"; - -export const caches = new Caches(); -export const logger = new Logger(LOGGER_LEVEL.DEBUG, LOGGER_LEVEL.DISABLED); -export const URL_REG = /^\s*(https?):\/\//im; diff --git a/src/background/extractor.ts b/src/background/extractor.ts index 59f2391..56a5a81 100644 --- a/src/background/extractor.ts +++ b/src/background/extractor.ts @@ -1,8 +1,9 @@ import { Task } from "./task"; import { saveFile } from "./tools"; import { createTab, getActiveTab, ping } from "./actions"; -import { logger, caches } from "./common"; import { ExtractResult } from "./result"; +import { logger } from "./logger"; +import { caches } from "./caches"; export class Extractor { private _tasks: Task[] = []; diff --git a/src/background/logger.ts b/src/background/logger.ts index beceee0..4f2ff68 100644 --- a/src/background/logger.ts +++ b/src/background/logger.ts @@ -71,3 +71,5 @@ export class Logger { ); } } + +export const logger = new Logger(LOGGER_LEVEL.DEBUG, LOGGER_LEVEL.DISABLED); diff --git a/src/background/messaging.ts b/src/background/messaging.ts index dbcb79c..d01de8d 100644 --- a/src/background/messaging.ts +++ b/src/background/messaging.ts @@ -1,6 +1,6 @@ import { Request, Actions } from "../common"; import { getTabByID } from "./actions"; -import { logger } from "./common"; +import { logger } from "./logger"; /** * Sending a message to target tab repeatedly until the response is not undefined. @@ -49,7 +49,13 @@ export function sendMessage( let result: T = r; if (dataChecker) { - let pms = dataChecker(r, err, count); + let pms: T | Promise; + try { + pms = dataChecker(r, err, count); + } catch (error) { + reject(error); + return; + } // don't catch if it's not a Promise if (pms instanceof Promise) { let checkerError: any; diff --git a/src/background/task.ts b/src/background/task.ts index 3b8b99d..9954b1e 100644 --- a/src/background/task.ts +++ b/src/background/task.ts @@ -4,7 +4,7 @@ import { testArgs, signitures } from "./signiture"; import { ExtractResult } from "./result"; import { messageSubscribers, ActionSubscriber } from "./messaging"; import { Actions } from "../common"; -import { logger } from "./common"; +import { logger } from "./logger"; export class Task { private _data: { [key: string]: string[][] } = {}; diff --git a/src/background/tools.ts b/src/background/tools.ts index 18bfc07..d293c68 100644 --- a/src/background/tools.ts +++ b/src/background/tools.ts @@ -1,6 +1,7 @@ -import { URL_REG } from "./common"; import { ExtractResult } from "./result"; +const URL_REG = /^\s*(https?):\/\//im; + export function parseUrls(...args) { if (!args.length) return []; let arg = args.shift();