Skip to content

Commit

Permalink
Fixes #26 - OpenBlur works in all tabs on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed Jul 11, 2024
1 parent e08a184 commit e121a27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Binary file added assets/images/blurry_1024x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/blurry_440x280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,51 @@ import { Message, Mode, MODES } from "./constants"
const cssToInject = "body { visibility: hidden; }"

let currentModeIndex = 1
let startupDone = false

console.debug("OpenBlur service worker script loaded")

function startUp() {
if (startupDone) {
return
}
startupDone = true
chrome.storage.sync.get("mode", (data) => {
if (data.mode && typeof data.mode === "object") {
currentModeIndex = (data.mode as Mode).index
}
void chrome.action.setIcon({ path: MODES[currentModeIndex].icon })
})
// Inject script into all tabs.
chrome.tabs
.query({})
.then((tabs) => {
for (const tab of tabs) {
if (tab.id !== undefined) {
const target: chrome.scripting.InjectionTarget = {
tabId: tab.id,
allFrames: true,
}
chrome.scripting
.executeScript({
target: target,
files: ["content.js"],
})
.catch((error: unknown) => {
console.info("OpenBlur could not inject content script into tab %d", tab.id, error)
})
}
}
})
.catch((error: unknown) => {
console.error("OpenBlur service worker could not query tabs at startup", error)
})
}

// Ensure the background script always runs.
chrome.runtime.onStartup.addListener(startUp)
chrome.runtime.onInstalled.addListener(startUp)
startUp()

// Hide the body content until OpenBlur processes the content and blurs the secrets.
chrome.webNavigation.onCommitted.addListener(function (details) {
Expand Down

0 comments on commit e121a27

Please sign in to comment.