Skip to content

Commit c859f14

Browse files
committed
Fixed up!
1 parent 87b4f8e commit c859f14

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

browser-extension/src/entrypoints/content.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { EnhancerRegistry, TextareaRegistry } from '../lib/registries'
66
const enhancers = new EnhancerRegistry()
77
const enhancedTextareas = new TextareaRegistry()
88

9-
// Expose for debugging in har:view
10-
;(window as any).gitcassoTextareaRegistry = enhancedTextareas
9+
// Expose for debugging in har:view
10+
; (window as any).gitcassoTextareaRegistry = enhancedTextareas
1111

1212
function sendEventToBackground(type: 'ENHANCED' | 'DESTROYED', spot: CommentSpot): void {
1313
const message: CommentEvent = {
@@ -88,16 +88,20 @@ function enhanceMaybe(textarea: HTMLTextAreaElement) {
8888
logger.debug('activating textarea {}', textarea)
8989
injectStyles()
9090

91-
const enhancedTextarea = enhancers.tryToEnhance(textarea)
92-
if (enhancedTextarea) {
93-
logger.debug(
94-
'Identified textarea:',
95-
enhancedTextarea.spot.type,
96-
enhancedTextarea.spot.unique_key,
97-
)
98-
enhancedTextareas.register(enhancedTextarea)
99-
} else {
100-
logger.debug('No handler found for textarea')
91+
try {
92+
const enhancedTextarea = enhancers.tryToEnhance(textarea)
93+
if (enhancedTextarea) {
94+
logger.debug(
95+
'Identified textarea:',
96+
enhancedTextarea.spot.type,
97+
enhancedTextarea.spot.unique_key,
98+
)
99+
enhancedTextareas.register(enhancedTextarea)
100+
} else {
101+
logger.debug('No handler found for textarea')
102+
}
103+
} catch (e) {
104+
logger.error(e)
101105
}
102106
}
103107

browser-extension/tests/har-view.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,20 +337,10 @@ function injectGitcassoScript(key: keyof typeof PAGES, html: string) {
337337
'console.warn("Webextension-polyfill check bypassed for HAR testing")'
338338
);
339339
340-
// Mock necessary APIs before executing
341-
window.chrome = window.chrome || {
342-
runtime: {
343-
getURL: (path) => 'chrome-extension://gitcasso-test/' + path,
344-
onMessage: { addListener: () => {} },
345-
sendMessage: () => Promise.resolve(),
346-
id: 'gitcasso-test'
347-
}
348-
};
349-
window.browser = window.chrome;
350-
351-
// Execute the patched script
340+
// Execute the patched script with browser API mocks prepended
341+
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;';
352342
const script = document.createElement('script');
353-
script.textContent = patchedCode;
343+
script.textContent = browserMocks + patchedCode;
354344
document.head.appendChild(script);
355345
console.log('Gitcasso content script loaded with location patching for:', '` + urlParts.href + `');
356346
})

0 commit comments

Comments
 (0)