diff --git a/apps/acf-extension/src/background/check-blog.ts b/apps/acf-extension/src/background/check-blog.ts deleted file mode 100644 index 34291549..00000000 --- a/apps/acf-extension/src/background/check-blog.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { TabsMessenger } from './tab'; - -const BLOG_VERSION = 'blog-version'; -export class Blog { - static async check(optionsPageUrl?: string) { - if (optionsPageUrl) { - fetch('https://blog.getautoclicker.com/feed.xml') - .then((response) => response.text()) - .then(async (response) => { - const regexResult = /\d+\.\d+\.\d+/.exec(response); - if (regexResult) { - const version = regexResult[0]; - const { [BLOG_VERSION]: storageVersion } = await chrome.storage.local.get(BLOG_VERSION); - if (storageVersion === undefined) { - Blog.update(version); - } else if (storageVersion !== version) { - Blog.show(optionsPageUrl, version); - Blog.update(version); - } - } - }) - .catch(console.error); - } - } - - static show(optionsPageUrl: string, version: string) { - TabsMessenger.optionsTab({ url: `${optionsPageUrl}?version=${version}` }); - } - - static update(version: string) { - chrome.storage.local.set({ [BLOG_VERSION]: version }); - } -} diff --git a/apps/acf-extension/src/background/index.ts b/apps/acf-extension/src/background/index.ts index fffd3209..44d2a6f0 100644 --- a/apps/acf-extension/src/background/index.ts +++ b/apps/acf-extension/src/background/index.ts @@ -8,15 +8,12 @@ import DiscordOauth2 from './discord-oauth2'; import GoogleSheets from './google-sheets'; import GoogleBackup from './google-backup'; import { TabsMessenger } from './tab'; -import { Blog } from './check-blog'; import { ACTION_POPUP } from '../common/constant'; import { OPTIONS_PAGE_URL, UNINSTALL_URL } from '../common/environments'; import GoogleOauth2 from './google-oauth2'; import DiscordMessaging from './discord-messaging'; import { sentryInit } from '../common/sentry'; -const EXTENSION_VERSION = 'extension-version'; - try { sentryInit('background'); @@ -30,8 +27,12 @@ try { /** * On initial install setup basic configuration */ - chrome.runtime.onInstalled.addListener(() => { - TabsMessenger.optionsTab({ url: OPTIONS_PAGE_URL }); + chrome.runtime.onInstalled.addListener((details) => { + if (details.reason === 'update') { + TabsMessenger.optionsTab({ url: `${OPTIONS_PAGE_URL}?version=${details.previousVersion}` }); + } else if (details.reason === 'install') { + TabsMessenger.optionsTab({ url: OPTIONS_PAGE_URL }); + } }); /** @@ -51,27 +52,6 @@ try { chrome.runtime.setUninstallURL(UNINSTALL_URL); } - /** - * On start up check for rate - */ - 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/common/sentry.ts b/apps/acf-extension/src/common/sentry.ts index b4e751cb..c044e652 100644 --- a/apps/acf-extension/src/common/sentry.ts +++ b/apps/acf-extension/src/common/sentry.ts @@ -26,7 +26,6 @@ export const sentryInit = (page: string) => { 'canvas.contentDocument', 'MyApp_RemoveAllHighlights', 'http://tt.epicplay.com', - 'Extension context invalidated.', "Can't find variable: ZiteReader", 'jigsaw is not defined', 'ComboSearch is not defined', @@ -44,7 +43,6 @@ export const sentryInit = (page: string) => { 'EBCallBackMessageReceived', // See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx 'conduitPage', - 'Could not establish connection. Receiving end does not exist.', 'Non-Error promise rejection captured', ], denyUrls: [ diff --git a/apps/acf-extension/src/content_scripts/common.ts b/apps/acf-extension/src/content_scripts/common.ts index c6e579fd..10b07409 100644 --- a/apps/acf-extension/src/content_scripts/common.ts +++ b/apps/acf-extension/src/content_scripts/common.ts @@ -39,26 +39,26 @@ const Common = (() => { const getElements = async (document: Document, elementFinder: string, retry: number, retryInterval: number | string): Promise | undefined> => { Logger.colorDebug('GetElements', elementFinder); let elements: HTMLElement[] | undefined; - if (/^(id::|#)/gi.test(elementFinder)) { - const element = document.getElementById(elementFinder.replace(/^(id::|#)/gi, '')); - elements = element ? [element] : undefined; - } else if (/^Selector::/gi.test(elementFinder)) { - const element = document.querySelector(elementFinder.replace(/^Selector::/gi, '')); - elements = element ? [element] : undefined; - } else if (/^ClassName::/gi.test(elementFinder)) { - const classElements = document.getElementsByClassName(elementFinder.replace(/^ClassName::/gi, '')) as HTMLCollectionOf; - elements = classElements.length !== 0 ? Array.from(classElements) : undefined; - } else if (/^Name::/gi.test(elementFinder)) { - const nameElements = document.getElementsByName(elementFinder.replace(/^Name::/gi, '')); - elements = nameElements.length !== 0 ? Array.from(nameElements) : undefined; - } else if (/^TagName::/gi.test(elementFinder)) { - const tagElements = document.getElementsByTagName(elementFinder.replace(/^TagName::/gi, '')) as HTMLCollectionOf; - elements = tagElements.length !== 0 ? Array.from(tagElements) : undefined; - } else if (/^SelectorAll::/gi.test(elementFinder)) { - const querySelectAll = document.querySelectorAll(elementFinder.replace(/^SelectorAll::/gi, '')); - elements = querySelectAll.length !== 0 ? Array.from(querySelectAll) : undefined; - } else { - try { + try { + if (/^(id::|#)/gi.test(elementFinder)) { + const element = document.getElementById(elementFinder.replace(/^(id::|#)/gi, '')); + elements = element ? [element] : undefined; + } else if (/^Selector::/gi.test(elementFinder)) { + const element = document.querySelector(elementFinder.replace(/^Selector::/gi, '')); + elements = element ? [element] : undefined; + } else if (/^ClassName::/gi.test(elementFinder)) { + const classElements = document.getElementsByClassName(elementFinder.replace(/^ClassName::/gi, '')) as HTMLCollectionOf; + elements = classElements.length !== 0 ? Array.from(classElements) : undefined; + } else if (/^Name::/gi.test(elementFinder)) { + const nameElements = document.getElementsByName(elementFinder.replace(/^Name::/gi, '')); + elements = nameElements.length !== 0 ? Array.from(nameElements) : undefined; + } else if (/^TagName::/gi.test(elementFinder)) { + const tagElements = document.getElementsByTagName(elementFinder.replace(/^TagName::/gi, '')) as HTMLCollectionOf; + elements = tagElements.length !== 0 ? Array.from(tagElements) : undefined; + } else if (/^SelectorAll::/gi.test(elementFinder)) { + const querySelectAll = document.querySelectorAll(elementFinder.replace(/^SelectorAll::/gi, '')); + elements = querySelectAll.length !== 0 ? Array.from(querySelectAll) : undefined; + } else { const nodes = document.evaluate(elementFinder, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (nodes.snapshotLength !== 0) { elements = []; @@ -68,13 +68,14 @@ const Common = (() => { i += 1; } } - } catch (e) { - if (e instanceof Error) { - throw new ConfigError(`elementFinder: ${e.message.split(':')[1]}`, 'Invalid Xpath'); - } - throw new ConfigError(`elementFinder: ${JSON.stringify(e)}`, 'Invalid Xpath'); } + } catch (e) { + if (e instanceof Error) { + throw new ConfigError(e.message, 'Invalid Xpath'); + } + throw new ConfigError(JSON.stringify(e), 'Invalid Xpath'); } + if (!elements) { const doRetry = await retryFunc(retry, retryInterval); if (doRetry) { diff --git a/apps/acf-extension/src/content_scripts/config.ts b/apps/acf-extension/src/content_scripts/config.ts index db7fb28e..d08def99 100644 --- a/apps/acf-extension/src/content_scripts/config.ts +++ b/apps/acf-extension/src/content_scripts/config.ts @@ -52,19 +52,17 @@ const ConfigProcessor = (() => { const error = { title: e.title, message: `url : ${config.url}\n${e.message}` }; setBadgeError(); const { notifications } = await new SettingsStorage().getSettings(); - if (notifications) { - const { onError, sound, discord } = notifications; - if (onError) { - NotificationsService.create(chrome.runtime.id, { type: 'basic', ...error, silent: !sound, iconUrl: Common.getNotificationIcon() }, 'error'); - if (discord) { - DiscordMessagingService.error(chrome.runtime.id, e.title || 'Configuration Error', [ - ...getFields(config), - ...e.message.split('\n').map((info) => { - const [name, value] = info.split(':'); - return { name, value: value.replace(/'/g, '`') }; - }), - ]); - } + if (notifications && notifications.onError) { + const { sound, discord } = notifications; + NotificationsService.create(chrome.runtime.id, { type: 'basic', ...error, silent: !sound, iconUrl: Common.getNotificationIcon() }, 'error'); + if (discord) { + DiscordMessagingService.error(chrome.runtime.id, e.title || 'Configuration Error', [ + ...getFields(config), + ...e.message.split('\n').map((info) => { + const [name, value] = info.split(':'); + return { name, value: value.replace(/'/g, '`') }; + }), + ]); } } else { console.error(error.title, '\n', error.message); diff --git a/apps/acf-extension/webpack.config.js b/apps/acf-extension/webpack.config.js index 13ad5325..06b6ff66 100644 --- a/apps/acf-extension/webpack.config.js +++ b/apps/acf-extension/webpack.config.js @@ -51,21 +51,27 @@ module.exports = composePlugins(withNx(), (config, ctx) => { }, ], }); + config.plugins.push( new Dotenv({ path: config.watch ? path.resolve(config.context, '.env') : './.env', safe: true, systemvars: true, - }), - sentryWebpackPlugin({ - org: 'dhruv-techapps', - project: 'acf-extension', - telemetry: false, - authToken: process.env.SENTRY_AUTH_TOKEN, - release: { - name: process.env.NX_RELEASE_VERSION?.replace('v', ''), - }, }) ); + + if (config.mode === 'development') { + config.plugins.push( + sentryWebpackPlugin({ + org: 'dhruv-techapps', + project: 'acf-extension', + telemetry: false, + authToken: process.env.SENTRY_AUTH_TOKEN, + release: { + name: process.env.NX_RELEASE_VERSION?.replace('v', ''), + }, + }) + ); + } return config; }); diff --git a/apps/acf-options-page/src/main.tsx b/apps/acf-options-page/src/main.tsx index 47f60f59..e6c96fd4 100644 --- a/apps/acf-options-page/src/main.tsx +++ b/apps/acf-options-page/src/main.tsx @@ -9,7 +9,10 @@ import { sentryInit } from './sentry'; window.EXTENSION_ID = process.env[`NX_${BROWSER}_EXTENSION_ID`] ?? ''; -sentryInit(); +if (process.env.NODE_ENV !== 'development') { + sentryInit(); +} + const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); root.render( diff --git a/apps/acf-options-page/src/sentry.ts b/apps/acf-options-page/src/sentry.ts index b5ca520c..5613abe0 100644 --- a/apps/acf-options-page/src/sentry.ts +++ b/apps/acf-options-page/src/sentry.ts @@ -5,7 +5,7 @@ export const sentryInit = () => { Sentry.init({ dsn: 'https://aacf1f88c133d2c9b4823c4c0b485ecc@o4506036997455872.ingest.sentry.io/4506037000994816', release, - ignoreErrors: ['NetFunnel is not defined', 'adsbygoogle.push() error: No slot size for availableWidth=0'], + ignoreErrors: ['NetFunnel is not defined', 'adsbygoogle.push() error: No slot size for availableWidth=0', 'ResizeObserver loop completed with undelivered notifications.'], environment: process.env.NX_VARIANT, // This sets the sample rate to be 10%. You may want this to be 100% while // in development and sample at a lower rate in production diff --git a/apps/acf-options-page/webpack.config.js b/apps/acf-options-page/webpack.config.js index d9741f40..06bcf154 100644 --- a/apps/acf-options-page/webpack.config.js +++ b/apps/acf-options-page/webpack.config.js @@ -6,15 +6,17 @@ const { withReact } = require('@nx/react'); module.exports = composePlugins(withNx(), withReact(), (config) => { // Update the webpack config as needed here. // e.g. `config.plugins.push(new MyPlugin())` - config.plugins.push( - sentryWebpackPlugin({ - org: 'dhruv-techapps', - project: 'acf-options-page', - authToken: process.env.SENTRY_AUTH_TOKEN, - release: { - name: process.env.NX_RELEASE_VERSION, - }, - }) - ); + if (config.mode !== 'development') { + config.plugins.push( + sentryWebpackPlugin({ + org: 'dhruv-techapps', + project: 'acf-options-page', + authToken: process.env.SENTRY_AUTH_TOKEN, + release: { + name: process.env.NX_RELEASE_VERSION, + }, + }) + ); + } return config; });