-
Notifications
You must be signed in to change notification settings - Fork 77
fix: prevent popup crash by ensuring DOM is loaded before accessing elements #81
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
base: master
Are you sure you want to change the base?
Changes from all commits
997ece4
683024a
ce4d1fc
c947196
2faa5da
2fdf479
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /* ExtensionShield β popup (self-contained, no service worker needed) */ | ||
| (function () { | ||
| 'use strict'; | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
|
|
||
| var API = 'https://extensionshield.com'; | ||
| var CACHE_TTL = 6 * 3600 * 1000; | ||
|
|
@@ -181,13 +182,15 @@ | |
| } | ||
|
|
||
| var extId = extractExtensionIdFromInput(raw); | ||
| if (!extId) { | ||
| setScanUrlMessage('Enter a Chrome Web Store URL.', 'error'); | ||
| return; | ||
| } | ||
|
|
||
| if (!extId) { | ||
| setScanUrlMessage('Please enter a valid Chrome Web Store URL or Extension ID.', 'error'); | ||
| return; | ||
| } | ||
| setScanUrlMessage('Scanningβ¦', ''); | ||
| setScanSearchLoading(true); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = true; | ||
| } | ||
| if (scanResultsContent) scanResultsContent.hidden = true; | ||
|
|
||
| renderScanResult({ | ||
|
|
@@ -205,6 +208,9 @@ | |
| renderScanResult(result); | ||
| setScanUrlMessage('', ''); | ||
| setScanSearchLoading(false); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = false; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -214,6 +220,9 @@ | |
| if (triggerResult.status === 'error') { | ||
| setScanUrlMessage('Could not start scan. Try on the website.', 'error'); | ||
| setScanSearchLoading(false); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = false; | ||
| } | ||
| return; | ||
| } | ||
| if (triggerResult.status === 'completed' || triggerResult.already_scanned) { | ||
|
|
@@ -222,11 +231,17 @@ | |
| renderScanResult(result); | ||
| setScanUrlMessage('', ''); | ||
| setScanSearchLoading(false); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = false; | ||
| } | ||
| }); | ||
| } | ||
| setScanUrlMessage('Scan in progressβ¦', ''); | ||
| return waitForScan(extId).then(function (p2) { | ||
| setScanSearchLoading(false); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = false; | ||
| } | ||
| if (p2._st === 'timeout') { | ||
| setScanUrlMessage('Scan is taking longer. Check again soon.', 'error'); | ||
| renderScanResult({ | ||
|
|
@@ -249,9 +264,15 @@ | |
|
|
||
| setScanUrlMessage('Could not fetch results.', 'error'); | ||
| setScanSearchLoading(false); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = false; | ||
| } | ||
| }).catch(function () { | ||
| setScanUrlMessage('Network error. Check your connection.', 'error'); | ||
| setScanSearchLoading(false); | ||
| if (scanUrlSubmit) { | ||
| scanUrlSubmit.disabled = false; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -303,11 +324,16 @@ | |
| return new Promise(function (resolve) { setTimeout(resolve, ms); }); | ||
| } | ||
|
|
||
| function esc(s) { | ||
| function esc(s) { | ||
| if (s === null || s === undefined) return ''; | ||
| try { | ||
| var d = document.createElement('div'); | ||
| d.textContent = s; | ||
| d.textContent = String(s); | ||
| return d.innerHTML; | ||
| } catch (e) { | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| function getIconUrl(ext) { | ||
| var icons = ext && ext.icons; | ||
|
|
@@ -647,44 +673,37 @@ | |
| } | ||
| } | ||
|
|
||
| function scan(force) { | ||
| chrome.permissions.contains({ permissions: ["management"] }, function(hasPerm) { | ||
| if (!hasPerm) { | ||
| showError("Management permission required. Click Extensions tab to grant."); | ||
| render([]); | ||
| function scan(force) { | ||
| showStatus('Getting extensionsβ¦'); | ||
|
|
||
| try { | ||
| chrome.management.getAll(function (all) { | ||
| if (chrome.runtime.lastError || !all) { | ||
| hideStatus(); | ||
| showError('Cannot access extensions'); | ||
| return; | ||
| } | ||
|
|
||
| showStatus('Getting extensionsβ¦'); | ||
| var selfId = chrome.runtime.id; | ||
| var exts = []; | ||
|
|
||
| chrome.runtime.sendMessage({ action: 'getAllExtensions' }, function (all) { | ||
| if (chrome.runtime.lastError || !all) { | ||
| chrome.management.getAll(function (fallbackAll) { | ||
| if (chrome.runtime.lastError) { | ||
| hideStatus(); | ||
| showError('Cannot access extensions: ' + (chrome.runtime.lastError.message || 'unknown')); | ||
| return; | ||
| } | ||
| var selfId = chrome.runtime.id; | ||
| var filtered = []; | ||
| for (var j = 0; j < fallbackAll.length; j++) { | ||
| if (!fallbackAll[j].permissions) fallbackAll[j].permissions = []; | ||
| if (fallbackAll[j].type === 'extension' && fallbackAll[j].id !== selfId && fallbackAll[j].enabled) filtered.push(fallbackAll[j]); | ||
| } | ||
| runScanWithExtensions(filtered, force); | ||
| }); | ||
| return; | ||
| for (var i = 0; i < all.length; i++) { | ||
| if ( | ||
| all[i].type === 'extension' && | ||
| all[i].id !== selfId && | ||
| all[i].enabled | ||
| ) { | ||
| exts.push(all[i]); | ||
| } | ||
| } | ||
|
|
||
| var exts = []; | ||
| for (var i = 0; i < all.length; i++) { | ||
| if (!all[i].permissions) all[i].permissions = []; | ||
| if (all[i].enabled) exts.push(all[i]); | ||
| } | ||
| runScanWithExtensions(exts, force); | ||
| }); | ||
| runScanWithExtensions(exts, force); | ||
| }); | ||
| } catch (e) { | ||
| hideStatus(); | ||
| showError('Unexpected error while scanning'); | ||
| } | ||
| } | ||
|
Comment on lines
+676
to
+706
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π§© Analysis chainπ Script executed: #!/bin/bash
set -e
echo "== manifest permission model =="
sed -n '1,40p' packages/extension/src/manifest.json
echo
echo "== popup startup + management API usage =="
rg -n -C3 'scan\(false\)|chrome\.management\.getAll|chrome\.permissions\.(contains|request)' \
packages/extension/src/popup.js \
packages/extension/src/background.jsRepository: Stanzin7/ExtensionShield Length of output: 3415 π Script executed: sed -n '65,80p' packages/extension/src/popup.jsRepository: Stanzin7/ExtensionShield Length of output: 573 Gate the initial scan on the optional
π€ Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Khushi5623 Please have a check on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| function runScanWithExtensions(exts, force) { | ||
| if (!exts || exts.length === 0) { | ||
|
|
@@ -769,6 +788,7 @@ | |
| nextExt(); | ||
| } | ||
|
|
||
| initTheme(); | ||
| scan(false); | ||
| initTheme(); | ||
| scan(false); | ||
| }); | ||
| })(); | ||
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.
Guard
handleScanUrlSubmit()itself against re-entry.Disabling the button only blocks pointer clicks. The Enter-key handler still calls
handleScanUrlSubmit()directly at Lines 315-318, so users can start overlapping scans while the first one is still in flight. Add an early return at the top of the handler (or a dedicatedisScanningflag) so every entry path shares the same lock.Suggested fix
function handleScanUrlSubmit() { + if (scanUrlSubmit && scanUrlSubmit.disabled) return; var raw = scanUrlInput && scanUrlInput.value ? scanUrlInput.value.trim() : '';π€ Prompt for AI Agents