@browserless.io/browserless 2.0.0-beta-5 → 2.0.0-beta-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -0
- package/README.md +11 -11
- package/bin/browserless.js +169 -11
- package/bin/scaffold/README.md +415 -0
- package/bin/scaffold/package.json +21 -0
- package/bin/scaffold/src/hello-world.http.ts +27 -0
- package/bin/scaffold/tsconfig.json +4 -0
- package/build/browserless.js +18 -15
- package/build/browsers/index.d.ts +2 -18
- package/build/browsers/index.js +43 -14
- package/build/file-system.d.ts +5 -0
- package/build/file-system.js +20 -5
- package/build/file-system.spec.d.ts +1 -0
- package/build/file-system.spec.js +44 -0
- package/build/http.d.ts +3 -3
- package/build/http.js +3 -3
- package/build/router.js +2 -4
- package/build/routes/chromium/http/content-post.body.json +8 -8
- package/build/routes/chromium/http/content-post.d.ts +15 -3
- package/build/routes/chromium/http/content-post.js +14 -15
- package/build/routes/chromium/http/download-post.d.ts +16 -3
- package/build/routes/chromium/http/download-post.js +17 -22
- package/build/routes/chromium/http/function-post.d.ts +16 -3
- package/build/routes/chromium/http/function-post.js +17 -22
- package/build/routes/chromium/http/pdf-post.body.json +8 -8
- package/build/routes/chromium/http/pdf-post.d.ts +15 -3
- package/build/routes/chromium/http/pdf-post.js +19 -15
- package/build/routes/chromium/http/performance.d.ts +15 -3
- package/build/routes/chromium/http/performance.js +15 -23
- package/build/routes/chromium/http/scrape-post.body.json +8 -8
- package/build/routes/chromium/http/scrape-post.d.ts +15 -3
- package/build/routes/chromium/http/scrape-post.js +15 -16
- package/build/routes/chromium/http/screenshot-post.body.json +8 -8
- package/build/routes/chromium/http/screenshot-post.d.ts +15 -3
- package/build/routes/chromium/http/screenshot-post.js +18 -15
- package/build/routes/chromium/tests/websocket.spec.js +20 -1
- package/build/routes/chromium/utils/function/handler.js +2 -2
- package/build/routes/chromium/ws/browser.d.ts +13 -3
- package/build/routes/chromium/ws/browser.js +10 -11
- package/build/routes/chromium/ws/cdp-chromium.d.ts +13 -3
- package/build/routes/chromium/ws/cdp-chromium.js +10 -11
- package/build/routes/chromium/ws/page.d.ts +13 -3
- package/build/routes/chromium/ws/page.js +10 -11
- package/build/routes/chromium/ws/playwright-chromium.d.ts +13 -3
- package/build/routes/chromium/ws/playwright-chromium.js +11 -12
- package/build/routes/firefox/ws/playwright-firefox.d.ts +13 -3
- package/build/routes/firefox/ws/playwright-firefox.js +11 -12
- package/build/routes/management/http/config-get.d.ts +15 -3
- package/build/routes/management/http/config-get.js +15 -20
- package/build/routes/management/http/metrics-get.d.ts +15 -3
- package/build/routes/management/http/metrics-get.js +16 -21
- package/build/routes/management/http/metrics-total-get.d.ts +15 -3
- package/build/routes/management/http/metrics-total-get.js +16 -21
- package/build/routes/management/http/sessions-get.d.ts +15 -3
- package/build/routes/management/http/sessions-get.js +16 -20
- package/build/routes/management/http/static-get.d.ts +15 -3
- package/build/routes/management/http/static-get.js +15 -20
- package/build/routes/webkit/ws/playwright-webkit.d.ts +13 -3
- package/build/routes/webkit/ws/playwright-webkit.js +11 -12
- package/build/server.js +0 -1
- package/build/types.d.ts +48 -38
- package/build/types.js +135 -0
- package/extensions/ublock/1p-filters.html +0 -1
- package/extensions/ublock/3p-filters.html +0 -2
- package/extensions/ublock/_locales/bg/messages.json +6 -6
- package/extensions/ublock/_locales/br_FR/messages.json +14 -14
- package/extensions/ublock/_locales/bs/messages.json +8 -8
- package/extensions/ublock/_locales/ca/messages.json +1 -1
- package/extensions/ublock/_locales/da/messages.json +5 -5
- package/extensions/ublock/_locales/fa/messages.json +1 -1
- package/extensions/ublock/_locales/fi/messages.json +6 -6
- package/extensions/ublock/_locales/hr/messages.json +4 -4
- package/extensions/ublock/_locales/nb/messages.json +1 -1
- package/extensions/ublock/_locales/no/messages.json +1 -1
- package/extensions/ublock/_locales/ro/messages.json +2 -2
- package/extensions/ublock/_locales/ru/messages.json +1 -1
- package/extensions/ublock/_locales/sk/messages.json +1 -1
- package/extensions/ublock/_locales/sv/messages.json +2 -2
- package/extensions/ublock/_locales/te/messages.json +17 -17
- package/extensions/ublock/_locales/vi/messages.json +12 -12
- package/extensions/ublock/_locales/zh_TW/messages.json +13 -13
- package/extensions/ublock/assets/assets.json +3 -3
- package/extensions/ublock/assets/resources/scriptlets.js +218 -97
- package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +3010 -2056
- package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +624 -433
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +93 -24
- package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +7 -15
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +795 -777
- package/extensions/ublock/assets/ublock/badware.min.txt +138 -72
- package/extensions/ublock/assets/ublock/filters.min.txt +1929 -2735
- package/extensions/ublock/assets/ublock/privacy.min.txt +57 -26
- package/extensions/ublock/assets/ublock/quick-fixes.min.txt +125 -74
- package/extensions/ublock/assets/ublock/unbreak.min.txt +46 -53
- package/extensions/ublock/css/codemirror.css +8 -7
- package/extensions/ublock/css/dom-inspector.css +40 -0
- package/extensions/ublock/css/logger-ui-inspector.css +7 -1
- package/extensions/ublock/css/logger-ui.css +12 -5
- package/extensions/ublock/css/popup-fenix.css +1 -1
- package/extensions/ublock/devtools.html +1 -0
- package/extensions/ublock/js/1p-filters.js +4 -3
- package/extensions/ublock/js/3p-filters.js +25 -31
- package/extensions/ublock/js/about.js +1 -1
- package/extensions/ublock/js/advanced-settings.js +1 -1
- package/extensions/ublock/js/asset-viewer.js +1 -1
- package/extensions/ublock/js/assets.js +74 -44
- package/extensions/ublock/js/background.js +9 -3
- package/extensions/ublock/js/base64-custom.js +1 -1
- package/extensions/ublock/js/benchmarks.js +1 -1
- package/extensions/ublock/js/biditrie.js +1 -1
- package/extensions/ublock/js/broadcast.js +75 -0
- package/extensions/ublock/js/cachestorage.js +68 -45
- package/extensions/ublock/js/click2load.js +1 -1
- package/extensions/ublock/js/cloud-ui.js +1 -1
- package/extensions/ublock/js/code-viewer.js +1 -1
- package/extensions/ublock/js/codemirror/search-thread.js +1 -1
- package/extensions/ublock/js/codemirror/search.js +1 -1
- package/extensions/ublock/js/codemirror/ubo-dynamic-filtering.js +1 -1
- package/extensions/ublock/js/codemirror/ubo-static-filtering.js +98 -24
- package/extensions/ublock/js/commands.js +1 -1
- package/extensions/ublock/js/console.js +1 -1
- package/extensions/ublock/js/contentscript-extra.js +1 -1
- package/extensions/ublock/js/contentscript.js +1 -3
- package/extensions/ublock/js/contextmenu.js +1 -1
- package/extensions/ublock/js/cosmetic-filtering.js +4 -4
- package/extensions/ublock/js/dashboard-common.js +1 -1
- package/extensions/ublock/js/dashboard.js +1 -1
- package/extensions/ublock/js/devtools.js +23 -15
- package/extensions/ublock/js/diff-updater.js +3 -3
- package/extensions/ublock/js/document-blocked.js +1 -1
- package/extensions/ublock/js/dom-inspector.js +68 -0
- package/extensions/ublock/js/dom.js +1 -1
- package/extensions/ublock/js/dyna-rules.js +1 -1
- package/extensions/ublock/js/dynamic-net-filtering.js +1 -1
- package/extensions/ublock/js/epicker-ui.js +35 -59
- package/extensions/ublock/js/fa-icons.js +1 -1
- package/extensions/ublock/js/filtering-context.js +1 -1
- package/extensions/ublock/js/filtering-engines.js +1 -1
- package/extensions/ublock/js/hnswitches.js +1 -1
- package/extensions/ublock/js/hntrie.js +1 -1
- package/extensions/ublock/js/html-filtering.js +1 -1
- package/extensions/ublock/js/httpheader-filtering.js +1 -1
- package/extensions/ublock/js/i18n.js +1 -1
- package/extensions/ublock/js/is-webrtc-supported.js +1 -1
- package/extensions/ublock/js/logger-ui-inspector.js +203 -145
- package/extensions/ublock/js/logger-ui.js +21 -5
- package/extensions/ublock/js/logger.js +6 -2
- package/extensions/ublock/js/lz4.js +2 -2
- package/extensions/ublock/js/messaging.js +266 -166
- package/extensions/ublock/js/mrucache.js +58 -0
- package/extensions/ublock/js/pagestore.js +1 -1
- package/extensions/ublock/js/popup-fenix.js +2 -1
- package/extensions/ublock/js/redirect-engine.js +1 -1
- package/extensions/ublock/js/redirect-resources.js +1 -12
- package/extensions/ublock/js/reverselookup-worker.js +1 -1
- package/extensions/ublock/js/reverselookup.js +1 -1
- package/extensions/ublock/js/scriptlet-filtering-core.js +300 -0
- package/extensions/ublock/js/scriptlet-filtering.js +122 -350
- package/extensions/ublock/js/scriptlets/cosmetic-logger.js +36 -47
- package/extensions/ublock/js/scriptlets/cosmetic-off.js +1 -1
- package/extensions/ublock/js/scriptlets/cosmetic-on.js +1 -1
- package/extensions/ublock/js/scriptlets/cosmetic-report.js +1 -1
- package/extensions/ublock/js/scriptlets/dom-inspector.js +341 -323
- package/extensions/ublock/js/scriptlets/dom-survey-elements.js +1 -1
- package/extensions/ublock/js/scriptlets/dom-survey-scripts.js +1 -1
- package/extensions/ublock/js/scriptlets/epicker.js +80 -89
- package/extensions/ublock/js/scriptlets/load-3p-css.js +1 -1
- package/extensions/ublock/js/scriptlets/load-large-media-all.js +1 -1
- package/extensions/ublock/js/scriptlets/load-large-media-interactive.js +1 -1
- package/extensions/ublock/js/scriptlets/noscript-spoof.js +1 -1
- package/extensions/ublock/js/scriptlets/should-inject-contentscript.js +1 -1
- package/extensions/ublock/js/scriptlets/subscriber.js +1 -1
- package/extensions/ublock/js/scriptlets/updater.js +20 -3
- package/extensions/ublock/js/settings.js +1 -1
- package/extensions/ublock/js/start.js +19 -20
- package/extensions/ublock/js/static-dnr-filtering.js +1 -1
- package/extensions/ublock/js/static-ext-filtering-db.js +1 -1
- package/extensions/ublock/js/static-ext-filtering.js +1 -1
- package/extensions/ublock/js/static-filtering-io.js +1 -1
- package/extensions/ublock/js/static-filtering-parser.js +5 -3
- package/extensions/ublock/js/static-net-filtering.js +57 -37
- package/extensions/ublock/js/storage.js +49 -29
- package/extensions/ublock/js/support.js +4 -4
- package/extensions/ublock/js/tab.js +1 -1
- package/extensions/ublock/js/tasks.js +1 -1
- package/extensions/ublock/js/text-encode.js +1 -1
- package/extensions/ublock/js/text-utils.js +1 -1
- package/extensions/ublock/js/theme.js +1 -1
- package/extensions/ublock/js/traffic.js +2 -1
- package/extensions/ublock/js/ublock.js +15 -11
- package/extensions/ublock/js/uri-utils.js +1 -1
- package/extensions/ublock/js/url-net-filtering.js +1 -1
- package/extensions/ublock/js/utils.js +1 -73
- package/extensions/ublock/js/vapi-background-ext.js +1 -1
- package/extensions/ublock/js/vapi-background.js +92 -83
- package/extensions/ublock/js/vapi-client.js +4 -33
- package/extensions/ublock/js/vapi-common.js +16 -30
- package/extensions/ublock/js/vapi.js +1 -1
- package/extensions/ublock/js/wasm/biditrie.wat +1 -1
- package/extensions/ublock/js/wasm/hntrie.wat +1 -1
- package/extensions/ublock/js/webext.js +1 -1
- package/extensions/ublock/js/whitelist.js +1 -1
- package/extensions/ublock/logger-ui.html +2 -2
- package/extensions/ublock/manifest.json +1 -1
- package/extensions/ublock/support.html +0 -1
- package/extensions/ublock/web_accessible_resources/dom-inspector.html +25 -0
- package/extensions/ublock/web_accessible_resources/epicker-ui.html +0 -1
- package/extensions/ublock/web_accessible_resources/googletagservices_gpt.js +1 -0
- package/package.json +7 -19
- package/scripts/build-open-api.js +7 -4
- package/src/browserless.ts +42 -18
- package/src/browsers/index.ts +48 -20
- package/src/file-system.spec.ts +58 -0
- package/src/file-system.ts +36 -8
- package/src/http.ts +3 -3
- package/src/router.ts +2 -6
- package/src/routes/chromium/http/content-post.ts +13 -16
- package/src/routes/chromium/http/download-post.ts +16 -27
- package/src/routes/chromium/http/function-post.ts +16 -25
- package/src/routes/chromium/http/pdf-post.ts +19 -15
- package/src/routes/chromium/http/performance.ts +14 -26
- package/src/routes/chromium/http/scrape-post.ts +14 -16
- package/src/routes/chromium/http/screenshot-post.ts +18 -15
- package/src/routes/chromium/tests/websocket.spec.ts +28 -1
- package/src/routes/chromium/utils/function/handler.ts +2 -1
- package/src/routes/chromium/ws/browser.ts +10 -12
- package/src/routes/chromium/ws/cdp-chromium.ts +10 -12
- package/src/routes/chromium/ws/page.ts +10 -12
- package/src/routes/chromium/ws/playwright-chromium.ts +10 -12
- package/src/routes/firefox/ws/playwright-firefox.ts +10 -12
- package/src/routes/management/http/config-get.ts +14 -23
- package/src/routes/management/http/metrics-get.ts +15 -24
- package/src/routes/management/http/metrics-total-get.ts +15 -26
- package/src/routes/management/http/sessions-get.ts +15 -23
- package/src/routes/management/http/static-get.ts +14 -22
- package/src/routes/webkit/ws/playwright-webkit.ts +10 -12
- package/src/server.ts +0 -1
- package/src/types.ts +59 -45
- package/static/docs/browserless-logo-inline.svg +1 -0
- package/static/docs/index.html +27 -0
- package/static/docs/swagger.json +33 -33
- package/static/function/client.js +626 -78
- package/extensions/ublock/js/vapi-client-extra.js +0 -312
- package/extensions/ublock/web_accessible_resources/addthis_widget.js +0 -39
- package/extensions/ublock/web_accessible_resources/ligatus_angular-tag.js +0 -29
- package/extensions/ublock/web_accessible_resources/monkeybroker.js +0 -43
- package/extensions/ublock/web_accessible_resources/mxpnl_mixpanel.js +0 -51
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*******************************************************************************
|
|
2
2
|
|
|
3
|
-
uBlock Origin - a
|
|
3
|
+
uBlock Origin - a comprehensive, efficient content blocker
|
|
4
4
|
Copyright (C) 2015-present Raymond Hill
|
|
5
5
|
|
|
6
6
|
This program is free software: you can redistribute it and/or modify
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
Home: https://github.com/gorhill/uBlock
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
/* globals browser */
|
|
23
|
+
|
|
22
24
|
'use strict';
|
|
23
25
|
|
|
24
26
|
import { dom, qs$, qsa$ } from './dom.js';
|
|
@@ -29,79 +31,122 @@ import { dom, qs$, qsa$ } from './dom.js';
|
|
|
29
31
|
|
|
30
32
|
/******************************************************************************/
|
|
31
33
|
|
|
34
|
+
const logger = self.logger;
|
|
32
35
|
const showdomButton = qs$('#showdom');
|
|
36
|
+
const inspector = qs$('#domInspector');
|
|
37
|
+
const domTree = qs$('#domTree');
|
|
38
|
+
const filterToIdMap = new Map();
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
typeof WeakMap === 'undefined'
|
|
39
|
-
) {
|
|
40
|
-
dom.cl.add(showdomButton, 'disabled');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
40
|
+
let inspectedTabId = 0;
|
|
41
|
+
let inspectedURL = '';
|
|
42
|
+
let inspectedHostname = '';
|
|
43
|
+
let uidGenerator = 1;
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
/*******************************************************************************
|
|
46
|
+
*
|
|
47
|
+
* How it works:
|
|
48
|
+
*
|
|
49
|
+
* 1. The logger/inspector is enabled from the logger window
|
|
50
|
+
*
|
|
51
|
+
* 2. The inspector content script is injected in the root frame of the tab
|
|
52
|
+
* currently selected in the logger
|
|
53
|
+
*
|
|
54
|
+
* 3. The inspector content script asks the logger/inspector to establish
|
|
55
|
+
* a two-way communication channel
|
|
56
|
+
*
|
|
57
|
+
* 3. The inspector content script embed an inspector frame in the document
|
|
58
|
+
* being inspected and waits for the inspector frame to be fully loaded
|
|
59
|
+
*
|
|
60
|
+
* 4. The inspector content script sends a messaging port object to the
|
|
61
|
+
* embedded inspector frame for a two-way communication channel between
|
|
62
|
+
* the inspector frame and the inspector content script
|
|
63
|
+
*
|
|
64
|
+
* 5. The inspector content script sends dom information to the
|
|
65
|
+
* logger/inspector
|
|
66
|
+
*
|
|
67
|
+
* */
|
|
68
|
+
|
|
69
|
+
const contentInspectorChannel = (( ) => {
|
|
70
|
+
let bcChannel;
|
|
71
|
+
let toContentPort;
|
|
72
|
+
|
|
73
|
+
const start = ( ) => {
|
|
74
|
+
bcChannel = new globalThis.BroadcastChannel('contentInspectorChannel');
|
|
75
|
+
bcChannel.onmessage = ev => {
|
|
76
|
+
const msg = ev.data || {};
|
|
77
|
+
connect(msg.tabId, msg.frameId);
|
|
78
|
+
};
|
|
79
|
+
browser.webNavigation.onDOMContentLoaded.addListener(onContentLoaded);
|
|
80
|
+
};
|
|
45
81
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var uidGenerator = 1;
|
|
54
|
-
var filterToIdMap = new Map();
|
|
82
|
+
const shutdown = ( ) => {
|
|
83
|
+
browser.webNavigation.onDOMContentLoaded.removeListener(onContentLoaded);
|
|
84
|
+
disconnect();
|
|
85
|
+
bcChannel.close();
|
|
86
|
+
bcChannel.onmessage = null;
|
|
87
|
+
bcChannel = undefined;
|
|
88
|
+
};
|
|
55
89
|
|
|
56
|
-
|
|
90
|
+
const connect = (tabId, frameId) => {
|
|
91
|
+
disconnect();
|
|
92
|
+
try {
|
|
93
|
+
toContentPort = browser.tabs.connect(tabId, { frameId });
|
|
94
|
+
toContentPort.onMessage.addListener(onContentMessage);
|
|
95
|
+
toContentPort.onDisconnect.addListener(onContentDisconnect);
|
|
96
|
+
} catch(_) {
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const disconnect = ( ) => {
|
|
101
|
+
if ( toContentPort === undefined ) { return; }
|
|
102
|
+
toContentPort.onMessage.removeListener(onContentMessage);
|
|
103
|
+
toContentPort.onDisconnect.removeListener(onContentDisconnect);
|
|
104
|
+
toContentPort.disconnect();
|
|
105
|
+
toContentPort = undefined;
|
|
106
|
+
};
|
|
57
107
|
|
|
58
|
-
const
|
|
108
|
+
const send = msg => {
|
|
109
|
+
if ( toContentPort === undefined ) { return; }
|
|
110
|
+
toContentPort.postMessage(msg);
|
|
111
|
+
};
|
|
59
112
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
inspectorConnectionId = undefined;
|
|
113
|
+
const onContentMessage = msg => {
|
|
114
|
+
if ( msg.what === 'domLayoutFull' ) {
|
|
115
|
+
inspectedURL = msg.url;
|
|
116
|
+
inspectedHostname = msg.hostname;
|
|
117
|
+
renderDOMFull(msg);
|
|
118
|
+
} else if ( msg.what === 'domLayoutIncremental' ) {
|
|
119
|
+
renderDOMIncremental(msg);
|
|
68
120
|
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const onContentDisconnect = ( ) => {
|
|
124
|
+
disconnect();
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const onContentLoaded = details => {
|
|
128
|
+
if ( details.tabId !== inspectedTabId ) { return; }
|
|
129
|
+
if ( details.frameId !== 0 ) { return; }
|
|
130
|
+
disconnect();
|
|
69
131
|
injectInspector();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
inspectedHostname = msg.payload.hostname;
|
|
75
|
-
renderDOMFull(msg.payload);
|
|
76
|
-
} else if ( msg.payload.what === 'domLayoutIncremental' ) {
|
|
77
|
-
renderDOMIncremental(msg.payload);
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
case 'connectionRequested':
|
|
81
|
-
if ( msg.tabId === undefined || msg.tabId !== inspectedTabId ) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
filterToIdMap.clear();
|
|
85
|
-
logger.removeAllChildren(domTree);
|
|
86
|
-
inspectorConnectionId = msg.id;
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return { start, disconnect, send, shutdown };
|
|
135
|
+
})();
|
|
90
136
|
|
|
91
137
|
/******************************************************************************/
|
|
92
138
|
|
|
93
|
-
const nodeFromDomEntry =
|
|
94
|
-
var node, value;
|
|
139
|
+
const nodeFromDomEntry = entry => {
|
|
95
140
|
const li = document.createElement('li');
|
|
96
141
|
dom.attr(li, 'id', entry.nid);
|
|
97
142
|
// expander/collapser
|
|
98
143
|
li.appendChild(document.createElement('span'));
|
|
99
144
|
// selector
|
|
100
|
-
node = document.createElement('code');
|
|
145
|
+
let node = document.createElement('code');
|
|
101
146
|
node.textContent = entry.sel;
|
|
102
147
|
li.appendChild(node);
|
|
103
148
|
// descendant count
|
|
104
|
-
value = entry.cnt || 0;
|
|
149
|
+
let value = entry.cnt || 0;
|
|
105
150
|
node = document.createElement('span');
|
|
106
151
|
node.textContent = value !== 0 ? value.toLocaleString() : '';
|
|
107
152
|
dom.attr(node, 'data-cnt', value);
|
|
@@ -114,7 +159,7 @@ const nodeFromDomEntry = function(entry) {
|
|
|
114
159
|
dom.cl.add(node, 'filter');
|
|
115
160
|
value = filterToIdMap.get(entry.filter);
|
|
116
161
|
if ( value === undefined ) {
|
|
117
|
-
value = uidGenerator
|
|
162
|
+
value = `${uidGenerator}`;
|
|
118
163
|
filterToIdMap.set(entry.filter, value);
|
|
119
164
|
uidGenerator += 1;
|
|
120
165
|
}
|
|
@@ -127,7 +172,7 @@ const nodeFromDomEntry = function(entry) {
|
|
|
127
172
|
|
|
128
173
|
/******************************************************************************/
|
|
129
174
|
|
|
130
|
-
const appendListItem =
|
|
175
|
+
const appendListItem = (ul, li) => {
|
|
131
176
|
ul.appendChild(li);
|
|
132
177
|
// Ancestor nodes of a node which is affected by a cosmetic filter will
|
|
133
178
|
// be marked as "containing cosmetic filters", for user convenience.
|
|
@@ -141,19 +186,16 @@ const appendListItem = function(ul, li) {
|
|
|
141
186
|
|
|
142
187
|
/******************************************************************************/
|
|
143
188
|
|
|
144
|
-
const renderDOMFull =
|
|
145
|
-
|
|
146
|
-
|
|
189
|
+
const renderDOMFull = response => {
|
|
190
|
+
const domTreeParent = domTree.parentElement;
|
|
191
|
+
let ul = domTreeParent.removeChild(domTree);
|
|
147
192
|
logger.removeAllChildren(domTree);
|
|
148
193
|
|
|
149
194
|
filterToIdMap.clear();
|
|
150
195
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var li, entry;
|
|
155
|
-
for ( var i = 0; i < n; i++ ) {
|
|
156
|
-
entry = entries[i];
|
|
196
|
+
let lvl = 0;
|
|
197
|
+
let li;
|
|
198
|
+
for ( const entry of response.layout ) {
|
|
157
199
|
if ( entry.lvl === lvl ) {
|
|
158
200
|
li = nodeFromDomEntry(entry);
|
|
159
201
|
appendListItem(ul, li);
|
|
@@ -186,24 +228,21 @@ const renderDOMFull = function(response) {
|
|
|
186
228
|
domTreeParent.appendChild(domTree);
|
|
187
229
|
};
|
|
188
230
|
|
|
189
|
-
// https://www.youtube.com/watch?v=IDGNA83mxDo
|
|
190
|
-
|
|
191
231
|
/******************************************************************************/
|
|
192
232
|
|
|
193
|
-
const patchIncremental =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
dom.cl.has(li, 'hasCosmeticHide') === false;
|
|
233
|
+
const patchIncremental = (from, delta) => {
|
|
234
|
+
let li = from.parentElement.parentElement;
|
|
235
|
+
const patchCosmeticHide = delta >= 0 &&
|
|
236
|
+
dom.cl.has(from, 'isCosmeticHide') &&
|
|
237
|
+
dom.cl.has(li, 'hasCosmeticHide') === false;
|
|
199
238
|
// Include descendants count when removing a node
|
|
200
239
|
if ( delta < 0 ) {
|
|
201
240
|
delta -= countFromNode(from);
|
|
202
241
|
}
|
|
203
242
|
for ( ; li.localName === 'li'; li = li.parentElement.parentElement ) {
|
|
204
|
-
span = li.children[2];
|
|
243
|
+
const span = li.children[2];
|
|
205
244
|
if ( delta !== 0 ) {
|
|
206
|
-
cnt = countFromNode(li) + delta;
|
|
245
|
+
const cnt = countFromNode(li) + delta;
|
|
207
246
|
span.textContent = cnt !== 0 ? cnt.toLocaleString() : '';
|
|
208
247
|
dom.attr(span, 'data-cnt', cnt);
|
|
209
248
|
}
|
|
@@ -215,15 +254,14 @@ const patchIncremental = function(from, delta) {
|
|
|
215
254
|
|
|
216
255
|
/******************************************************************************/
|
|
217
256
|
|
|
218
|
-
const renderDOMIncremental =
|
|
257
|
+
const renderDOMIncremental = response => {
|
|
219
258
|
// Process each journal entry:
|
|
220
259
|
// 1 = node added
|
|
221
260
|
// -1 = node removed
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
for (
|
|
226
|
-
entry = journal[i];
|
|
261
|
+
const nodes = new Map(response.nodes);
|
|
262
|
+
let li = null;
|
|
263
|
+
let ul = null;
|
|
264
|
+
for ( const entry of response.journal ) {
|
|
227
265
|
// Remove node
|
|
228
266
|
if ( entry.what === -1 ) {
|
|
229
267
|
li = qs$(`#${entry.nid}`);
|
|
@@ -239,7 +277,7 @@ const renderDOMIncremental = function(response) {
|
|
|
239
277
|
}
|
|
240
278
|
// Add node as sibling
|
|
241
279
|
if ( entry.what === 1 && entry.l ) {
|
|
242
|
-
previous = qs$(`#${entry.l}`);
|
|
280
|
+
const previous = qs$(`#${entry.l}`);
|
|
243
281
|
// This should not happen
|
|
244
282
|
if ( previous === null ) {
|
|
245
283
|
// throw new Error('No left sibling!?');
|
|
@@ -275,25 +313,22 @@ const renderDOMIncremental = function(response) {
|
|
|
275
313
|
|
|
276
314
|
/******************************************************************************/
|
|
277
315
|
|
|
278
|
-
const countFromNode =
|
|
279
|
-
|
|
280
|
-
|
|
316
|
+
const countFromNode = li => {
|
|
317
|
+
const span = li.children[2];
|
|
318
|
+
const cnt = parseInt(dom.attr(span, 'data-cnt'), 10);
|
|
281
319
|
return isNaN(cnt) ? 0 : cnt;
|
|
282
320
|
};
|
|
283
321
|
|
|
284
322
|
/******************************************************************************/
|
|
285
323
|
|
|
286
|
-
const selectorFromNode =
|
|
287
|
-
|
|
288
|
-
var code;
|
|
324
|
+
const selectorFromNode = node => {
|
|
325
|
+
let selector = '';
|
|
289
326
|
while ( node !== null ) {
|
|
290
327
|
if ( node.localName === 'li' ) {
|
|
291
|
-
code = qs$(node, 'code');
|
|
328
|
+
const code = qs$(node, 'code');
|
|
292
329
|
if ( code !== null ) {
|
|
293
|
-
selector = code.textContent
|
|
294
|
-
if ( selector.
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
330
|
+
selector = `${code.textContent} > ${selector}`;
|
|
331
|
+
if ( selector.includes('#') ) { break; }
|
|
297
332
|
}
|
|
298
333
|
}
|
|
299
334
|
node = node.parentElement;
|
|
@@ -303,10 +338,10 @@ const selectorFromNode = function(node) {
|
|
|
303
338
|
|
|
304
339
|
/******************************************************************************/
|
|
305
340
|
|
|
306
|
-
const selectorFromFilter =
|
|
341
|
+
const selectorFromFilter = node => {
|
|
307
342
|
while ( node !== null ) {
|
|
308
343
|
if ( node.localName === 'li' ) {
|
|
309
|
-
|
|
344
|
+
const code = qs$(node, 'code:nth-of-type(2)');
|
|
310
345
|
if ( code !== null ) {
|
|
311
346
|
return code.textContent;
|
|
312
347
|
}
|
|
@@ -318,8 +353,8 @@ const selectorFromFilter = function(node) {
|
|
|
318
353
|
|
|
319
354
|
/******************************************************************************/
|
|
320
355
|
|
|
321
|
-
const nidFromNode =
|
|
322
|
-
|
|
356
|
+
const nidFromNode = node => {
|
|
357
|
+
let li = node;
|
|
323
358
|
while ( li !== null ) {
|
|
324
359
|
if ( li.localName === 'li' ) {
|
|
325
360
|
return li.id || '';
|
|
@@ -331,7 +366,7 @@ const nidFromNode = function(node) {
|
|
|
331
366
|
|
|
332
367
|
/******************************************************************************/
|
|
333
368
|
|
|
334
|
-
const startDialog = (
|
|
369
|
+
const startDialog = (( ) => {
|
|
335
370
|
let dialog;
|
|
336
371
|
let textarea;
|
|
337
372
|
let hideSelectors = [];
|
|
@@ -367,17 +402,17 @@ const startDialog = (function() {
|
|
|
367
402
|
};
|
|
368
403
|
|
|
369
404
|
const onClicked = function(ev) {
|
|
370
|
-
|
|
405
|
+
const target = ev.target;
|
|
371
406
|
|
|
372
407
|
ev.stopPropagation();
|
|
373
408
|
|
|
374
409
|
if ( target.id === 'createCosmeticFilters' ) {
|
|
375
|
-
messaging.send('loggerUI', {
|
|
410
|
+
vAPI.messaging.send('loggerUI', {
|
|
376
411
|
what: 'createUserFilter',
|
|
377
412
|
filters: textarea.value,
|
|
378
413
|
});
|
|
379
414
|
// Force a reload for the new cosmetic filter(s) to take effect
|
|
380
|
-
messaging.send('loggerUI', {
|
|
415
|
+
vAPI.messaging.send('loggerUI', {
|
|
381
416
|
what: 'reloadTab',
|
|
382
417
|
tabId: inspectedTabId,
|
|
383
418
|
});
|
|
@@ -386,7 +421,7 @@ const startDialog = (function() {
|
|
|
386
421
|
};
|
|
387
422
|
|
|
388
423
|
const showCommitted = function() {
|
|
389
|
-
|
|
424
|
+
contentInspectorChannel.send({
|
|
390
425
|
what: 'showCommitted',
|
|
391
426
|
hide: hideSelectors.join(',\n'),
|
|
392
427
|
unhide: unhideSelectors.join(',\n')
|
|
@@ -394,7 +429,7 @@ const startDialog = (function() {
|
|
|
394
429
|
};
|
|
395
430
|
|
|
396
431
|
const showInteractive = function() {
|
|
397
|
-
|
|
432
|
+
contentInspectorChannel.send({
|
|
398
433
|
what: 'showInteractive',
|
|
399
434
|
hide: hideSelectors.join(',\n'),
|
|
400
435
|
unhide: unhideSelectors.join(',\n')
|
|
@@ -444,13 +479,13 @@ const startDialog = (function() {
|
|
|
444
479
|
|
|
445
480
|
/******************************************************************************/
|
|
446
481
|
|
|
447
|
-
const onClicked =
|
|
482
|
+
const onClicked = ev => {
|
|
448
483
|
ev.stopPropagation();
|
|
449
484
|
|
|
450
485
|
if ( inspectedTabId === 0 ) { return; }
|
|
451
486
|
|
|
452
|
-
|
|
453
|
-
|
|
487
|
+
const target = ev.target;
|
|
488
|
+
const parent = target.parentElement;
|
|
454
489
|
|
|
455
490
|
// Expand/collapse branch
|
|
456
491
|
if (
|
|
@@ -473,7 +508,7 @@ const onClicked = function(ev) {
|
|
|
473
508
|
|
|
474
509
|
// Toggle cosmetic filter
|
|
475
510
|
if ( dom.cl.has(target, 'filter') ) {
|
|
476
|
-
|
|
511
|
+
contentInspectorChannel.send({
|
|
477
512
|
what: 'toggleFilter',
|
|
478
513
|
original: false,
|
|
479
514
|
target: dom.cl.toggle(target, 'off'),
|
|
@@ -489,7 +524,7 @@ const onClicked = function(ev) {
|
|
|
489
524
|
}
|
|
490
525
|
// Toggle node
|
|
491
526
|
else {
|
|
492
|
-
|
|
527
|
+
contentInspectorChannel.send({
|
|
493
528
|
what: 'toggleNodes',
|
|
494
529
|
original: true,
|
|
495
530
|
target: dom.cl.toggle(target, 'off') === false,
|
|
@@ -505,21 +540,19 @@ const onClicked = function(ev) {
|
|
|
505
540
|
|
|
506
541
|
/******************************************************************************/
|
|
507
542
|
|
|
508
|
-
const onMouseOver = (
|
|
543
|
+
const onMouseOver = (( ) => {
|
|
509
544
|
let mouseoverTarget = null;
|
|
510
545
|
|
|
511
|
-
const
|
|
512
|
-
|
|
546
|
+
const mouseoverTimer = vAPI.defer.create(( ) => {
|
|
547
|
+
contentInspectorChannel.send({
|
|
513
548
|
what: 'highlightOne',
|
|
514
549
|
selector: selectorFromNode(mouseoverTarget),
|
|
515
550
|
nid: nidFromNode(mouseoverTarget),
|
|
516
551
|
scrollTo: true
|
|
517
552
|
});
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
const mouseoverTimer = vAPI.defer.create(timerHandler);
|
|
553
|
+
});
|
|
521
554
|
|
|
522
|
-
return
|
|
555
|
+
return ev => {
|
|
523
556
|
if ( inspectedTabId === 0 ) { return; }
|
|
524
557
|
// Convenience: skip real-time highlighting if shift key is pressed.
|
|
525
558
|
if ( ev.shiftKey ) { return; }
|
|
@@ -533,31 +566,34 @@ const onMouseOver = (function() {
|
|
|
533
566
|
|
|
534
567
|
/******************************************************************************/
|
|
535
568
|
|
|
536
|
-
const currentTabId =
|
|
569
|
+
const currentTabId = ( ) => {
|
|
537
570
|
if ( dom.cl.has(showdomButton, 'active') === false ) { return 0; }
|
|
538
571
|
return logger.tabIdFromPageSelector();
|
|
539
572
|
};
|
|
540
573
|
|
|
541
574
|
/******************************************************************************/
|
|
542
575
|
|
|
543
|
-
const injectInspector =
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
576
|
+
const injectInspector = (( ) => {
|
|
577
|
+
const timer = vAPI.defer.create(( ) => {
|
|
578
|
+
const tabId = currentTabId();
|
|
579
|
+
if ( tabId <= 0 ) { return; }
|
|
580
|
+
inspectedTabId = tabId;
|
|
581
|
+
vAPI.messaging.send('loggerUI', {
|
|
582
|
+
what: 'scriptlet',
|
|
583
|
+
tabId,
|
|
584
|
+
scriptlet: 'dom-inspector',
|
|
585
|
+
});
|
|
551
586
|
});
|
|
552
|
-
|
|
587
|
+
return ( ) => {
|
|
588
|
+
shutdownInspector();
|
|
589
|
+
timer.offon(353);
|
|
590
|
+
};
|
|
591
|
+
})();
|
|
553
592
|
|
|
554
593
|
/******************************************************************************/
|
|
555
594
|
|
|
556
|
-
const shutdownInspector =
|
|
557
|
-
|
|
558
|
-
vAPI.MessagingConnection.disconnectFrom(inspectorConnectionId);
|
|
559
|
-
inspectorConnectionId = undefined;
|
|
560
|
-
}
|
|
595
|
+
const shutdownInspector = ( ) => {
|
|
596
|
+
contentInspectorChannel.disconnect();
|
|
561
597
|
logger.removeAllChildren(domTree);
|
|
562
598
|
dom.cl.remove(inspector, 'vExpanded');
|
|
563
599
|
inspectedTabId = 0;
|
|
@@ -565,61 +601,81 @@ const shutdownInspector = function() {
|
|
|
565
601
|
|
|
566
602
|
/******************************************************************************/
|
|
567
603
|
|
|
568
|
-
const onTabIdChanged =
|
|
604
|
+
const onTabIdChanged = ( ) => {
|
|
569
605
|
const tabId = currentTabId();
|
|
570
606
|
if ( tabId <= 0 ) {
|
|
571
607
|
return toggleOff();
|
|
572
608
|
}
|
|
573
609
|
if ( inspectedTabId !== tabId ) {
|
|
574
|
-
shutdownInspector();
|
|
575
610
|
injectInspector();
|
|
576
611
|
}
|
|
577
612
|
};
|
|
578
613
|
|
|
579
614
|
/******************************************************************************/
|
|
580
615
|
|
|
581
|
-
const
|
|
582
|
-
const
|
|
583
|
-
const
|
|
616
|
+
const toggleVExpandView = ( ) => {
|
|
617
|
+
const branches = qsa$('#domTree li.branch.show > ul > li.branch:not(.show)');
|
|
618
|
+
for ( const branch of branches ) {
|
|
619
|
+
dom.cl.add(branch, 'show');
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
const toggleVCompactView = ( ) => {
|
|
624
|
+
const branches = qsa$('#domTree li.branch.show > ul > li:not(.show)');
|
|
625
|
+
const tohideSet = new Set();
|
|
584
626
|
for ( const branch of branches ) {
|
|
585
|
-
|
|
627
|
+
const node = branch.closest('li.branch.show');
|
|
628
|
+
if ( node.id === 'n1' ) { continue; }
|
|
629
|
+
tohideSet.add(node);
|
|
630
|
+
}
|
|
631
|
+
const tohideList = Array.from(tohideSet);
|
|
632
|
+
let i = tohideList.length - 1;
|
|
633
|
+
while ( i > 0 ) {
|
|
634
|
+
if ( tohideList[i-1].contains(tohideList[i]) ) {
|
|
635
|
+
tohideList.splice(i-1, 1);
|
|
636
|
+
} else if ( tohideList[i].contains(tohideList[i-1]) ) {
|
|
637
|
+
tohideList.splice(i, 1);
|
|
638
|
+
}
|
|
639
|
+
i -= 1;
|
|
640
|
+
}
|
|
641
|
+
for ( const node of tohideList ) {
|
|
642
|
+
dom.cl.remove(node, 'show');
|
|
586
643
|
}
|
|
587
644
|
};
|
|
588
645
|
|
|
589
|
-
const toggleHCompactView =
|
|
646
|
+
const toggleHCompactView = ( ) => {
|
|
590
647
|
dom.cl.toggle(inspector, 'hCompact');
|
|
591
648
|
};
|
|
592
649
|
|
|
593
650
|
/******************************************************************************/
|
|
594
651
|
|
|
595
|
-
const revert =
|
|
652
|
+
const revert = ( ) => {
|
|
596
653
|
dom.cl.remove('#domTree .off', 'off');
|
|
597
|
-
|
|
598
|
-
inspectorConnectionId,
|
|
599
|
-
{ what: 'resetToggledNodes' }
|
|
600
|
-
);
|
|
654
|
+
contentInspectorChannel.send({ what: 'resetToggledNodes' });
|
|
601
655
|
dom.cl.add(qs$(inspector, '.permatoolbar .revert'), 'disabled');
|
|
602
656
|
dom.cl.add(qs$(inspector, '.permatoolbar .commit'), 'disabled');
|
|
603
657
|
};
|
|
604
658
|
|
|
605
659
|
/******************************************************************************/
|
|
606
660
|
|
|
607
|
-
const toggleOn =
|
|
661
|
+
const toggleOn = ( ) => {
|
|
608
662
|
dom.cl.add('#inspectors', 'dom');
|
|
609
663
|
window.addEventListener('beforeunload', toggleOff);
|
|
610
664
|
document.addEventListener('tabIdChanged', onTabIdChanged);
|
|
611
665
|
domTree.addEventListener('click', onClicked, true);
|
|
612
666
|
domTree.addEventListener('mouseover', onMouseOver, true);
|
|
667
|
+
dom.on('#domInspector .vExpandToggler', 'click', toggleVExpandView);
|
|
613
668
|
dom.on('#domInspector .vCompactToggler', 'click', toggleVCompactView);
|
|
614
669
|
dom.on('#domInspector .hCompactToggler', 'click', toggleHCompactView);
|
|
615
670
|
dom.on('#domInspector .permatoolbar .revert', 'click', revert);
|
|
616
671
|
dom.on('#domInspector .permatoolbar .commit', 'click', startDialog);
|
|
672
|
+
contentInspectorChannel.start();
|
|
617
673
|
injectInspector();
|
|
618
674
|
};
|
|
619
675
|
|
|
620
676
|
/******************************************************************************/
|
|
621
677
|
|
|
622
|
-
const toggleOff =
|
|
678
|
+
const toggleOff = ( ) => {
|
|
623
679
|
dom.cl.remove(showdomButton, 'active');
|
|
624
680
|
dom.cl.remove('#inspectors', 'dom');
|
|
625
681
|
shutdownInspector();
|
|
@@ -627,16 +683,18 @@ const toggleOff = function() {
|
|
|
627
683
|
document.removeEventListener('tabIdChanged', onTabIdChanged);
|
|
628
684
|
domTree.removeEventListener('click', onClicked, true);
|
|
629
685
|
domTree.removeEventListener('mouseover', onMouseOver, true);
|
|
686
|
+
dom.off('#domInspector .vExpandToggler', 'click', toggleVExpandView);
|
|
630
687
|
dom.off('#domInspector .vCompactToggler', 'click', toggleVCompactView);
|
|
631
688
|
dom.off('#domInspector .hCompactToggler', 'click', toggleHCompactView);
|
|
632
689
|
dom.off('#domInspector .permatoolbar .revert', 'click', revert);
|
|
633
690
|
dom.off('#domInspector .permatoolbar .commit', 'click', startDialog);
|
|
691
|
+
contentInspectorChannel.shutdown();
|
|
634
692
|
inspectedTabId = 0;
|
|
635
693
|
};
|
|
636
694
|
|
|
637
695
|
/******************************************************************************/
|
|
638
696
|
|
|
639
|
-
const toggle =
|
|
697
|
+
const toggle = ( ) => {
|
|
640
698
|
if ( dom.cl.toggle(showdomButton, 'active') ) {
|
|
641
699
|
toggleOn();
|
|
642
700
|
} else {
|