Ryan Christian D. Deniega commited on
Commit
7ba7fea
Β·
1 Parent(s): 4cb413f

fix(extension): init() no longer exits when service worker returns undefined

Browse files
Files changed (1) hide show
  1. extension/content.js +6 -3
extension/content.js CHANGED
@@ -394,12 +394,15 @@
394
  // ── Initialization ────────────────────────────────────────────────────────
395
 
396
  async function init() {
397
- // Check autoScan setting before activating
 
398
  const response = await new Promise(resolve => {
399
- chrome.runtime.sendMessage({ type: 'GET_SETTINGS' }, resolve)
 
 
400
  }).catch(() => ({ autoScan: true }))
401
 
402
- if (!response?.autoScan) return
403
 
404
  // Process any posts already in the DOM
405
  const existing = findPosts(document.body)
 
394
  // ── Initialization ────────────────────────────────────────────────────────
395
 
396
  async function init() {
397
+ // Check autoScan setting before activating.
398
+ // Default to true if the service worker hasn't responded yet (MV3 cold start).
399
  const response = await new Promise(resolve => {
400
+ chrome.runtime.sendMessage({ type: 'GET_SETTINGS' }, (r) => {
401
+ resolve(r ?? { autoScan: true })
402
+ })
403
  }).catch(() => ({ autoScan: true }))
404
 
405
+ if (response?.autoScan === false) return
406
 
407
  // Process any posts already in the DOM
408
  const existing = findPosts(document.body)