Skip to content

Add Chrome extension with host/toolbar architecture for viewing Interactive Document files#52

Closed
danmarshall with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-2a1a315d-3920-477b-ae2a-6148752c1e85
Closed

Add Chrome extension with host/toolbar architecture for viewing Interactive Document files#52
danmarshall with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-2a1a315d-3920-477b-ae2a-6148752c1e85

Conversation

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown
Contributor
  • Add Chrome extension with host/toolbar architecture for viewing Interactive Document files
  • Implement automatic file detection for .idoc.md and .idoc.json files
  • Use secure sandbox infrastructure for iframe-based rendering
  • Integrate toolbar with "view source" and "download" functionality
  • Follow Chrome Manifest V3 standards
  • Reuse existing UMD bundles for consistency
  • Revert package-lock.json to original state and merge main
  • Regenerate package-lock.json after merging latest changes

The Chrome extension now follows the established host/toolbar architecture and has been properly synchronized with the latest main branch. The package-lock.json has been regenerated to reflect the current dependency state after merging main.


💡 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.

@danmarshall danmarshall changed the title [WIP] Let's create a chrome extension. it should live in the packages folder, just like the vscode extension does. It is unclear to me if it should use the markdown renderer directly or the sandbox. I suspect the latter, for security reasons but I'm not expe... Chrome Extension Aug 22, 2025
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Comment thread packages/chrome-extension/src/content.ts Fixed
…ntation

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Copilot AI changed the title Chrome Extension Add Chrome extension for viewing Interactive Document files Aug 22, 2025
Copilot AI requested a review from danmarshall August 22, 2025 22:01
@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot nice job. Now see that we should use the host/toolbar model that we do in web/frontend and vscode. lets make sure to have all mesasge types in the common project. perhaps you can even resuse some of those instead of creating new ones. the toolbar should enable 'view source', and 'download'

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Comment on lines +234 to +238
errorDiv.innerHTML = `
<h3>Error Loading Viewer</h3>
<p>${error.message}</p>
<button onclick="this.parentElement.remove()">Close</button>
`;

Check warning

Code scanning / CodeQL

Exception text reinterpreted as HTML Medium

Exception text
is reinterpreted as HTML without escaping meta-characters.
Exception text
is reinterpreted as HTML without escaping meta-characters.
Exception text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 11 months ago

To fix this vulnerability, the exception message (error.message) must be HTML-escaped before being inserted into a template string and assigned to innerHTML. This prevents malicious input from being interpreted as markup or script. A simple HTML-escaping function must be added (e.g., converting <, >, &, ", and ' to their respective HTML entities). The fix should be inserted in the same file, with the escaping function defined locally or imported if appropriate (preferably local, as we're restricted to code within the shown file). Replace the direct reference to ${error.message} on line 236 with the escaped version via escapeHtml(error.message).

Required changes:

  • Add a utility function, e.g., escapeHtml(str: string): string near the top of the file.
  • During error display (line 236), replace interpolation of error.message with escapeHtml(error.message).

Suggested changeset 1
packages/chrome-extension/src/content.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/chrome-extension/src/content.ts b/packages/chrome-extension/src/content.ts
--- a/packages/chrome-extension/src/content.ts
+++ b/packages/chrome-extension/src/content.ts
@@ -3,6 +3,16 @@
  * Licensed under the MIT License.
  */
 
+// Utility to escape HTML for safe insertion into innerHTML
+function escapeHtml(str: string): string {
+  return str
+    .replace(/&/g, '&amp;')
+   .replace(/</g, '&lt;')
+   .replace(/>/g, '&gt;')
+   .replace(/"/g, '&quot;')
+   .replace(/'/g, '&#39;');
+}
+
 // Content script that runs on pages with .idoc files
 (function() {
   'use strict';
@@ -233,7 +243,7 @@
       `;
       errorDiv.innerHTML = `
         <h3>Error Loading Viewer</h3>
-        <p>${error.message}</p>
+        <p>${escapeHtml(error.message)}</p>
         <button onclick="this.parentElement.remove()">Close</button>
       `;
       document.body.appendChild(errorDiv);
EOF
@@ -3,6 +3,16 @@
* Licensed under the MIT License.
*/

// Utility to escape HTML for safe insertion into innerHTML
function escapeHtml(str: string): string {
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}

// Content script that runs on pages with .idoc files
(function() {
'use strict';
@@ -233,7 +243,7 @@
`;
errorDiv.innerHTML = `
<h3>Error Loading Viewer</h3>
<p>${error.message}</p>
<p>${escapeHtml(error.message)}</p>
<button onclick="this.parentElement.remove()">Close</button>
`;
document.body.appendChild(errorDiv);
Copilot is powered by AI and may make mistakes. Always verify output.
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown
Contributor Author

@copilot nice job. Now see that we should use the host/toolbar model that we do in web/frontend and vscode. lets make sure to have all mesasge types in the common project. perhaps you can even resuse ...

I've refactored the Chrome extension to use the host/toolbar model as requested. The changes include:

  • Replaced custom overlay with Chartifact.host.Listener and Chartifact.toolbar.Toolbar
  • Reused existing UMD bundles (host, sandbox, compiler) for consistency
  • Configured toolbar with "view source" and "download" buttons (tweakButton and downloadButton)
  • Uses the same architecture patterns as web-frontend and vscode

The toolbar now properly supports viewing source code and downloading files as requested. The implementation follows the established host/toolbar model throughout the codebase.

Commit: 52a0fdd

Copilot AI changed the title Add Chrome extension for viewing Interactive Document files Add Chrome extension with host/toolbar architecture for viewing Interactive Document files Aug 22, 2025
@danmarshall
danmarshall marked this pull request as ready for review September 3, 2025 17:33
@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot can you undo your package-lock, merge main, and then regenerate it?

Copilot AI and others added 3 commits September 3, 2025 17:38
…opilot/fix-2a1a315d-3920-477b-ae2a-6148752c1e85

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Sep 3, 2025

Copy link
Copy Markdown
Contributor Author

@copilot can you undo your package-lock, merge main, and then regenerate it?

Done! I've reverted the package-lock.json changes, merged main, and regenerated the package-lock.json. The changes are now properly synchronized with the latest main branch.

Commit: bd65bd6

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.

3 participants