Skip to content

Commit 450d33f

Browse files
committed
fix message passing in anonymoius frames and file:///*.htm[l]?
1 parent bb9546c commit 450d33f

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

src/api/clone.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TAG } from '@/api/const';
2-
import { SHA256 } from './toolkit';
2+
import { SHA256 } from '@/api/toolkit';
33

44
type TInstanceBadgeTag = (id: string) => string;
55
type TSymbolBadgeTag = (symbolName: string, symbolId: string) => string;
@@ -63,7 +63,7 @@ export async function post(
6363
try {
6464
window.postMessage(
6565
{ source: 'jsdiff-console-to-proxy-inprogress', on: true },
66-
window.location.origin
66+
'*'
6767
);
6868

6969
for (const key of ['push', 'left', 'right']) {
@@ -82,14 +82,14 @@ export async function post(
8282

8383
window.postMessage(
8484
{ source: 'jsdiff-console-to-proxy-compare', payload },
85-
window.location.origin
85+
'*'
8686
);
8787
} catch (error) {
8888
console.error('console.diff()', error);
8989

9090
window.postMessage(
9191
{ source: 'jsdiff-console-to-proxy-inprogress', on: false },
92-
window.location.origin
92+
'*'
9393
);
9494
}
9595
}

src/api/proxy.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ export function proxyMessageGate(
55
callbackCompare: (e: MessageEvent<ICompareMessage>) => Promise<void>
66
) {
77
return function (e: MessageEvent) {
8-
if (
9-
e.origin === window.location.origin &&
10-
e.source === window &&
11-
typeof e.data === 'object' &&
12-
e.data !== null
13-
) {
8+
if (e.source === window && typeof e.data === 'object' && e.data !== null) {
149
if ('jsdiff-console-to-proxy-inprogress' === e.data.source) {
1510
callbackInprogress(e);
1611
} else if ('jsdiff-console-to-proxy-compare' === e.data.source) {
@@ -94,7 +89,7 @@ function processComparisonObject(
9489
return rv;
9590
}
9691

97-
function handleResponse(error: chrome.runtime.LastError | undefined): void {
92+
function handleResponse(): void {
9893
if (!isIgnorable(chrome.runtime.lastError)) {
9994
console.error(chrome.runtime.lastError);
10095
}

src/api/toolkit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function hasValue(o: unknown): boolean {
44

55
export async function SHA256(data: string): Promise<string> {
66
const textAsBuffer = new TextEncoder().encode(data);
7-
const hashBuffer = await window.crypto.subtle.digest('SHA-256', textAsBuffer);
7+
const hashBuffer = await crypto.subtle.digest('SHA-256', textAsBuffer);
88
const hashArray = Array.from(new Uint8Array(hashBuffer));
99
const digest = hashArray
1010
.map((b) => b.toString(16).padStart(2, '0').toUpperCase())

src/jsdiff-console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Object.assign(console, {
3333
},
3434
});
3535

36-
console.debug('✚ console.diff()');
36+
console.debug(`✚ console.diff()`);

0 commit comments

Comments
 (0)