Skip to content

Commit 7188d34

Browse files
authored
v3.0.1 (#12)
support broader set of data types + add customClone + serialize: Symbol, Set, Map, +/-Infinity, NaN, BigInt, undefine + tune function serialization + add pseudo ids for potentionally recurring instances + update documentation features and limitations
1 parent 6c8709a commit 7188d34

40 files changed

+1174
-523
lines changed

.gitignore

+4-55
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,16 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
8-
# Runtime data
9-
pids
10-
*.pid
11-
*.seed
12-
*.pid.lock
13-
14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
16-
17-
# Coverage directory used by tools like istanbul
18-
coverage
19-
20-
# nyc test coverage
21-
.nyc_output
22-
23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
29-
# node-waf configuration
30-
.lock-wscript
31-
32-
# Compiled binary addons (http://nodejs.org/api/addons.html)
33-
build/Release
341

352
# Dependency directories
363
node_modules/
37-
jspm_packages/
38-
39-
# Typescript v1 declaration files
40-
typings/
41-
42-
# Optional npm cache directory
43-
.npm
44-
45-
# Optional eslint cache
46-
.eslintcache
47-
48-
# Optional REPL history
49-
.node_repl_history
50-
51-
# Output of 'npm pack'
52-
*.tgz
53-
54-
# dotenv environment variables file
55-
.env
564

575
# ide
586
.idea
597

608
# os
619
.DS_Store
6210

63-
*.zip
64-
*.js.map
65-
6611
# typescript output
6712
.ts-built
13+
14+
# application files not for git
15+
*.js.map
16+
*.zip

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/src/js/bundle
1+
/bundle/js
22
.ts-built
33
*.min.js

.prettierrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
25
"singleQuote": true
36
}

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode"]
3+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"json.schemaDownload.enable": true
3+
}

README.md

+78-26
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
[![console.diff()](https://storage.googleapis.com/web-dev-uploads/image/WlD8wC6g8khYWPJUsQceQkhXSlv1/tbyBjqi7Zu733AAKA5n4.png)](https://chrome.google.com/webstore/detail/jsdiff-devtool/iefeamoljhdcpigpnpggeiiabpnpgonb)
44

5-
Chrome devtools extension intended to display result of deep in-memory object
6-
comparisons with the help of dedicated console commands.
5+
Chrome extension to compare objects in memory with console.diff(old, new) devtools function.
76

87
<details>
98
<summary> <strong>Screenshots</strong> </summary>
@@ -23,23 +22,54 @@ comparisons with the help of dedicated console commands.
2322

2423
### Features
2524

26-
- compare objects between multiple [sub]domains, chrome tabs, or single page reloads
27-
- function code included in comparison result in form of a string, may help to see if it was altered
28-
- document, dom-elements and other non-serializable objects are filtered-out from the results
29-
- self recurring references displayed only once, the rest of occurrences are filtered-out
30-
- basic integration with search functionality within devtools
31-
- if search query contains upper-case letter - the search will be case-sensitive
25+
- Symple user interface:
3226

33-
### Limitations and workarounds
27+
- Button to hide/show unchanged properties.
28+
- Button to copy changed properties in format of `jsondiffpatch` diff object.
29+
- Button to clear current result.
30+
- Indicator of the last update time.
31+
- Indicator of a fatal error (out of storage memory).
3432

35-
- some instances of objects may cause exception during preparations for comparison
36-
- try to narrow compared contexts
37-
- if it's some Browser API that causes an exception and not a framework, consider opening an issue,
38-
so it will be possible to solve it on a permanent basis
39-
- while paused in debug mode, JSDiff panel won't reflect the result until runtime is resumed ([#10][i10])
33+
- Compare objects between multiple [sub]domains, chrome tabs, or single page reloads.
34+
35+
- JSDiff devtools panel reflects current state of comparison, regardless the tab[s] it was opened from.
36+
37+
- Basic integration with search functionality within devtools:
38+
39+
- If search query contains at least one upper-case letter - the search will be case-sensitive.
40+
41+
- Using `console.diff` functions from within online code editors like: [codesandbox.io](https://codesandbox.io), [coderpad.io](https://coderpad.io), [flems.io](https://flems.io), [codepen.io](https://codepen.io), [jsfiddle.net](https://jsfiddle.net).
42+
43+
- Functions are included in comparison result in order to detect possible alterations, in form of a string combined from a function name (if present) and a SHA-256 hash of a `function.toString()` body. Native functions are shown as silmply as `ƒ⟪native⟫`.
44+
45+
- Some DOM objects like Document or Element are not worth to be shown entirely, since that is not the purpose of this extension. So if they are present anywhere, they are serialized as `0x####: ⟪unserializable⟫`.
46+
47+
- Object, Array, Map, Set - serialized only once and the rest of their ocurrances are mentioned with unique reference like: `0x####: {♻️}`, `0x####: [♻️]`, `0x####: Map{♻️}`, `0x####: Set[♻️]` respectivly.
48+
49+
- Map keys, unless they are primitive types, serialized by their pseudo ids.
50+
51+
- Symbols serialized with his pseudo id like: `0x####: Symbol(name)`.
52+
53+
- Serialization of numerics like `+/-Infinity`, `NaN`, `BigInt`, or `undefined` serialized like: `Number⟪Infinity⟫`, `Number⟪NaN⟫`, `BigInt⟪#⟫`, `⟪undefined⟫` respectivly.
54+
55+
- Failsafe serialization of objects having security issues while accessing their properties.
56+
57+
- Failsefe serialization of objects having `toJSON()` function (when instead of serialization of all object properties, - only toJSON() return value is serialized, similar to the way native `JSON.strigify()` works).
58+
59+
### Legend
60+
61+
- Pseudo id, assigned to non-primitive data types, used in order to detect reference recurrences and, in case of Symbols - symbol uniqueness. Id for an object shown in the output only if it seen more than once. It being assigned in the scope of serialization of a high level argument instance, while comparing left or right side; that means if some object, having id 0x0001 on the left side, is not guarantied to have same id on the right side.
62+
63+
### Limitations
64+
65+
- While paused in debug mode, JSDiff panel won't reflect the result until runtime is resumed (see [#10][i10]).
4066

4167
[i10]: https://github.com/zendive/jsdiff/issues/10
4268

69+
- Compared objects, after being serialized, and stored in `chrome.storage.local` wich has 10MB limit.
70+
71+
- Will not work on `file:///` prorocol and https://chrome.google.com/webstore site.
72+
4373
### API
4474

4575
- **console.diff(left, right)** - compare left and right arguments
@@ -72,25 +102,47 @@ console.diffLeft(Date.now());
72102
console.diffRight(Date.now());
73103
```
74104

105+
- **console.diff\_(\*)** - deprecated, left for backward compatibility, uses `nativeClone` based of JSON.parse(JSON.stringify(...)) serialization method
106+
75107
### Usage basics
76108

77109
Historically, left side represents the old state and right side the new state.
78110

79111
- Things that are present on the left side but missing on the right side are colour-coded as red (old).
112+
80113
- Things that are missing on the left side but present on the right side are colour-coded as green (new).
81114

82-
To track changes of the same variable in timed manner you can push it with `diffPush` or `diff`
83-
with a single argument, that will shift objects from right to left, showing differences with previous push state.
115+
- To track changes of the same variable in timed manner you can push it with `diffPush` or `diff` with a single argument, - that will shift objects from right to left, showing differences with previous push state.
84116

85117
### How it works
86118

87-
- `jsdiff-devtools.js` registers devtools panel
88-
- injects `console.diff` commands into inspected window's console interface
89-
- each function clones arguments and sends them via `postMessage` to `jsdiff-proxy.js` in `jsdiff-console-to-proxy` message
90-
- injects `jsdiff-proxy.js` that listens on window `jsdiff-console-to-proxy` message and sends it further to chrome runtime in `jsdiff-proxy-to-devtools` message
91-
- listens on `jsdiff-proxy-to-devtools` and prepares payload for `view/panel.vue` and sends it with `jsdiff-devtools-to-panel-compare` message
92-
- when user invokes devtools search command - informs `view/panel.vue` with `jsdiff-devtools-to-panel-search` message
93-
- when `view/panel.vue` is visible in devtools
94-
- reflects result of last compare request
95-
- listens on `jsdiff-devtools-to-panel-compare` requests
96-
- listens on `jsdiff-devtools-to-panel-search` and tries to find query in DOM
119+
- `manifest.json` injects content scripts to each visited site (except for chrome web store site and google-protected alike):
120+
- `jsdiff-console.ts` as [MAIN](https://developer.chrome.com/docs/extensions/reference/scripting/#type-ExecutionWorld) world (has access to the target site memory)
121+
- sends messages to `jsdiff-proxy.ts`.
122+
- `jsdiff-proxy.ts` as `ISOLATED` world (has access to the chrome runtime)
123+
- stores data from `jsdiff-console.ts` in `chrome.storage.local` and sends runtime messages to `panel.vue`.
124+
- `jsdiff-devtools.ts` registers `panel.vue` as a JSDiff devtools panel that reads current state of `chorme.storage.local` and listens to incomming `chrome.runtime` mesages from `jsdiff-proxy.ts`.
125+
126+
### How to build
127+
128+
- requires npm/nodejs
129+
- requires pnpm `npm i -g pnpm`
130+
131+
```sh
132+
pnpm i
133+
pnpm dev # local development
134+
pnpm zip # make extension.zip
135+
```
136+
137+
### Protection
138+
139+
- How to protect your site from this extension:
140+
- Well, tests show that even `Content-Security-Policy: default-src 'none';` header won't prevent injection of extension content-scripts...
141+
- In general, you can incapacitate console functions:
142+
```js
143+
for (const prop in console) {
144+
if (typeof console[prop] === 'function' && prop !== 'error') {
145+
console[prop] = function noop() {};
146+
}
147+
}
148+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.

bundle/js/jsdiff-console.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/js/jsdiff-devtools.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/js/jsdiff-panel.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/js/jsdiff-proxy.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<meta charset="UTF-8" />
5-
<script src="/src/js/jsdiff-devtools.js"></script>
5+
<script src="./js/jsdiff-devtools.js"></script>
66
</head>
77
<body></body>
88
</html>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<meta charset="UTF-8" />
55
</head>
66
<body>
77
<div id="jsdiff-app"></div>
8-
<script src="/src/js/bundle/jsdiff-panel.js"></script>
8+
<script src="./js/jsdiff-panel.js"></script>
99
</body>
1010
</html>

manifest.json

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
{
22
"name": "console.diff(...)",
3-
"description": "Compare in-memory objects and see the result inside devtools panel with a set of console.diff functions.",
4-
"version": "3.0.0",
3+
"description": "Compare objects in memory with console.diff(old, new) devtools function",
4+
"version": "3.0.1",
55
"manifest_version": 3,
6-
"minimum_chrome_version": "88.0",
7-
"devtools_page": "src/jsdiff-devtools.html",
6+
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlCx2Bl0li+3idvfrH9cQL/MzphafGFqMUA2P+0vbyhwxsxWl0llOaGQbkirX5qCoAVHoUCPqu3hCjpVCv35igPbfqDs5bdLZZmXt2F0HjEQnWI/eZKd9IKcKYMplEeL2BodmpU02VrP1UnUzQHZeeMWk9ybgWOqCimkwliILVubRj5dxNB9AidLwO4Z5iGq/OvW9AJMYdxKxrLP2lF6/GGNcCBg+iCJZwlQOhFB9LbUjytT4ws3bIEX4b5zmWLqGKR1NiZfGug2eCWXt9oEKg2WkbXmBBzFKqxnM/bBUrVR29N9qNgx0f42qnyhsW3Bo4kPzE3d0asXCV5nofLTLEwIDAQAB",
7+
"minimum_chrome_version": "100.0",
8+
"devtools_page": "bundle/jsdiff-devtools.html",
9+
"content_scripts": [
10+
{
11+
"world": "MAIN",
12+
"js": ["/bundle/js/jsdiff-console.js"],
13+
"matches": ["<all_urls>"],
14+
"match_origin_as_fallback": true,
15+
"all_frames": true,
16+
"run_at": "document_start"
17+
},
18+
{
19+
"js": ["/bundle/js/jsdiff-proxy.js"],
20+
"matches": ["<all_urls>"],
21+
"match_origin_as_fallback": true,
22+
"all_frames": true,
23+
"run_at": "document_start"
24+
}
25+
],
826
"icons": {
9-
"28": "src/img/panel-icon28.png",
10-
"64": "src/img/panel-icon64.png",
11-
"128": "src/img/panel-icon128.png"
27+
"28": "bundle/img/panel-icon28.png",
28+
"64": "bundle/img/panel-icon64.png",
29+
"128": "bundle/img/panel-icon128.png"
1230
},
13-
"permissions": ["storage", "scripting", "clipboardWrite"],
31+
"permissions": ["storage"],
1432
"host_permissions": ["*://*/*"]
1533
}

0 commit comments

Comments
 (0)