-
-
Notifications
You must be signed in to change notification settings - Fork 0
FEAT: Identify and resolved major performance issues + Build enhanced performance system and landing site #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RianaAzad
wants to merge
9
commits into
master
Choose a base branch
from
chore/performance
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b7c7bbe
CHORE: identified and resolved major performance issues
RianaAzad f23be8c
FIX: Memory leaks, timer conflicts, tabId validation and naming consi…
FardinHash 6ba70da
FEAT: Added performance monitoring and testing system
FardinHash ed0b1be
Init: website setup
RianaAzad 470b607
FEAT: Designed and developed landing page with features, browser-avai…
RianaAzad 2ed944b
CHORE: implemented complete SEO optimization with og-tags, logo, JSON…
FardinHash 593faa8
CHORE: implemented complete SEO optimization with og-tags, logo, JSON…
FardinHash 368abae
Merge pull request #8 from intellwe/feat/website
RianaAzad a7af754
DOCS: Completed Extension store optimizations
FardinHash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| // Safe-Web Background Service Worker | ||
| // Safe-Web Background Service Worker - Optimized | ||
| // Handles extension lifecycle, storage, and communication with content scripts | ||
|
|
||
| class SafeWebBackground { | ||
| constructor() { | ||
| this.tabUpdateThrottle = new Map(); | ||
| this.initializeExtension(); | ||
| this.setupEventListeners(); | ||
| } | ||
|
|
@@ -48,7 +49,7 @@ class SafeWebBackground { | |
| chrome.runtime.onMessage.addListener(this.handleMessage.bind(this)); | ||
|
|
||
| // Tab update handling | ||
| chrome.tabs.onUpdated.addListener(this.handleTabUpdate.bind(this)); | ||
| chrome.tabs.onUpdated.addListener(this.throttledTabUpdate.bind(this)); | ||
|
|
||
| // Storage change handling | ||
| chrome.storage.onChanged.addListener(this.handleStorageChange.bind(this)); | ||
|
|
@@ -85,17 +86,17 @@ class SafeWebBackground { | |
| break; | ||
|
|
||
| case "TOGGLE_MASKING": | ||
| await this.toggleMasking(sender.tab.id); | ||
| await this.toggleMasking(sender.tab?.id); | ||
| sendResponse({ success: true }); | ||
| break; | ||
|
|
||
| case "GET_TAB_STATE": | ||
| const tabState = await this.getTabState(sender.tab.id); | ||
| const tabState = await this.getTabState(sender.tab?.id); | ||
| sendResponse({ success: true, data: tabState }); | ||
| break; | ||
|
|
||
| case "UPDATE_TAB_STATE": | ||
| await this.updateTabState(sender.tab.id, data); | ||
| await this.updateTabState(sender.tab?.id, data); | ||
| sendResponse({ success: true }); | ||
| break; | ||
|
|
||
|
|
@@ -117,6 +118,20 @@ class SafeWebBackground { | |
| return true; | ||
| } | ||
|
|
||
| throttledTabUpdate(tabId, changeInfo, tab) { | ||
| if (this.tabUpdateThrottle.has(tabId)) { | ||
| clearTimeout(this.tabUpdateThrottle.get(tabId)); | ||
| } | ||
|
|
||
| this.tabUpdateThrottle.set( | ||
| tabId, | ||
| setTimeout(() => { | ||
| this.handleTabUpdate(tabId, changeInfo, tab); | ||
| this.tabUpdateThrottle.delete(tabId); | ||
| }, 100) | ||
| ); | ||
| } | ||
|
|
||
| async handleTabUpdate(tabId, changeInfo, tab) { | ||
| if (changeInfo.status === "complete" && tab.url) { | ||
| // Inject content script if needed | ||
|
|
@@ -153,12 +168,12 @@ class SafeWebBackground { | |
| async getSettings() { | ||
| try { | ||
| const result = await chrome.storage.sync.get("safeWebSettings"); | ||
|
|
||
| // Return default settings if none exist | ||
| if (!result.safeWebSettings) { | ||
| const defaultSettings = { | ||
| maskingEnabled: false, | ||
| maskingStyle: 'blur', | ||
| maskingStyle: "blur", | ||
| maskingIntensity: 5, | ||
| sensitivePatterns: { | ||
| email: true, | ||
|
|
@@ -167,20 +182,20 @@ class SafeWebBackground { | |
| creditCard: true, | ||
| names: false, | ||
| addresses: false, | ||
| customPatterns: [] | ||
| customPatterns: [], | ||
| }, | ||
| shortcuts: { | ||
| toggleMasking: 'Ctrl+Shift+M' | ||
| toggleMasking: "Ctrl+Shift+M", | ||
| }, | ||
| theme: 'dark', | ||
| animations: true | ||
| theme: "dark", | ||
| animations: true, | ||
| }; | ||
|
|
||
| // Initialize with default settings | ||
| await chrome.storage.sync.set({ safeWebSettings: defaultSettings }); | ||
| return defaultSettings; | ||
| } | ||
|
|
||
| return result.safeWebSettings; | ||
| } catch (error) { | ||
| console.error("Safe-Web: Failed to get settings:", error); | ||
|
|
@@ -200,6 +215,8 @@ class SafeWebBackground { | |
| } | ||
|
|
||
| async toggleMasking(tabId) { | ||
| if (!tabId) return; | ||
|
|
||
| const settings = await this.getSettings(); | ||
| const newState = !settings.maskingEnabled; | ||
|
|
||
|
|
@@ -217,16 +234,29 @@ class SafeWebBackground { | |
| } | ||
|
|
||
| async getTabState(tabId) { | ||
| const result = await chrome.storage.local.get(`tab_${tabId}`); | ||
| return ( | ||
| result[`tab_${tabId}`] || { maskingActive: false, detectedElements: [] } | ||
| ); | ||
| if (!tabId) return { maskingActive: false, detectedElements: [] }; | ||
|
|
||
| try { | ||
| const result = await chrome.storage.local.get(`tab_${tabId}`); | ||
| return ( | ||
| result[`tab_${tabId}`] || { maskingActive: false, detectedElements: [] } | ||
| ); | ||
| } catch (error) { | ||
| console.error("Safe-Web: Failed to get tab state:", error); | ||
| return { maskingActive: false, detectedElements: [] }; | ||
| } | ||
| } | ||
|
|
||
| async updateTabState(tabId, state) { | ||
| const currentState = await this.getTabState(tabId); | ||
| const newState = { ...currentState, ...state }; | ||
| await chrome.storage.local.set({ [`tab_${tabId}`]: newState }); | ||
| if (!tabId) return; | ||
|
|
||
| try { | ||
| const currentState = await this.getTabState(tabId); | ||
| const newState = { ...currentState, ...state }; | ||
| await chrome.storage.local.set({ [`tab_${tabId}`]: newState }); | ||
| } catch (error) { | ||
| console.error("Safe-Web: Failed to update tab state:", error); | ||
| } | ||
| } | ||
|
|
||
| async ensureContentScript(tabId, url) { | ||
|
|
@@ -250,6 +280,8 @@ class SafeWebBackground { | |
| target: { tabId }, | ||
| files: ["content.css"], | ||
| }); | ||
|
|
||
| console.log("Safe-Web: Content script injected into tab", tabId); | ||
| } catch (injectionError) { | ||
| console.error( | ||
| "Safe-Web: Failed to inject content script:", | ||
|
|
@@ -262,32 +294,42 @@ class SafeWebBackground { | |
| async analyzeContent(content) { | ||
| // Basic content analysis for sensitive information | ||
| const patterns = { | ||
| email: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g, | ||
| phone: /(\+1\s?)?(\([0-9]{3}\)|[0-9]{3})[\s\-]?[0-9]{3}[\s\-]?[0-9]{4}/g, | ||
| ssn: /\b\d{3}-?\d{2}-?\d{4}\b/g, | ||
| creditCard: /\b\d{4}[\s\-]?\d{4}[\s\-]?\d{4}[\s\-]?\d{4}\b/g, | ||
| emails: ( | ||
|
||
| content.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [] | ||
| ).length, | ||
| phones: ( | ||
| content.match( | ||
| /(\+1\s?)?(\([0-9]{3}\)|[0-9]{3})[\s\-]?[0-9]{3}[\s\-]?[0-9]{4}/g | ||
| ) || [] | ||
| ).length, | ||
| ssns: (content.match(/\b\d{3}-?\d{2}-?\d{4}\b/g) || []).length, | ||
| creditCards: ( | ||
| content.match(/\b\d{4}[\s\-]?\d{4}[\s\-]?\d{4}[\s\-]?\d{4}\b/g) || [] | ||
| ).length, | ||
| }; | ||
|
|
||
| const detected = {}; | ||
|
|
||
| for (const [type, pattern] of Object.entries(patterns)) { | ||
| const matches = content.match(pattern); | ||
| if (matches) { | ||
| detected[type] = matches.length; | ||
| } | ||
| } | ||
|
|
||
| return detected; | ||
| return { | ||
| totalMatches: Object.values(patterns).reduce( | ||
| (sum, count) => sum + count, | ||
| 0 | ||
| ), | ||
| breakdown: patterns, | ||
| timestamp: Date.now(), | ||
| }; | ||
| } | ||
|
|
||
| async showWelcome() { | ||
| await chrome.tabs.create({ | ||
| url: chrome.runtime.getURL("welcome.html"), | ||
| }); | ||
| try { | ||
| await chrome.tabs.create({ | ||
| url: chrome.runtime.getURL("welcome.html"), | ||
| }); | ||
| } catch (error) { | ||
| console.error("Safe-Web: Failed to show welcome page:", error); | ||
| } | ||
| } | ||
|
|
||
| async handleUpdate(previousVersion) { | ||
| console.log(`Safe-Web updated from ${previousVersion}`); | ||
| console.log(`Safe-Web updated from version ${previousVersion}`); | ||
| // Handle any migration logic here | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
tabIdis undefined, you end up storing and clearing a key ofundefinedin the throttle map. Add an early return guard whentabIdis falsy to avoid unintended behavior.