Skip to content

Commit f52c484

Browse files
committed
Our extension loads!
1 parent f6ca1dc commit f52c484

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

browser-extension/tests/har-view.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,42 @@ app.get('/page/:filename/gitcasso', async (req, res) => {
173173
`/asset/${filename.replace('.har', '')}`
174174
)
175175

176-
// Inject the Gitcasso content script at the end of the body
176+
// Inject patched content script that bypasses webextension-polyfill
177177
const contentScriptTag = `
178178
<script>
179-
// Load the Gitcasso content script from the dev server
180-
const script = document.createElement('script');
181-
script.src = 'http://localhost:3000/content-scripts/content.js';
182-
script.onload = () => console.log('Gitcasso content script loaded successfully');
183-
script.onerror = () => console.error('Failed to load Gitcasso content script - is the dev server running?');
184-
document.body.appendChild(script);
179+
// Fetch and patch the content script to remove webextension-polyfill issues
180+
fetch('http://localhost:3000/.output/chrome-mv3-dev/content-scripts/content.js')
181+
.then(response => response.text())
182+
.then(code => {
183+
console.log('Fetched content script, patching webextension-polyfill...');
184+
185+
// Replace the problematic webextension-polyfill error check
186+
const patchedCode = code.replace(
187+
/throw new Error\\("This script should only be loaded in a browser extension\\."/g,
188+
'console.warn("Webextension-polyfill check bypassed for HAR testing"'
189+
);
190+
191+
// Mock necessary APIs before executing
192+
window.chrome = window.chrome || {
193+
runtime: {
194+
getURL: (path) => 'chrome-extension://gitcasso-test/' + path,
195+
onMessage: { addListener: () => {} },
196+
sendMessage: () => Promise.resolve(),
197+
id: 'gitcasso-test'
198+
}
199+
};
200+
window.browser = window.chrome;
201+
202+
// Execute the patched script
203+
const script = document.createElement('script');
204+
script.textContent = patchedCode;
205+
document.head.appendChild(script);
206+
207+
console.log('Gitcasso content script loaded and patched for HAR testing');
208+
})
209+
.catch(error => {
210+
console.error('Failed to load and patch content script:', error);
211+
});
185212
</script>
186213
`
187214

0 commit comments

Comments
 (0)