Skip to content

Commit 3b753af

Browse files
authored
Merge pull request #161 from SentienceAPI/sync-extension-v2.8.4
Sync Extension: v2.8.4
2 parents eb4a217 + b97f181 commit 3b753af

File tree

4 files changed

+93
-75
lines changed

4 files changed

+93
-75
lines changed

src/extension/content.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@
7979
case "SENTIENCE_SHOW_OVERLAY":
8080
!function(data) {
8181
const {elements: elements, targetElementId: targetElementId} = data;
82-
if (!elements || !Array.isArray(elements)) return;
82+
if (!elements || "object" != typeof elements || "number" != typeof elements.length) return;
83+
const elementsArray = Array.isArray(elements) ? elements : Array.from(elements);
8384
removeOverlay();
8485
const host = document.createElement("div");
8586
host.id = OVERLAY_HOST_ID, host.style.cssText = "\n position: fixed !important;\n top: 0 !important;\n left: 0 !important;\n width: 100vw !important;\n height: 100vh !important;\n pointer-events: none !important;\n z-index: 2147483647 !important;\n margin: 0 !important;\n padding: 0 !important;\n ",
8687
document.body.appendChild(host);
8788
const shadow = host.attachShadow({
8889
mode: "closed"
89-
}), maxImportance = Math.max(...elements.map(e => e.importance || 0), 1);
90-
elements.forEach(element => {
90+
}), maxImportance = Math.max(...elementsArray.map(e => e.importance || 0), 1);
91+
elementsArray.forEach(element => {
9192
const bbox = element.bbox;
9293
if (!bbox) return;
9394
const isTarget = element.id === targetElementId, isPrimary = element.visual_cues?.is_primary || !1, importance = element.importance || 0;

src/extension/injected_api.js

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -390,33 +390,46 @@
390390
return null;
391391
}
392392
function getRawHTML(root) {
393-
const sourceRoot = root || document.body, clone = sourceRoot.cloneNode(!0);
394-
[ "nav", "footer", "header", "script", "style", "noscript", "iframe", "svg" ].forEach(tag => {
395-
clone.querySelectorAll(tag).forEach(el => {
396-
el.parentNode && el.parentNode.removeChild(el);
397-
});
398-
});
399-
const invisibleSelectors = [], walker = document.createTreeWalker(sourceRoot, NodeFilter.SHOW_ELEMENT, null, !1);
393+
const sourceRoot = root || document.body, clone = sourceRoot.cloneNode(!0), unwantedTags = [ "script", "style", "noscript", "iframe", "svg" ], unwantedTagSet = new Set(unwantedTags);
394+
function getChildIndex(node) {
395+
let index = 0, sibling = node;
396+
for (;sibling = sibling.previousElementSibling; ) index++;
397+
return index;
398+
}
399+
function getElementPath(node, root) {
400+
const path = [];
401+
let current = node;
402+
for (;current && current !== root && current.parentElement; ) path.unshift(getChildIndex(current)),
403+
current = current.parentElement;
404+
return path;
405+
}
406+
const invisiblePaths = [], walker = document.createTreeWalker(sourceRoot, NodeFilter.SHOW_ELEMENT, null, !1);
400407
let node;
401408
for (;node = walker.nextNode(); ) {
402409
const tag = node.tagName.toLowerCase();
403410
if ("head" === tag || "title" === tag) continue;
411+
if (unwantedTagSet.has(tag)) continue;
404412
const style = window.getComputedStyle(node);
405-
if ("none" === style.display || "hidden" === style.visibility || 0 === node.offsetWidth && 0 === node.offsetHeight) {
406-
let selector = tag;
407-
if (node.id) selector = `#${node.id}`; else if (node.className && "string" == typeof node.className) {
408-
const classes = node.className.trim().split(/\s+/).filter(c => c);
409-
classes.length > 0 && (selector = `${tag}.${classes.join(".")}`);
410-
}
411-
invisibleSelectors.push(selector);
412-
}
413+
"none" !== style.display && "hidden" !== style.visibility || invisiblePaths.push(getElementPath(node, sourceRoot));
413414
}
414-
invisibleSelectors.forEach(selector => {
415-
try {
416-
clone.querySelectorAll(selector).forEach(el => {
417-
el.parentNode && el.parentNode.removeChild(el);
418-
});
419-
} catch (e) {}
415+
invisiblePaths.sort((a, b) => {
416+
if (a.length !== b.length) return b.length - a.length;
417+
for (let i = a.length - 1; i >= 0; i--) if (a[i] !== b[i]) return b[i] - a[i];
418+
return 0;
419+
}), invisiblePaths.forEach(path => {
420+
const el = function(root, path) {
421+
let current = root;
422+
for (const index of path) {
423+
if (!current || !current.children || index >= current.children.length) return null;
424+
current = current.children[index];
425+
}
426+
return current;
427+
}(clone, path);
428+
el && el.parentNode && el.parentNode.removeChild(el);
429+
}), unwantedTags.forEach(tag => {
430+
clone.querySelectorAll(tag).forEach(el => {
431+
el.parentNode && el.parentNode.removeChild(el);
432+
});
420433
});
421434
clone.querySelectorAll("a[href]").forEach(link => {
422435
const href = link.getAttribute("href");
@@ -1178,17 +1191,21 @@
11781191
}, autoDisableTimeout)), window.sentience_stopRecording = stopRecording, stopRecording;
11791192
}
11801193
function showOverlay(elements, targetElementId = null) {
1181-
elements && Array.isArray(elements) && window.postMessage({
1194+
if (!elements || "object" != typeof elements || "number" != typeof elements.length) return;
1195+
const elementsArray = Array.isArray(elements) ? elements : Array.from(elements);
1196+
window.postMessage({
11821197
type: "SENTIENCE_SHOW_OVERLAY",
1183-
elements: elements,
1198+
elements: elementsArray,
11841199
targetElementId: targetElementId,
11851200
timestamp: Date.now()
11861201
}, "*");
11871202
}
11881203
function showGrid(grids, targetGridId = null) {
1189-
grids && Array.isArray(grids) && window.postMessage({
1204+
if (!grids || "object" != typeof grids || "number" != typeof grids.length) return;
1205+
const gridsArray = Array.isArray(grids) ? grids : Array.from(grids);
1206+
window.postMessage({
11901207
type: "SENTIENCE_SHOW_GRID_OVERLAY",
1191-
grids: grids,
1208+
grids: gridsArray,
11921209
targetGridId: targetGridId,
11931210
timestamp: Date.now()
11941211
}, "*");

src/extension/manifest.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": "Sentience Semantic Visual Grounding Extractor",
4-
"version": "2.8.3",
4+
"version": "2.8.4",
55
"description": "Extract semantic visual grounding data from web pages",
66
"permissions": ["activeTab", "scripting"],
77
"host_permissions": ["<all_urls>"],

src/extension/release.json

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
{
2-
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/279250819",
3-
"assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/279250819/assets",
4-
"upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/279250819/assets{?name,label}",
5-
"html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.8.3",
6-
"id": 279250819,
2+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/279701545",
3+
"assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/279701545/assets",
4+
"upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/279701545/assets{?name,label}",
5+
"html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.8.4",
6+
"id": 279701545,
77
"author": {
8-
"login": "github-actions[bot]",
9-
"id": 41898282,
10-
"node_id": "MDM6Qm90NDE4OTgyODI=",
11-
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
8+
"login": "rcholic",
9+
"id": 135060,
10+
"node_id": "MDQ6VXNlcjEzNTA2MA==",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/135060?v=4",
1212
"gravatar_id": "",
13-
"url": "https://api.github.com/users/github-actions%5Bbot%5D",
14-
"html_url": "https://github.com/apps/github-actions",
15-
"followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers",
16-
"following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}",
17-
"gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}",
18-
"starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}",
19-
"subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions",
20-
"organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs",
21-
"repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos",
22-
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
23-
"received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events",
24-
"type": "Bot",
13+
"url": "https://api.github.com/users/rcholic",
14+
"html_url": "https://github.com/rcholic",
15+
"followers_url": "https://api.github.com/users/rcholic/followers",
16+
"following_url": "https://api.github.com/users/rcholic/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/rcholic/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/rcholic/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/rcholic/subscriptions",
20+
"organizations_url": "https://api.github.com/users/rcholic/orgs",
21+
"repos_url": "https://api.github.com/users/rcholic/repos",
22+
"events_url": "https://api.github.com/users/rcholic/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/rcholic/received_events",
24+
"type": "User",
2525
"user_view_type": "public",
2626
"site_admin": false
2727
},
28-
"node_id": "RE_kwDOQshiJ84QpQeD",
29-
"tag_name": "v2.8.3",
28+
"node_id": "RE_kwDOQshiJ84Qq-gp",
29+
"tag_name": "v2.8.4",
3030
"target_commitish": "main",
31-
"name": "Release v2.8.3",
31+
"name": "Release v2.8.4",
3232
"draft": false,
3333
"immutable": false,
3434
"prerelease": false,
35-
"created_at": "2026-01-23T06:12:02Z",
36-
"updated_at": "2026-01-23T06:14:22Z",
37-
"published_at": "2026-01-23T06:13:11Z",
35+
"created_at": "2026-01-25T06:10:24Z",
36+
"updated_at": "2026-01-25T06:11:51Z",
37+
"published_at": "2026-01-25T06:11:11Z",
3838
"assets": [
3939
{
40-
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/344654926",
41-
"id": 344654926,
42-
"node_id": "RA_kwDOQshiJ84UiwRO",
40+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/345545012",
41+
"id": 345545012,
42+
"node_id": "RA_kwDOQshiJ84UmJk0",
4343
"name": "extension-files.tar.gz",
4444
"label": "",
4545
"uploader": {
@@ -65,17 +65,17 @@
6565
},
6666
"content_type": "application/gzip",
6767
"state": "uploaded",
68-
"size": 79317,
69-
"digest": "sha256:0d8979ec6c3cde0fb679501f89e5fdb0db8d547661b1da7d6299f28262ad1fc4",
68+
"size": 79724,
69+
"digest": "sha256:d78574e7fb0dfa121a261b650478a1d7a188377b3ba03fed1205cf07f2e1895e",
7070
"download_count": 0,
71-
"created_at": "2026-01-23T06:13:12Z",
72-
"updated_at": "2026-01-23T06:13:12Z",
73-
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.8.3/extension-files.tar.gz"
71+
"created_at": "2026-01-25T06:11:50Z",
72+
"updated_at": "2026-01-25T06:11:51Z",
73+
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.8.4/extension-files.tar.gz"
7474
},
7575
{
76-
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/344654925",
77-
"id": 344654925,
78-
"node_id": "RA_kwDOQshiJ84UiwRN",
76+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/345545011",
77+
"id": 345545011,
78+
"node_id": "RA_kwDOQshiJ84UmJkz",
7979
"name": "extension-package.zip",
8080
"label": "",
8181
"uploader": {
@@ -101,15 +101,15 @@
101101
},
102102
"content_type": "application/zip",
103103
"state": "uploaded",
104-
"size": 80784,
105-
"digest": "sha256:cc80691d6efc868a9d4009fe1b8bdb94f33017666a7d2db429a1f4aaee978616",
104+
"size": 81073,
105+
"digest": "sha256:b6c4cb930256d2067e566281976840417da78595a734a48f6baae735e3a0356b",
106106
"download_count": 0,
107-
"created_at": "2026-01-23T06:13:12Z",
108-
"updated_at": "2026-01-23T06:13:12Z",
109-
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.8.3/extension-package.zip"
107+
"created_at": "2026-01-25T06:11:50Z",
108+
"updated_at": "2026-01-25T06:11:51Z",
109+
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.8.4/extension-package.zip"
110110
}
111111
],
112-
"tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.8.3",
113-
"zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.8.3",
114-
"body": "**Full Changelog**: https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/compare/v2.8.2...v2.8.3"
112+
"tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.8.4",
113+
"zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.8.4",
114+
"body": ""
115115
}

0 commit comments

Comments
 (0)