using my boilerplate yuh
This commit is contained in:
11
src/background/events/onHistoryStateUpdated.ts
Normal file
11
src/background/events/onHistoryStateUpdated.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* This event is fired when any tab's url changes.
|
||||
* This is useful for content scripts to know when SPA navigations occur.
|
||||
* @param details
|
||||
*/
|
||||
export default function onHistoryStateUpdated(
|
||||
details: chrome.webNavigation.WebNavigationTransitionCallbackDetails
|
||||
): void {
|
||||
const { tabId, url } = details;
|
||||
// TODO: send a message to tab with tabId to reanalyze the page
|
||||
}
|
||||
26
src/background/events/onInstall.ts
Normal file
26
src/background/events/onInstall.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { SECOND } from 'src/shared/util/time';
|
||||
|
||||
/**
|
||||
* Called when the extension is first installed or synced onto a new machine
|
||||
*/
|
||||
export default async function onInstall() {
|
||||
// set the uninstall url
|
||||
chrome.runtime.setUninstallURL('https://www.google.com');
|
||||
logOnInstallEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* making sure we are not sending duplicate install event for users that have synced browsers
|
||||
* sync storage get's cleared on browser uninstall, so re-installing the browser will trigger the event
|
||||
*/
|
||||
function logOnInstallEvent() {
|
||||
setTimeout(async () => {
|
||||
const manifest = chrome.runtime.getManifest();
|
||||
const INSTALL_KEY = `${manifest.short_name}-installed`;
|
||||
const storage = await chrome.storage.sync.get(INSTALL_KEY);
|
||||
if (!storage[INSTALL_KEY]) {
|
||||
// TODO: send install event
|
||||
await chrome.storage.sync.set({ [INSTALL_KEY]: true });
|
||||
}
|
||||
}, 5 * SECOND);
|
||||
}
|
||||
4
src/background/events/onNewChromeSession.ts
Normal file
4
src/background/events/onNewChromeSession.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* This function is called when the user's browser opens for the first time
|
||||
*/
|
||||
export default function onNewChromeSession() {}
|
||||
9
src/background/events/onServiceWorkerAlive.ts
Normal file
9
src/background/events/onServiceWorkerAlive.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { openDebugTab } from '../util/openDebugTab';
|
||||
|
||||
/**
|
||||
* Called whenever the background service worker comes alive
|
||||
* (usually around 30 seconds to 5 minutes after it was last alive)
|
||||
*/
|
||||
export default function onServiceWorkerAlive() {
|
||||
openDebugTab();
|
||||
}
|
||||
10
src/background/events/onUpdate.ts
Normal file
10
src/background/events/onUpdate.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { hotReloadTab } from 'src/background/util/hotReloadTab';
|
||||
|
||||
/**
|
||||
* Called when the extension is updated (or when the extension is reloaded in development mode)
|
||||
*/
|
||||
export default function onUpdate() {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
hotReloadTab();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user