Skip to content

Commit de58d5f

Browse files
authored
make it work in firefox v120 (#19)
1 parent 50d4e80 commit de58d5f

20 files changed

+194
-109
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ node_modules/
88
# os
99
.DS_Store
1010

11-
# typescript output
12-
.ts-built
13-
14-
# application files not for git
11+
# application autogenerated files not for git
1512
*.js.map
1613
*.zip
14+
manifest.json
15+
bundle/js

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/bundle/js
2-
.ts-built
32
*.min.js
43
pnpm-lock.yaml

Makefile

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
ZIP_FILE="extension.zip"
1+
ZIP_CHROME_FILE="extension.chrome.zip"
2+
ZIP_FIREFOX_FILE="extension.firefox.zip"
23
HASH_ALG="sha384"
34

45
.PHONY:
5-
install clean all lint dev prod zip
6+
install clean all lint dev prod zip_chrome zip_firefox
7+
tune2chrome tune2firefox
68

79
install:
810
npm i -g pnpm
911
pnpm i
1012

1113
clean:
1214
rm -rf ./node_modules
13-
rm -rf $(ZIP_FILE)
15+
rm -rf $(ZIP_CHROME_FILE) $(ZIP_FIREFOX_FILE)
1416
rm -rf ./bundle/js/
1517

1618
all:
1719
make lint
1820
make prod
19-
make zip
21+
make zip_chrome
22+
make zip_firefox
2023

2124
lint:
2225
npx prettier . --write
@@ -27,12 +30,28 @@ dev:
2730
npx webpack --progress --watch --mode=development
2831

2932
prod:
33+
rm -rf ./bundle/js/
3034
NODE_OPTIONS="--loader=ts-node/esm --no-warnings=ExperimentalWarning" \
3135
NODE_ENV="production" \
3236
npx webpack --mode=production
3337

34-
zip:
35-
rm -rf $(ZIP_FILE)
36-
zip -r $(ZIP_FILE) ./bundle ./manifest.json > /dev/null
37-
FILE_HASH=$$(openssl dgst -$(HASH_ALG) -binary $(ZIP_FILE) | openssl base64 -A); \
38-
echo "$(ZIP_FILE) $(HASH_ALG):$$FILE_HASH"
38+
zip_chrome:
39+
make tune2chrome
40+
rm -rf $(ZIP_CHROME_FILE)
41+
zip -r $(ZIP_CHROME_FILE) ./bundle ./manifest.json > /dev/null
42+
zip --delete $(ZIP_CHROME_FILE) "bundle/js/firefox/*"
43+
FILE_HASH=$$(openssl dgst -$(HASH_ALG) -binary $(ZIP_CHROME_FILE) | openssl base64 -A); \
44+
echo "$(ZIP_CHROME_FILE) $(HASH_ALG):$$FILE_HASH"
45+
46+
zip_firefox:
47+
make tune2firefox
48+
rm -rf $(ZIP_FIREFOX_FILE)
49+
zip -r $(ZIP_FIREFOX_FILE) ./bundle ./manifest.json > /dev/null
50+
FILE_HASH=$$(openssl dgst -$(HASH_ALG) -binary $(ZIP_FIREFOX_FILE) | openssl base64 -A); \
51+
echo "$(ZIP_FIREFOX_FILE) $(HASH_ALG):$$FILE_HASH"
52+
53+
tune2chrome:
54+
cp manifest.chrome.json manifest.json
55+
56+
tune2firefox:
57+
cp manifest.firefox.json manifest.json

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ Historically, left side represents the old state and right side the new state.
124124
```sh
125125
make install # to install dependencies
126126
make all # build for prod and make extension.zip
127+
make tune2chrome # or tune2firefox for relevant manifest
127128
make dev # local development
128129
```
129130

bundle/js/jsdiff-console.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

bundle/js/jsdiff-devtools.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

bundle/js/jsdiff-panel.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

bundle/js/jsdiff-proxy.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

manifest.json renamed to manifest.chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "console.diff(...)",
4-
"version": "3.0.4",
4+
"version": "3.0.5",
55
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlCx2Bl0li+3idvfrH9cQL/MzphafGFqMUA2P+0vbyhwxsxWl0llOaGQbkirX5qCoAVHoUCPqu3hCjpVCv35igPbfqDs5bdLZZmXt2F0HjEQnWI/eZKd9IKcKYMplEeL2BodmpU02VrP1UnUzQHZeeMWk9ybgWOqCimkwliILVubRj5dxNB9AidLwO4Z5iGq/OvW9AJMYdxKxrLP2lF6/GGNcCBg+iCJZwlQOhFB9LbUjytT4ws3bIEX4b5zmWLqGKR1NiZfGug2eCWXt9oEKg2WkbXmBBzFKqxnM/bBUrVR29N9qNgx0f42qnyhsW3Bo4kPzE3d0asXCV5nofLTLEwIDAQAB",
66
"description": "Compare objects in memory with console.diff(old, new) devtools function",
77
"minimum_chrome_version": "100.0",

manifest.firefox.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"manifest_version": 3,
3+
"name": "console.diff(...)",
4+
"version": "3.0.5",
5+
"description": "Compare objects in memory with console.diff(old, new) devtools function",
6+
"minimum_chrome_version": "100.0",
7+
"browser_specific_settings": {
8+
"gecko": {
9+
10+
"strict_min_version": "118.0"
11+
}
12+
},
13+
"homepage_url": "https://github.com/zendive/jsdiff",
14+
"author": "[email protected]",
15+
"permissions": ["storage", "devtools", "activeTab"],
16+
"host_permissions": ["<all_urls>"],
17+
"background": {
18+
"scripts": ["bundle/js/firefox/jsdiff-background.js"]
19+
},
20+
"devtools_page": "bundle/jsdiff-devtools.html",
21+
"icons": {
22+
"28": "bundle/img/panel-icon28.png",
23+
"64": "bundle/img/panel-icon64.png",
24+
"128": "bundle/img/panel-icon128.png"
25+
},
26+
"content_scripts": [
27+
{
28+
"js": ["bundle/js/jsdiff-console.js", "bundle/js/jsdiff-proxy.js"],
29+
"matches": ["*://*/*"],
30+
"all_frames": true,
31+
"run_at": "document_start"
32+
}
33+
]
34+
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsdiff",
3-
"version": "3.0.4",
3+
"version": "3.0.5",
44
"description": "Chrome extension to compare objects in memory with console.diff(old, new) devtools function",
55
"private": true,
66
"scripts": {
@@ -25,6 +25,7 @@
2525
"type": "module",
2626
"devDependencies": {
2727
"@types/chrome": "0.0.251",
28+
"@types/firefox-webext-browser": "120.0.0",
2829
"@types/webpack-bundle-analyzer": "4.6.3",
2930
"@vue/compiler-sfc": "3.3.8",
3031
"clean-webpack-plugin": "4.0.0",
@@ -36,8 +37,8 @@
3637
"sass": "1.69.5",
3738
"sass-loader": "13.3.2",
3839
"style-loader": "3.3.3",
39-
"ts-node": "10.9.1",
40-
"typescript": "5.2.2",
40+
"ts-node": "10.9.2",
41+
"typescript": "5.3.3",
4142
"vue": "3.4.3",
4243
"vue-loader": "17.3.1",
4344
"webpack": "5.89.0",

pnpm-lock.yaml

Lines changed: 22 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/@types/index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ declare global {
4646
| IProgressMessage
4747
| IErrorMessage
4848
| ISearchMessage;
49+
50+
interface Window {
51+
wrappedJSObject: { jsdiff: () => void };
52+
}
53+
54+
// firefox extension context
55+
// currently not present in '@types/firefox-webext-browser'
56+
function cloneInto(...args: any[]): any;
4957
}

src/firefox/background-script.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// background script for firefox partial(?) MV3 implementation
2+
3+
let ports = new Set<chrome.runtime.Port>();
4+
5+
// Listen for connections from DevTools pages
6+
chrome.runtime.onConnect.addListener((port) => {
7+
if (port.name === 'jsdiff-devtools-page-connect') {
8+
ports.add(port);
9+
10+
port.onDisconnect.addListener(() => {
11+
ports.delete(port);
12+
});
13+
}
14+
});
15+
16+
// Listen for messages from content scripts
17+
// and forward the message to the DevTools page connected ports
18+
chrome.runtime.onMessage.addListener((msg) => {
19+
for (const port of ports) {
20+
port.postMessage(msg);
21+
}
22+
});

src/jsdiff-console.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { post, nativeClone, customClone } from '@/api/clone';
22

3-
Object.assign(console, {
3+
const consoleAPI = {
44
diff: (...args: unknown[]) => {
55
post(
66
customClone,
@@ -31,6 +31,18 @@ Object.assign(console, {
3131
: { left: args[0], right: args[1], timestamp: Date.now() }
3232
);
3333
},
34-
});
34+
};
3535

36-
console.debug(`✚ console.diff()`);
36+
if (typeof browser === 'undefined') {
37+
// chrome
38+
Object.assign(console, consoleAPI);
39+
console.debug(`✚ console.diff()`);
40+
} else if (typeof cloneInto === 'function') {
41+
// firefox
42+
// the technic described in:
43+
// @link: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts
44+
window.wrappedJSObject.jsdiff = cloneInto(consoleAPI, window, {
45+
cloneFunctions: true,
46+
});
47+
console.debug(`✚ jsdiff.diff()`);
48+
}

src/jsdiff-devtools.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ if (chrome.devtools.inspectedWindow.tabId !== null) {
55
'/bundle/img/panel-icon28.png',
66
'/bundle/jsdiff-panel.html',
77
(panel) => {
8-
panel.onSearch.addListener(async (cmd, query) => {
9-
await chrome.runtime.sendMessage({
10-
source: 'jsdiff-devtools-to-panel-search',
11-
params: { cmd, query },
12-
} as ISearchMessage);
13-
});
8+
if (typeof panel.onSearch?.addListener === 'function') {
9+
panel.onSearch.addListener(async (cmd, query) => {
10+
await chrome.runtime.sendMessage({
11+
source: 'jsdiff-devtools-to-panel-search',
12+
params: { cmd, query },
13+
} as ISearchMessage);
14+
});
15+
}
1416
}
1517
);
1618
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createApp } from 'vue';
22
import Panel from '@/view/panel.vue';
33

4-
const app = createApp(Panel);
5-
app.mount('#jsdiff-app');
4+
createApp(Panel).mount('#jsdiff-app');

0 commit comments

Comments
 (0)