Skip to content

Eliminate getFavicon duplication in injected script#45

Merged
JOHLC merged 1 commit into2025.11.1from
copilot/sub-pr-37-167bcaaa-3d19-4f92-b4ca-0af9b90c3b60
Nov 18, 2025
Merged

Eliminate getFavicon duplication in injected script#45
JOHLC merged 1 commit into2025.11.1from
copilot/sub-pr-37-167bcaaa-3d19-4f92-b4ca-0af9b90c3b60

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 18, 2025

Description

Removes duplicated getFavicon function code (86 lines) from the injected script by using function serialization.

Type of Change

  • ♻️ Code refactoring (no functional changes)

Changes Made

  • Serialize getFavicon using .toString() and pass as argument to chrome.scripting.executeScript
  • Reconstruct function in page context using eval instead of duplicating implementation
  • Add explanatory comments about the serialization approach and safety considerations

The function is now maintained in one location. Updates to favicon selection logic automatically propagate to the injected script without manual synchronization.

// Before: 86 lines of duplicated getFavicon implementation inline
const results = await chrome.scripting.executeScript({
  target: { tabId: tab.id },
  func: () => {
    function getFavicon() { /* 86 lines duplicated here */ }
    // ...
  }
});

// After: Single source of truth with serialization
const getFaviconStr = getFavicon.toString();
const results = await chrome.scripting.executeScript({
  target: { tabId: tab.id },
  func: (getFaviconCode) => {
    const getFavicon = eval('(' + getFaviconCode + ')');
    // ...
  },
  args: [getFaviconStr]
});

Testing

  • I have tested these changes locally
  • I have tested the extension in Chrome/Edge
  • I have tested the Home Assistant webhook integration (if applicable)
  • I have verified that no XSS or security vulnerabilities are introduced

Screenshots (if applicable)

N/A - Internal refactoring with no UI changes

Checklist

  • My code follows the existing code style
  • I have performed a self-review of my changes
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings or errors
  • I have tested edge cases and error conditions
  • Any dependent changes have been merged and published

Related Issues

Addresses feedback from #37 (comment #37 (comment))

Additional Notes

The eval usage is safe here as we control the source code and execution occurs in the page context, not the extension context. ESLint exception is documented inline.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI mentioned this pull request Nov 18, 2025
Copilot AI changed the title [WIP] Address feedback from PR #37 discussions Eliminate getFavicon duplication in injected script Nov 18, 2025
Copilot AI requested a review from JOHLC November 18, 2025 20:20
@JOHLC JOHLC marked this pull request as ready for review November 18, 2025 20:20
@JOHLC JOHLC merged commit f48cf60 into 2025.11.1 Nov 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants