Skip to content

Commit 6d5d0a9

Browse files
committed
Modify har-view to match.
1 parent 46f64e8 commit 6d5d0a9

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

browser-extension/tests/har-view.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,31 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
315315
const contentScriptTag =
316316
`
317317
<script>
318-
// Patch window.location before loading content script
319-
console.log('Patching window.location to simulate original URL...');
320-
321-
// Use history.pushState to change the pathname
322-
window.history.pushState({}, '', '${urlParts.pathname}');
323-
324-
console.log('Location patched:', {
325-
hostname: window.location.hostname,
326-
pathname: window.location.pathname,
327-
href: window.location.href,
328-
host: window.location.host
329-
});
330-
318+
console.log('Loading Gitcasso with mocked location:', '${urlParts.href}');
319+
331320
// Fetch and patch the content script to remove webextension-polyfill issues
332321
fetch('/chrome-mv3-dev/content-scripts/content.js')
333322
.then(response => response.text())
334323
.then(code => {
335-
console.log('Fetched content script, patching webextension-polyfill...');
336-
324+
console.log('Fetched content script, patching webextension-polyfill and detectLocation...');
325+
337326
// Replace the problematic webextension-polyfill error check
338-
const patchedCode = code.replace(
327+
let patchedCode = code.replace(
339328
'throw new Error("This script should only be loaded in a browser extension.")',
340329
'console.warn("Webextension-polyfill check bypassed for HAR testing")'
341330
);
342331
332+
// Override detectLocation function with correct domain and pathname
333+
patchedCode = patchedCode.replace(
334+
/function detectLocation(): StrippedLocation {[sS]*?}/,
335+
'function detectLocation() {\\n' +
336+
' return {\\n' +
337+
' domain: \\'${urlParts.host}\\',\\n' +
338+
' pathname: \\'${urlParts.pathname}\\'\\n' +
339+
' };\\n' +
340+
'}'
341+
);
342+
343343
// Execute the patched script with browser API mocks prepended
344344
const browserMocks = 'window.chrome=window.chrome||{runtime:{getURL:path=>"chrome-extension://gitcasso-test/"+path,onMessage:{addListener:()=>{}},sendMessage:()=>Promise.resolve(),id:"gitcasso-test"}};window.browser=window.chrome;';
345345
const script = document.createElement('script');
@@ -505,8 +505,9 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
505505
506506
const content = enhanced.length > 0
507507
? '<div style="' + styles.header + '">CommentSpots (' + enhanced.length + '):</div>' +
508+
'<div style="font-size: 10px; color: #666; margin-bottom: 8px; word-break: break-all;">URL: ${urlParts.href}</div>' +
508509
enhanced.map(formatSpot).join('')
509-
: '<div style="' + styles.empty + '">No CommentSpots detected yet...<br><small>Textareas found: ' + document.querySelectorAll('textarea').length + '</small></div>';
510+
: '<div style="' + styles.empty + '">No CommentSpots detected yet...<br><small>Textareas found: ' + document.querySelectorAll('textarea').length + '</small><br><small>URL: ${urlParts.href}</small></div>';
510511
511512
commentSpotDisplay.innerHTML = content;
512513
}

0 commit comments

Comments
 (0)