diff --git a/apps/acf-extension/src/background/check-blog.ts b/apps/acf-extension/src/background/check-blog.ts index a2e9f6d7..34291549 100644 --- a/apps/acf-extension/src/background/check-blog.ts +++ b/apps/acf-extension/src/background/check-blog.ts @@ -1,6 +1,6 @@ import { TabsMessenger } from './tab'; -const LOCAL_STORAGE_VERSION = 'version'; +const BLOG_VERSION = 'blog-version'; export class Blog { static async check(optionsPageUrl?: string) { if (optionsPageUrl) { @@ -10,7 +10,7 @@ export class Blog { const regexResult = /\d+\.\d+\.\d+/.exec(response); if (regexResult) { const version = regexResult[0]; - const { version: storageVersion } = await chrome.storage.local.get(LOCAL_STORAGE_VERSION); + const { [BLOG_VERSION]: storageVersion } = await chrome.storage.local.get(BLOG_VERSION); if (storageVersion === undefined) { Blog.update(version); } else if (storageVersion !== version) { @@ -18,7 +18,8 @@ export class Blog { Blog.update(version); } } - }); + }) + .catch(console.error); } } @@ -27,6 +28,6 @@ export class Blog { } static update(version: string) { - chrome.storage.local.set({ [LOCAL_STORAGE_VERSION]: version }); + chrome.storage.local.set({ [BLOG_VERSION]: version }); } } diff --git a/apps/acf-extension/src/background/context-menu.ts b/apps/acf-extension/src/background/context-menu.ts index b53044ce..0a9265be 100644 --- a/apps/acf-extension/src/background/context-menu.ts +++ b/apps/acf-extension/src/background/context-menu.ts @@ -13,6 +13,7 @@ export default function registerContextMenus(optionsPageUrl?: string) { if (menuItemId === CONTEXT_MENU_CONFIG_PAGE_ID) { chrome.tabs.create({ url: optionsPageUrl }); } else if (menuItemId === ACTION_POPUP) { + console.info(tab); tab?.id && chrome.tabs.sendMessage(tab.id, { action: ACTION_POPUP }); } else if (menuItemId === CONTEXT_MENU_ELEMENT_ID) { const url = new URL(optionsPageUrl); diff --git a/apps/acf-extension/src/background/index.ts b/apps/acf-extension/src/background/index.ts index b099cce5..fffd3209 100644 --- a/apps/acf-extension/src/background/index.ts +++ b/apps/acf-extension/src/background/index.ts @@ -1,6 +1,5 @@ /* eslint-disable no-new */ -import { DateUtil } from '@dhruv-techapps/core-common'; -import { LOCAL_STORAGE_KEY, RUNTIME_MESSAGE_ACF } from '@dhruv-techapps/acf-common'; +import { RUNTIME_MESSAGE_ACF } from '@dhruv-techapps/acf-common'; import { Runtime } from '@dhruv-techapps/core-extension'; import registerContextMenus from './context-menu'; @@ -16,25 +15,23 @@ import GoogleOauth2 from './google-oauth2'; import DiscordMessaging from './discord-messaging'; import { sentryInit } from '../common/sentry'; +const EXTENSION_VERSION = 'extension-version'; + try { sentryInit('background'); /** * Browser Action set to open option page / configuration page */ - chrome.action.onClicked.addListener(async (tab) => { + chrome.action.onClicked.addListener((tab) => { tab.id && chrome.tabs.sendMessage(tab.id, { action: ACTION_POPUP }); }); /** * On initial install setup basic configuration */ - chrome.runtime.onInstalled.addListener(async () => { - const result = await chrome.storage.local.get(LOCAL_STORAGE_KEY.INSTALL_DATE); - if (!result[LOCAL_STORAGE_KEY.INSTALL_DATE]) { - chrome.storage.local.set({ [LOCAL_STORAGE_KEY.INSTALL_DATE]: DateUtil.getDateWithoutTime().toJSON() }); - TabsMessenger.optionsTab({ url: OPTIONS_PAGE_URL }); - } + chrome.runtime.onInstalled.addListener(() => { + TabsMessenger.optionsTab({ url: OPTIONS_PAGE_URL }); }); /** @@ -56,16 +53,25 @@ try { /** * On start up check for rate - * TODO Need to implement rate us feature */ - chrome.runtime.onStartup.addListener(async () => { - const result = await chrome.runtime.requestUpdateCheck(); - if (result.status === 'update_available') { - chrome.runtime.reload(); - } + chrome.runtime.onStartup.addListener(() => { + chrome.storage.local.get(EXTENSION_VERSION).then(({ [EXTENSION_VERSION]: version }) => { + const manifestVersion = chrome.runtime.getManifest().version; + if (version !== undefined && version !== manifestVersion) { + chrome.storage.local.remove(EXTENSION_VERSION); + chrome.runtime.reload(); + } + }); Blog.check(OPTIONS_PAGE_URL); }); + /** + * If an update is available it will auto update + */ + chrome.runtime.onUpdateAvailable.addListener(({ version }) => { + chrome.storage.local.set({ [EXTENSION_VERSION]: version }); + }); + /** * Setup on Message Listener */ diff --git a/apps/acf-extension/src/background/release.md b/apps/acf-extension/src/background/release.md new file mode 100644 index 00000000..a16ab36d --- /dev/null +++ b/apps/acf-extension/src/background/release.md @@ -0,0 +1,3 @@ +# Bug Fix + +- Fixed error chrome.runtime.requestUpdateCheck as its supported by latest version of chrome browser. diff --git a/apps/acf-extension/src/common/sentry.ts b/apps/acf-extension/src/common/sentry.ts index 927cf463..b086dc45 100644 --- a/apps/acf-extension/src/common/sentry.ts +++ b/apps/acf-extension/src/common/sentry.ts @@ -1,11 +1,53 @@ import * as Sentry from '@sentry/browser'; -import { NX_RELEASE_VERSION, VARIANT } from './environments'; +import { NX_RELEASE_VERSION, VARIANT } from './environments'; export const sentryInit = (page: string) => { Sentry.init({ dsn: 'https://23ec1ed44876c4cbe18082f514cc5901@o4506036997455872.ingest.sentry.io/4506037629943808', environment: VARIANT, - + ignoreErrors: [ + // Random plugins/extensions + 'top.GLOBALS', + // See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error.html + 'originalCreateNotification', + 'canvas.contentDocument', + 'MyApp_RemoveAllHighlights', + 'http://tt.epicplay.com', + "Can't find variable: ZiteReader", + 'jigsaw is not defined', + 'ComboSearch is not defined', + 'TypeError sentryWrapped', + 'TypeError: Illegal invocation', + 'UnhandledRejection: Non-Error promise rejection captured with value: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received', + 'http://loading.retry.widdit.com/', + 'atomicFindClose', + // Facebook borked + 'fb_xd_fragment', + // ISP "optimizing" proxy - `Cache-Control: no-transform` seems to + // reduce this. (thanks @acdha) + // See http://stackoverflow.com/questions/4113268 + 'bmi_SafeAddOnload', + 'EBCallBackMessageReceived', + // See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx + 'conduitPage', + ], + denyUrls: [ + // Facebook flakiness + /graph\.facebook\.com/i, + // Facebook blocked + /connect\.facebook\.net\/en_US\/all\.js/i, + // Woopra flakiness + /eatdifferent\.com\.woopra-ns\.com/i, + /static\.woopra\.com\/js\/woopra\.js/i, + // Chrome extensions + /extensions\//i, + /^chrome:\/\//i, + // Other plugins + /127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb + /webappstoolbarba\.texthelp\.com\//i, + /metrics\.itunes\.apple\.com\.edgesuite\.net\//i, + ], + allowUrls: [new RegExp(`chrome-extension://${chrome.runtime.id}`, 'i')], // Alternatively, use `process.env.npm_package_version` for a dynamic release version // if your build tool supports it. release: `acf-extension@${NX_RELEASE_VERSION?.replace('v', '')}`, diff --git a/apps/acf-extension/src/content_scripts/addon.ts b/apps/acf-extension/src/content_scripts/addon.ts index d402c492..59b90e78 100644 --- a/apps/acf-extension/src/content_scripts/addon.ts +++ b/apps/acf-extension/src/content_scripts/addon.ts @@ -81,14 +81,19 @@ const AddonProcessor = (() => { if (/than/gi.test(condition) && (Number.isNaN(Number(nodeValue)) || Number.isNaN(Number(value)))) { throw new ConfigError(`Greater || Less can only compare number '${nodeValue}' '${value}'`, 'Wrong Comparison'); } - if (typeof nodeValue === 'boolean') { - if (nodeValue && condition === ADDON_CONDITIONS['✓ Is Checked ']) { - return true; - } else if (!nodeValue && condition === ADDON_CONDITIONS['✕ Is Not Checked ']) { - return true; + if (typeof nodeValue === 'boolean' || condition === ADDON_CONDITIONS['✓ Is Checked '] || condition === ADDON_CONDITIONS['✕ Is Not Checked ']) { + if (typeof nodeValue === 'boolean') { + if (nodeValue && condition === ADDON_CONDITIONS['✓ Is Checked ']) { + return true; + } else if (!nodeValue && condition === ADDON_CONDITIONS['✕ Is Not Checked ']) { + return true; + } + return false; + } else { + throw new ConfigError('Element Finder need to point checkbox', 'Wrong Element Finder / Addon Condition'); } - return false; } + switch (condition) { case ADDON_CONDITIONS['= Equals']: return new RegExp(`^${value}$`, 'gi').test(nodeValue); diff --git a/apps/acf-extension/src/content_scripts/config.ts b/apps/acf-extension/src/content_scripts/config.ts index 61344661..db7fb28e 100644 --- a/apps/acf-extension/src/content_scripts/config.ts +++ b/apps/acf-extension/src/content_scripts/config.ts @@ -66,6 +66,8 @@ const ConfigProcessor = (() => { ]); } } + } else { + console.error(error.title, '\n', error.message); } } else { throw e; @@ -100,7 +102,7 @@ const ConfigProcessor = (() => { Logger.colorDebug('Config Start Manually'); ActionService.setBadgeText(chrome.runtime.id, { text: 'Manual' }); ActionService.setTitle(chrome.runtime.id, { title: 'Start Manually' }); - Hotkey.setup(config.hotkey, start.bind(this, config)); + Hotkey.setup(start.bind(this, config), config.hotkey); } else { Logger.colorDebug('Config Start Automatically'); ActionService.setBadgeText(chrome.runtime.id, { text: 'Auto' }); diff --git a/apps/acf-extension/src/content_scripts/hotkey.ts b/apps/acf-extension/src/content_scripts/hotkey.ts index eb5fa02d..c7c9bc70 100644 --- a/apps/acf-extension/src/content_scripts/hotkey.ts +++ b/apps/acf-extension/src/content_scripts/hotkey.ts @@ -4,11 +4,11 @@ import { Logger } from '@dhruv-techapps/core-common'; const LOGGER_LETTER = 'Hotkey'; export const Hotkey = (() => { - const setup = (hotkey: string = defaultHotkey, start: () => void) => { + const setup = (start: () => void, hotkey: string = defaultHotkey) => { Logger.colorDebug(LOGGER_LETTER, hotkey); document.addEventListener('keydown', ({ ctrlKey, shiftKey, altKey, code }) => { const key = hotkey.split('+').pop()?.trim(); - if (code.replace(/key/gi, '') === key) { + if (code !== undefined && code.replace(/key/gi, '') === key) { if (/ctrl/gi.test(hotkey) === ctrlKey && /alt/gi.test(hotkey) === altKey && /shift/gi.test(hotkey) === shiftKey) { start(); } diff --git a/apps/acf-extension/src/wizard/popup.ts b/apps/acf-extension/src/wizard/popup.ts index 6d87e755..316e3472 100644 --- a/apps/acf-extension/src/wizard/popup.ts +++ b/apps/acf-extension/src/wizard/popup.ts @@ -9,12 +9,14 @@ export const Popup = (() => { const setHover = (xpath: string, operation: 'add' | 'remove') => { xpath = WizardElementUtil.clearXpath(xpath); - const nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - if (nodes.snapshotLength !== 0) { - let i = 0; - while (i < nodes.snapshotLength) { - (nodes.snapshotItem(i) as HTMLElement).classList[operation]('auto-clicker-hover'); - i += 1; + if (xpath) { + const nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + if (nodes.snapshotLength !== 0) { + let i = 0; + while (i < nodes.snapshotLength) { + (nodes.snapshotItem(i) as HTMLElement).classList[operation]('auto-clicker-hover'); + i += 1; + } } } }; @@ -40,8 +42,10 @@ export const Popup = (() => { }) as EventListener); popupContainer.addEventListener('element-focus', ((e: CustomEvent) => { const xpath = WizardElementUtil.clearXpath(e.detail.xpath); - const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); - (result.singleNodeValue).focus(); + if (xpath) { + const result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); + (result.singleNodeValue).focus(); + } }) as EventListener); };